From 65faabeed48584c461ca21d784c3f1d46f67f832 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Mon, 18 Mar 2013 23:00:46 +0100 Subject: Connect instance list to model. --- libmultimc/src/instancelist.cpp | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'libmultimc/src') diff --git a/libmultimc/src/instancelist.cpp b/libmultimc/src/instancelist.cpp index 78650634..83a72afb 100644 --- a/libmultimc/src/instancelist.cpp +++ b/libmultimc/src/instancelist.cpp @@ -15,11 +15,10 @@ #include "include/instancelist.h" -#include "siglist_impl.h" - #include #include #include +#include #include "include/instance.h" #include "include/instanceloader.h" @@ -37,7 +36,7 @@ InstanceList::InstListError InstanceList::loadList() { QDir dir(m_instDir); QDirIterator iter(dir); - + m_instances.clear(); while (iter.hasNext()) { QString subDir = iter.next(); @@ -78,10 +77,41 @@ InstanceList::InstListError InstanceList::loadList() qDebug(QString("Loaded instance %1").arg(inst->name()).toUtf8()); inst->setParent(this); - append(QSharedPointer(inst)); + m_instances.append(inst); } } } - + emit invalidated(); return NoError; } + +/// Clear all instances. Triggers notifications. +void InstanceList::clear() +{ + m_instances.clear(); + emit invalidated(); +}; + +/// Add an instance. Triggers notifications, returns the new index +int InstanceList::add(InstancePtr t) +{ + m_instances.append(t); + emit instanceAdded(count() - 1); + return count() - 1; +} + +InstancePtr InstanceList::getInstanceById(QString instId) +{ + QListIterator iter(m_instances); + InstancePtr inst; + while(iter.hasNext()) + { + inst = iter.next(); + if (inst->id() == instId) + break; + } + if (inst->id() != instId) + return InstancePtr(); + else + return iter.peekPrevious(); +} \ No newline at end of file -- cgit From 7e222c3e8f4d1c007edafc31e75e7712813dd64b Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Mon, 18 Mar 2013 23:35:54 +0100 Subject: Loading instance groups and exposing them to the model --- gui/instancemodel.cpp | 2 +- libmultimc/include/instance.h | 7 +++ libmultimc/src/instancelist.cpp | 109 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 116 insertions(+), 2 deletions(-) (limited to 'libmultimc/src') diff --git a/gui/instancemodel.cpp b/gui/instancemodel.cpp index 49909940..0051602b 100644 --- a/gui/instancemodel.cpp +++ b/gui/instancemodel.cpp @@ -78,7 +78,7 @@ QVariant InstanceModel::data ( const QModelIndex& index, int role ) const case KCategorizedSortFilterProxyModel::CategorySortRole: case KCategorizedSortFilterProxyModel::CategoryDisplayRole: { - return "IT'S A GROUP"; + return pdata->group(); } default: break; diff --git a/libmultimc/include/instance.h b/libmultimc/include/instance.h index c41e6718..9334dff8 100644 --- a/libmultimc/include/instance.h +++ b/libmultimc/include/instance.h @@ -65,6 +65,9 @@ class LIBMULTIMC_EXPORT Instance : public QObject //! The instance's notes. Q_PROPERTY(QString notes READ notes WRITE setNotes) + //! The instance's group. + Q_PROPERTY(QString group READ group WRITE setGroup) + /*! * Whether or not the instance's minecraft.jar needs to be rebuilt. * If this is true, when the instance launches, its jar mods will be @@ -181,6 +184,9 @@ public: virtual QString notes() const { return settings().get("notes").toString(); } virtual void setNotes(QString val) { settings().set("notes", val); } + virtual QString group() const { return m_group; } + virtual void setGroup(QString val) { m_group = val; } + virtual bool shouldRebuild() const { return settings().get("NeedsRebuild").toBool(); } virtual void setShouldRebuild(bool val) { settings().set("NeedsRebuild", val); } @@ -279,6 +285,7 @@ public: private: QString m_rootDir; + QString m_group; SettingsObject *m_settings; }; diff --git a/libmultimc/src/instancelist.cpp b/libmultimc/src/instancelist.cpp index 83a72afb..a835fcfe 100644 --- a/libmultimc/src/instancelist.cpp +++ b/libmultimc/src/instancelist.cpp @@ -19,12 +19,17 @@ #include #include #include +#include +#include +#include +#include #include "include/instance.h" #include "include/instanceloader.h" #include "pathutils.h" +const static int GROUP_FILE_FORMAT_VERSION = 1; InstanceList::InstanceList(const QString &instDir, QObject *parent) : QObject(parent), m_instDir("instances") @@ -36,6 +41,104 @@ InstanceList::InstListError InstanceList::loadList() { QDir dir(m_instDir); QDirIterator iter(dir); + + QString groupFileName = m_instDir + "/instgroups.json"; + // temporary map from instance ID to group name + QMap groupMap; + + // HACK: this is really an if. breaks after one iteration. + while (QFileInfo(groupFileName).exists()) + { + QFile groupFile(groupFileName); + + if (!groupFile.open(QIODevice::ReadOnly)) + { + // An error occurred. Ignore it. + qDebug("Failed to read instance group file."); + break; + } + + QTextStream in(&groupFile); + QString jsonStr = in.readAll(); + groupFile.close(); + + QJsonParseError error; + QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonStr.toUtf8(), &error); + + if (error.error != QJsonParseError::NoError) + { + qWarning(QString("Failed to parse instance group file: %1 at offset %2"). + arg(error.errorString(), QString::number(error.offset)).toUtf8()); + break; + } + + if (!jsonDoc.isObject()) + { + qWarning("Invalid group file. Root entry should be an object."); + break; + } + + 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()) + { + qWarning("Invalid group list JSON: 'groups' should be an object."); + break; + } + + // 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; + } + } + } + break; + } m_instances.clear(); while (iter.hasNext()) { @@ -74,7 +177,11 @@ InstanceList::InstListError InstanceList::loadList() else { QSharedPointer inst(instPtr); - + auto iter = groupMap.find(inst->id()); + if(iter != groupMap.end()) + { + inst->setGroup((*iter)); + } qDebug(QString("Loaded instance %1").arg(inst->name()).toUtf8()); inst->setParent(this); m_instances.append(inst); -- cgit From 7d7e4034f48b578c87a4651075c2b73dc236181b Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Tue, 19 Mar 2013 06:24:34 +0100 Subject: Property change propagation, changing instance groups, icon preview --- gui/instancemodel.cpp | 13 ++++++++----- gui/instancemodel.h | 1 - gui/mainwindow.cpp | 33 ++++++++++++++++++++++++++++++--- gui/mainwindow.h | 7 ++++++- libmultimc/include/instance.h | 29 +++++++++++++++++++++++++---- libmultimc/include/instancelist.h | 3 +++ libmultimc/src/instancelist.cpp | 13 +++++++++++++ 7 files changed, 85 insertions(+), 14 deletions(-) (limited to 'libmultimc/src') diff --git a/gui/instancemodel.cpp b/gui/instancemodel.cpp index 0051602b..3c96c8f0 100644 --- a/gui/instancemodel.cpp +++ b/gui/instancemodel.cpp @@ -5,7 +5,6 @@ InstanceModel::InstanceModel ( const InstanceList& instances, QObject *parent ) : QAbstractListModel ( parent ), m_instances ( &instances ) { - cachedIcon = QIcon(":/icons/multimc/scalable/apps/multimc.svg"); currentInstancesNumber = m_instances->count(); connect(m_instances,SIGNAL(instanceAdded(int)),this,SLOT(onInstanceAdded(int))); connect(m_instances,SIGNAL(instanceChanged(int)),this,SLOT(onInstanceChanged(int))); @@ -19,10 +18,10 @@ void InstanceModel::onInstanceAdded ( int index ) endInsertRows(); } -// TODO: this doesn't trigger yet void InstanceModel::onInstanceChanged ( int index ) { - + QModelIndex mx = InstanceModel::index(index); + dataChanged(mx,mx); } void InstanceModel::onInvalidated() @@ -71,8 +70,12 @@ QVariant InstanceModel::data ( const QModelIndex& index, int role ) const } case Qt::DecorationRole: { - // FIXME: replace with an icon cache - return cachedIcon; + // FIXME: replace with an icon cache/renderer + QString path = ":/icons/instances/"; + path += pdata->iconKey(); + QIcon icon(path); + return icon; + //else return QIcon(":/icons/multimc/scalable/apps/multimc.svg"); } // for now. case KCategorizedSortFilterProxyModel::CategorySortRole: diff --git a/gui/instancemodel.h b/gui/instancemodel.h index de43b7b8..208ee68e 100644 --- a/gui/instancemodel.h +++ b/gui/instancemodel.h @@ -29,7 +29,6 @@ public slots: private: const InstanceList* m_instances; - QIcon cachedIcon; int currentInstancesNumber; }; diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index a96d80a7..78f58713 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -116,6 +116,11 @@ MainWindow::MainWindow ( QWidget *parent ) : // Load the instances. instList.loadList(); + // just a test + /* + instList.at(0)->setGroup("TEST GROUP"); + instList.at(0)->setName("TEST ITEM"); + */ } MainWindow::~MainWindow() @@ -140,6 +145,18 @@ void MainWindow::on_actionAddInstance_triggered() newInstDlg->exec(); } +void MainWindow::on_actionChangeInstGroup_triggered() +{ + Instance* inst = selectedInstance(); + if(inst) + { + QString name ( inst->group() ); + name = QInputDialog::getText ( this, tr ( "Group name" ), tr ( "Enter a new group name." ), QLineEdit::Normal, name ); + inst->setGroup(name); + } +} + + void MainWindow::on_actionViewInstanceFolder_triggered() { openInDefaultProgram ( globalSettings->get ( "InstanceDir" ).toString() ); @@ -210,8 +227,7 @@ void MainWindow::on_instanceView_customContextMenuRequested ( const QPoint &pos instContextMenu->exec ( view->mapToGlobal ( pos ) ); } - -void MainWindow::on_actionLaunchInstance_triggered() +Instance* MainWindow::selectedInstance() { QAbstractItemView * iv = view; auto smodel = iv->selectionModel(); @@ -224,7 +240,18 @@ void MainWindow::on_actionLaunchInstance_triggered() if(mindex.isValid()) { - Instance * inst = (Instance *) mindex.data(InstanceModel::InstancePointerRole).value(); + return (Instance *) mindex.data(InstanceModel::InstancePointerRole).value(); + } + else + return nullptr; +} + + +void MainWindow::on_actionLaunchInstance_triggered() +{ + Instance* inst = selectedInstance(); + if(inst) + { doLogin(inst->id()); } } diff --git a/gui/mainwindow.h b/gui/mainwindow.h index c2dedf74..5d990639 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -44,14 +44,19 @@ public: // Browser Dialog void openWebPage(QUrl url); + +private: + Instance *selectedInstance(); private slots: void on_actionAbout_triggered(); void on_actionAddInstance_triggered(); - void on_actionViewInstanceFolder_triggered(); + void on_actionChangeInstGroup_triggered(); + void on_actionViewInstanceFolder_triggered(); + void on_actionRefresh_triggered(); void on_actionViewCentralModsFolder_triggered(); diff --git a/libmultimc/include/instance.h b/libmultimc/include/instance.h index 9334dff8..258a0dab 100644 --- a/libmultimc/include/instance.h +++ b/libmultimc/include/instance.h @@ -176,16 +176,28 @@ public: //// General Info //// virtual QString name() { return settings().get("name").toString(); } - virtual void setName(QString val) { settings().set("name", val); } + virtual void setName(QString val) + { + settings().set("name", val); + emit propertiesChanged(this); + } virtual QString iconKey() const { return settings().get("iconKey").toString(); } - virtual void setIconKey(QString val) { settings().set("iconKey", val); } + virtual void setIconKey(QString val) + { + settings().set("iconKey", val); + emit propertiesChanged(this); + } virtual QString notes() const { return settings().get("notes").toString(); } virtual void setNotes(QString val) { settings().set("notes", val); } virtual QString group() const { return m_group; } - virtual void setGroup(QString val) { m_group = val; } + virtual void setGroup(QString val) + { + m_group = val; + emit propertiesChanged(this); + } virtual bool shouldRebuild() const { return settings().get("NeedsRebuild").toBool(); } virtual void setShouldRebuild(bool val) { settings().set("NeedsRebuild", val); } @@ -208,7 +220,10 @@ public: virtual qint64 lastLaunch() { return settings().get("lastLaunchTime").value(); } virtual void setLastLaunch(qint64 val = QDateTime::currentMSecsSinceEpoch()) - { settings().set("lastLaunchTime", val); } + { + settings().set("lastLaunchTime", val); + emit propertiesChanged(this); + } ////// Directories ////// @@ -283,6 +298,12 @@ public: */ virtual SettingsObject &settings() const; +signals: + /*! + * \brief Signal emitted when properties relevant to the instance view change + */ + void propertiesChanged(Instance * inst); + private: QString m_rootDir; QString m_group; diff --git a/libmultimc/include/instancelist.h b/libmultimc/include/instancelist.h index 3eef8bdc..a0d8788a 100644 --- a/libmultimc/include/instancelist.h +++ b/libmultimc/include/instancelist.h @@ -78,6 +78,9 @@ signals: void instanceChanged(int index); void invalidated(); +private slots: + void propertiesChanged(Instance * inst); + protected: QString m_instDir; QList< InstancePtr > m_instances; diff --git a/libmultimc/src/instancelist.cpp b/libmultimc/src/instancelist.cpp index a835fcfe..f9c525d0 100644 --- a/libmultimc/src/instancelist.cpp +++ b/libmultimc/src/instancelist.cpp @@ -185,6 +185,7 @@ InstanceList::InstListError InstanceList::loadList() qDebug(QString("Loaded instance %1").arg(inst->name()).toUtf8()); inst->setParent(this); m_instances.append(inst); + connect(instPtr, SIGNAL(propertiesChanged(Instance*)),this, SLOT(propertiesChanged(Instance*))); } } } @@ -221,4 +222,16 @@ InstancePtr InstanceList::getInstanceById(QString instId) return InstancePtr(); else return iter.peekPrevious(); +} + +void InstanceList::propertiesChanged(Instance * inst) +{ + for(int i = 0; i < m_instances.count(); i++) + { + if(inst == m_instances[i].data()) + { + emit instanceChanged(i); + break; + } + } } \ No newline at end of file -- cgit From f4c9cb8c1d395422b7e4f1c27ac92b6df08a39bb Mon Sep 17 00:00:00 2001 From: Orochimarufan Date: Mon, 25 Feb 2013 22:47:03 +0100 Subject: refactor indendation, fix a bug in MinecraftProcess & fix a bug in InstanceLauncher --- java/constants.h | 8 +-- java/javautils.cpp | 86 ++++++++++++++++---------------- java/javautils.h | 4 +- libmultimc/include/minecraftprocess.h | 2 +- libmultimc/src/minecraftprocess.cpp | 2 + libsettings/include/keyring.h | 78 ++++++++++++++--------------- libsettings/src/keyring.cpp | 30 +++++------ libsettings/src/stubkeyring.cpp | 62 +++++++++++------------ libsettings/src/stubkeyring.h | 20 ++++---- libutil/include/cmdutils.h | 17 +++---- libutil/src/cmdutils.cpp | 16 +++--- main.cpp | 7 +-- test.cpp | 94 +++++++++++++++++------------------ 13 files changed, 211 insertions(+), 215 deletions(-) (limited to 'libmultimc/src') diff --git a/java/constants.h b/java/constants.h index 80697ebe..61aa5687 100644 --- a/java/constants.h +++ b/java/constants.h @@ -7,7 +7,7 @@ namespace java class constant { public: - enum type_t : uint8_t + enum type_t : uint8_t { j_hole = 0, // HACK: this is a hole in the array, because java is crazy j_string_data = 1, @@ -145,7 +145,7 @@ namespace java uint16_t descriptor_index; } name_and_type; }; - }; + }; /** * A helper class that represents the custom container used in Java class file for storage of constants @@ -185,7 +185,7 @@ namespace java index++; } } - } + } typedef std::vector container_type; /** * Access constants based on jar file index numbers (index of the first element is 1) @@ -208,5 +208,5 @@ namespace java } private: container_type constants; - }; + }; } diff --git a/java/javautils.cpp b/java/javautils.cpp index bf4b5cdf..4a359031 100644 --- a/java/javautils.cpp +++ b/java/javautils.cpp @@ -26,56 +26,56 @@ namespace javautils QString GetMinecraftJarVersion(QString jarName) { - QString version = MCVer_Unknown; + QString version = MCVer_Unknown; - // check if minecraft.jar exists - QFile jar(jarName); - if (!jar.exists()) - return version; + // check if minecraft.jar exists + QFile jar(jarName); + if (!jar.exists()) + return version; - // open minecraft.jar - QuaZip zip(&jar); - if (!zip.open(QuaZip::mdUnzip)) - return version; + // open minecraft.jar + QuaZip zip(&jar); + if (!zip.open(QuaZip::mdUnzip)) + return version; - // open Minecraft.class - zip.setCurrentFile("net/minecraft/client/Minecraft.class", QuaZip::csSensitive); - QuaZipFile Minecraft(&zip); - if (!Minecraft.open(QuaZipFile::ReadOnly)) - return version; + // open Minecraft.class + zip.setCurrentFile("net/minecraft/client/Minecraft.class", QuaZip::csSensitive); + QuaZipFile Minecraft(&zip); + if (!Minecraft.open(QuaZipFile::ReadOnly)) + return version; - // read Minecraft.class - qint64 size = Minecraft.size(); - char *classfile = new char[size]; - Minecraft.read(classfile, size); + // read Minecraft.class + qint64 size = Minecraft.size(); + char *classfile = new char[size]; + Minecraft.read(classfile, size); - // parse Minecraft.class - try { - char *temp = classfile; - java::classfile MinecraftClass(temp, size); - java::constant_pool constants = MinecraftClass.constants; - for(java::constant_pool::container_type::const_iterator iter=constants.begin(); - iter != constants.end(); iter++) - { - const java::constant & constant = *iter; - if (constant.type != java::constant::j_string_data) - continue; - const std::string & str = constant.str_data; - if (str.compare(0, 20, "Minecraft Minecraft ") == 0) - { - version = str.substr(20).data(); - break; - } - } - } catch(java::classfile_exception &) {} + // parse Minecraft.class + try { + char *temp = classfile; + java::classfile MinecraftClass(temp, size); + java::constant_pool constants = MinecraftClass.constants; + for(java::constant_pool::container_type::const_iterator iter=constants.begin(); + iter != constants.end(); iter++) + { + const java::constant & constant = *iter; + if (constant.type != java::constant::j_string_data) + continue; + const std::string & str = constant.str_data; + if (str.compare(0, 20, "Minecraft Minecraft ") == 0) + { + version = str.substr(20).data(); + break; + } + } + } catch(java::classfile_exception &) {} - // clean up - delete[] classfile; - Minecraft.close(); - zip.close(); - jar.close(); + // clean up + delete[] classfile; + Minecraft.close(); + zip.close(); + jar.close(); - return version; + return version; } } diff --git a/java/javautils.h b/java/javautils.h index 7f9b6d89..883eff1d 100644 --- a/java/javautils.h +++ b/java/javautils.h @@ -21,8 +21,8 @@ namespace javautils { - /** - * @brief Get the version from a minecraft.jar by parsing its class files. Expensive! + /** + * @brief Get the version from a minecraft.jar by parsing its class files. Expensive! */ QString GetMinecraftJarVersion(QString jar); } diff --git a/libmultimc/include/minecraftprocess.h b/libmultimc/include/minecraftprocess.h index 8986f7ad..d6b9f612 100644 --- a/libmultimc/include/minecraftprocess.h +++ b/libmultimc/include/minecraftprocess.h @@ -85,7 +85,7 @@ protected: QStringList m_arguments; void genArgs(); - void log(QString text); + void log(QString text, ConsoleWindow::WriteMode mode = ConsoleWindow::MULTIMC); protected slots: void finish(int, QProcess::ExitStatus status); diff --git a/libmultimc/src/minecraftprocess.cpp b/libmultimc/src/minecraftprocess.cpp index 943d76b1..3aecb1ee 100644 --- a/libmultimc/src/minecraftprocess.cpp +++ b/libmultimc/src/minecraftprocess.cpp @@ -197,6 +197,8 @@ void MinecraftProcess::launch() start(m_instance->settings().get("JavaPath").toString(), m_arguments); if (!waitForStarted()) { + log("Could not launch minecraft!", ConsoleWindow::ERROR); + return; //TODO: error handling } diff --git a/libsettings/include/keyring.h b/libsettings/include/keyring.h index 4563a268..afdc3bba 100644 --- a/libsettings/include/keyring.h +++ b/libsettings/include/keyring.h @@ -6,7 +6,7 @@ * 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 + * 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, @@ -33,53 +33,53 @@ */ class LIBMMCSETTINGS_EXPORT Keyring : public QObject { - Q_OBJECT + Q_OBJECT public: - /** - * @brief the System Keyring instance - * @return the Keyring instance - */ - static Keyring *instance(); + /** + * @brief the System Keyring instance + * @return the Keyring instance + */ + static Keyring *instance(); - /** - * @brief store a password in the Keyring - * @param service the service name - * @param username the account name - * @param password the password to store - * @return success - */ - virtual bool storePassword(QString service, QString username, QString password) = 0; + /** + * @brief store a password in the Keyring + * @param service the service name + * @param username the account name + * @param password the password to store + * @return success + */ + virtual bool storePassword(QString service, QString username, QString password) = 0; - /** - * @brief get a password from the Keyring - * @param service the service name - * @param username the account name - * @return the password (success=!isNull()) - */ - virtual QString getPassword(QString service, QString username) = 0; + /** + * @brief get a password from the Keyring + * @param service the service name + * @param username the account name + * @return the password (success=!isNull()) + */ + virtual QString getPassword(QString service, QString username) = 0; - /** - * @brief lookup a password - * @param service the service name - * @param username the account name - * @return wether the password is available - */ - virtual bool hasPassword(QString service, QString username) = 0; + /** + * @brief lookup a password + * @param service the service name + * @param username the account name + * @return wether the password is available + */ + virtual bool hasPassword(QString service, QString username) = 0; - /** - * @brief get a list of all stored accounts. - * @param service the service name - * @return - */ - virtual QStringList getStoredAccounts(QString service) = 0; + /** + * @brief get a list of all stored accounts. + * @param service the service name + * @return + */ + virtual QStringList getStoredAccounts(QString service) = 0; protected: - /// fall back to StubKeyring if false - virtual bool isValid() { return false; } + /// fall back to StubKeyring if false + virtual bool isValid() { return false; } private: - static Keyring *m_instance; - static void destroy(); + static Keyring *m_instance; + static void destroy(); }; #endif // KEYRING_H diff --git a/libsettings/src/keyring.cpp b/libsettings/src/keyring.cpp index 1b13e35c..9eaba684 100644 --- a/libsettings/src/keyring.cpp +++ b/libsettings/src/keyring.cpp @@ -6,7 +6,7 @@ * 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 + * 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, @@ -37,27 +37,27 @@ class Win32Keystore; Keyring *Keyring::instance() { - if (m_instance == nullptr) - { + if (m_instance == nullptr) + { #ifdef KEYRING - m_instance = new KEYRING(); - if (!m_instance->isValid()) - { - qWarning("Could not create SystemKeyring! falling back to StubKeyring."); - m_instance = new StubKeyring(); - } + m_instance = new KEYRING(); + if (!m_instance->isValid()) + { + qWarning("Could not create SystemKeyring! falling back to StubKeyring."); + m_instance = new StubKeyring(); + } #else - qWarning("Keyrings are not supported on your OS. Fallback StubKeyring is insecure!"); - m_instance = new StubKeyring(); + qWarning("Keyrings are not supported on your OS. Fallback StubKeyring is insecure!"); + m_instance = new StubKeyring(); #endif - atexit(Keyring::destroy); - } - return m_instance; + atexit(Keyring::destroy); + } + return m_instance; } void Keyring::destroy() { - delete m_instance; + delete m_instance; } Keyring *Keyring::m_instance; diff --git a/libsettings/src/stubkeyring.cpp b/libsettings/src/stubkeyring.cpp index 0e29d2f2..963f3dd9 100644 --- a/libsettings/src/stubkeyring.cpp +++ b/libsettings/src/stubkeyring.cpp @@ -6,7 +6,7 @@ * 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 + * 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, @@ -25,72 +25,72 @@ int scrambler = 0x9586309; QString scramble(QString in_) { - QByteArray in = in_.toUtf8(); - QByteArray out; - for (int i = 0; itype = OptionType::Switch; + param->type = otSwitch; param->name = name; param->metavar = QString("<%1>").arg(name); param->def = def; @@ -72,7 +72,7 @@ void Parser::addOption(QString name, QVariant def) throw "Name not unique"; OptionDef *param = new OptionDef; - param->type = OptionType::Option; + param->type = otOption; param->name = name; param->metavar = QString("<%1>").arg(name); param->def = def; @@ -161,7 +161,7 @@ QString Parser::compileHelp(QString progName, int helpIndent, bool useFlags) help << flagPrefix << option->flag << ", "; } help << optPrefix << option->name; - if (option->type == OptionType::Option) + if (option->type == otOption) { QString arg = QString("%1%2").arg(((m_argStyle == ArgumentStyle::Equals) ? "=" : " "), option->metavar); nameLength += arg.length(); @@ -193,7 +193,7 @@ QString Parser::compileUsage(QString progName, bool useFlags) usage << flagPrefix << option->flag; else usage << optPrefix << option->name; - if (option->type == OptionType::Option) + if (option->type == otOption) usage << ((m_argStyle == ArgumentStyle::Equals) ? "=" : " ") << option->metavar; usage << "]"; } @@ -265,9 +265,9 @@ QHash Parser::parse(QStringList argv) throw ParsingError(QString("Option %2%1 was given multiple times").arg(name, optionPrefix)); OptionDef *option = m_options[name]; - if (option->type == OptionType::Switch) + if (option->type == otSwitch) map[name] = true; - else //if (option->type == OptionType::Option) + else //if (option->type == otOption) { if (m_argStyle == ArgumentStyle::Space) expecting.append(name); @@ -312,9 +312,9 @@ QHash Parser::parse(QStringList argv) if (map.contains(option->name)) throw ParsingError(QString("Option %2%1 was given multiple times").arg(option->name, optionPrefix)); - if (option->type == OptionType::Switch) + if (option->type == otSwitch) map[option->name] = true; - else //if (option->type == OptionType::Option) + else //if (option->type == otOption) { if (m_argStyle == ArgumentStyle::Space) expecting.append(option->name); diff --git a/main.cpp b/main.cpp index cf193ff0..31d5277e 100644 --- a/main.cpp +++ b/main.cpp @@ -66,12 +66,9 @@ private: { inst = iter.next(); if (inst->id() == instId) - break; + return inst; } - if (inst->id() != instId) - return InstancePtr(); - else - return iter.peekPrevious(); + return InstancePtr(); } private slots: diff --git a/test.cpp b/test.cpp index 26600220..2b015454 100644 --- a/test.cpp +++ b/test.cpp @@ -10,51 +10,51 @@ using namespace Util::Commandline; int main(int argc, char **argv) { - QCoreApplication app(argc, argv); - app.setApplicationName("MMC Keyring test"); - app.setOrganizationName("Orochimarufan"); - - Parser p; - p.addArgument("user", false); - p.addArgument("password", false); - p.addSwitch("set"); - p.addSwitch("get"); - p.addSwitch("list"); - p.addOption("service", "Test"); - p.addShortOpt("service", 's'); - - QHash args; - try { - args = p.parse(app.arguments()); - } catch (ParsingError) { - std::cout << "Syntax error." << std::endl; - return 1; - } - - if (args["set"].toBool()) { - if (args["user"].isNull() || args["password"].isNull()) { - std::cout << "set operation needs bot user and password set" << std::endl; - return 1; - } - - return Keyring::instance()->storePassword(args["service"].toString(), - args["user"].toString(), args["password"].toString()); - } else if (args["get"].toBool()) { - if (args["user"].isNull()) { - std::cout << "get operation needs user set" << std::endl; - return 1; - } - - std::cout << "Password: " << qPrintable(Keyring::instance()->getPassword(args["service"].toString(), - args["user"].toString())) << std::endl; - return 0; - } else if (args["list"].toBool()) { - QStringList accounts = Keyring::instance()->getStoredAccounts(args["service"].toString()); - std::cout << "stored accounts:" << std::endl << '\t' << qPrintable(accounts.join("\n\t")) << std::endl; - return 0; - } else { - std::cout << "No operation given!" << std::endl; - std::cout << qPrintable(p.compileHelp(argv[0])) << std::endl; - return 1; - } + QCoreApplication app(argc, argv); + app.setApplicationName("MMC Keyring test"); + app.setOrganizationName("Orochimarufan"); + + Parser p; + p.addArgument("user", false); + p.addArgument("password", false); + p.addSwitch("set"); + p.addSwitch("get"); + p.addSwitch("list"); + p.addOption("service", "Test"); + p.addShortOpt("service", 's'); + + QHash args; + try { + args = p.parse(app.arguments()); + } catch (ParsingError) { + std::cout << "Syntax error." << std::endl; + return 1; + } + + if (args["set"].toBool()) { + if (args["user"].isNull() || args["password"].isNull()) { + std::cout << "set operation needs bot user and password set" << std::endl; + return 1; + } + + return Keyring::instance()->storePassword(args["service"].toString(), + args["user"].toString(), args["password"].toString()); + } else if (args["get"].toBool()) { + if (args["user"].isNull()) { + std::cout << "get operation needs user set" << std::endl; + return 1; + } + + std::cout << "Password: " << qPrintable(Keyring::instance()->getPassword(args["service"].toString(), + args["user"].toString())) << std::endl; + return 0; + } else if (args["list"].toBool()) { + QStringList accounts = Keyring::instance()->getStoredAccounts(args["service"].toString()); + std::cout << "stored accounts:" << std::endl << '\t' << qPrintable(accounts.join("\n\t")) << std::endl; + return 0; + } else { + std::cout << "No operation given!" << std::endl; + std::cout << qPrintable(p.compileHelp(argv[0])) << std::endl; + return 1; + } } -- cgit From e4f86893a899ee86cfa6d238f891bec04977c966 Mon Sep 17 00:00:00 2001 From: Orochimarufan Date: Fri, 22 Mar 2013 14:40:55 +0100 Subject: fix merge issues, make console window work again --- CMakeLists.txt | 2 +- gui/consolewindow.cpp | 77 ++++++++++---------- gui/consolewindow.h | 79 +++++++++----------- libmultimc/include/minecraftprocess.h | 132 ++++++++++++++++++++-------------- libmultimc/src/minecraftprocess.cpp | 22 ++---- libsettings/CMakeLists.txt | 11 ++- libsettings/include/keyring.h | 5 +- libsettings/src/stubkeyring.h | 1 - main.cpp | 1 + 9 files changed, 171 insertions(+), 159 deletions(-) (limited to 'libmultimc/src') diff --git a/CMakeLists.txt b/CMakeLists.txt index 742f47f6..97ff786c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -266,7 +266,7 @@ IF(DEFINED MMC_KEYRING_TEST) # test.cpp ADD_EXECUTABLE(Test test.cpp) QT5_USE_MODULES(Test Core) -TARGET_LINK_LIBRARIES(Test libmmcutil libmmcsettings) +TARGET_LINK_LIBRARIES(Test libUtil libSettings) ENDIF() ################################ INSTALLATION AND PACKAGING ################################ diff --git a/gui/consolewindow.cpp b/gui/consolewindow.cpp index 1d84fe04..811900a2 100644 --- a/gui/consolewindow.cpp +++ b/gui/consolewindow.cpp @@ -4,70 +4,71 @@ #include ConsoleWindow::ConsoleWindow(QWidget *parent) : - QDialog(parent), - ui(new Ui::ConsoleWindow), - m_mayclose(true) + QDialog(parent), + ui(new Ui::ConsoleWindow), + m_mayclose(true) { - ui->setupUi(this); + ui->setupUi(this); } ConsoleWindow::~ConsoleWindow() { - delete ui; + delete ui; } void ConsoleWindow::writeColor(QString text, const char *color) { - // append a paragraph - if (color != nullptr) - ui->text->appendHtml(QString("%2").arg(color).arg(text)); - else - ui->text->appendPlainText(text); - // scroll down - QScrollBar *bar = ui->text->verticalScrollBar(); - bar->setValue(bar->maximum()); + // append a paragraph + if (color != nullptr) + ui->text->appendHtml(QString("%2").arg(color).arg(text)); + else + ui->text->appendPlainText(text); + // scroll down + QScrollBar *bar = ui->text->verticalScrollBar(); + bar->setValue(bar->maximum()); } -void ConsoleWindow::write(QString data, WriteMode mode) +void ConsoleWindow::write(QString data, MessageLevel::Enum mode) { - if (data.endsWith('\n')) - data = data.left(data.length()-1); - QStringList paragraphs = data.split('\n'); - QListIterator iter(paragraphs); - if (mode == MULTIMC) - while(iter.hasNext()) - writeColor(iter.next(), "blue"); - else if (mode == ERROR) - while(iter.hasNext()) - writeColor(iter.next(), "red"); - else - while(iter.hasNext()) - writeColor(iter.next()); + if (data.endsWith('\n')) + data = data.left(data.length()-1); + QStringList paragraphs = data.split('\n'); + QListIterator iter(paragraphs); + if (mode == MessageLevel::MultiMC) + while(iter.hasNext()) + writeColor(iter.next(), "blue"); + else if (mode == MessageLevel::Error) + while(iter.hasNext()) + writeColor(iter.next(), "red"); + // TODO: implement other MessageLevels + else + while(iter.hasNext()) + writeColor(iter.next()); } void ConsoleWindow::clear() { - ui->text->clear(); + ui->text->clear(); } void ConsoleWindow::on_closeButton_clicked() { - close(); + close(); } void ConsoleWindow::setMayClose(bool mayclose) { - m_mayclose = mayclose; - if (mayclose) - ui->closeButton->setEnabled(true); - else - ui->closeButton->setEnabled(false); + m_mayclose = mayclose; + if (mayclose) + ui->closeButton->setEnabled(true); + else + ui->closeButton->setEnabled(false); } void ConsoleWindow::closeEvent(QCloseEvent * event) { - if(!m_mayclose) - event->ignore(); - else - QDialog::closeEvent(event); + if(!m_mayclose) + event->ignore(); + else + QDialog::closeEvent(event); } diff --git a/gui/consolewindow.h b/gui/consolewindow.h index 1d322afb..5490bc92 100644 --- a/gui/consolewindow.h +++ b/gui/consolewindow.h @@ -2,6 +2,7 @@ #define CONSOLEWINDOW_H #include +#include "minecraftprocess.h" namespace Ui { class ConsoleWindow; @@ -9,61 +10,51 @@ class ConsoleWindow; class ConsoleWindow : public QDialog { - Q_OBJECT + Q_OBJECT public: - /** - * @brief The WriteMode enum - * defines how stuff is displayed - */ - enum WriteMode { - DEFAULT, - ERROR, - MULTIMC - }; + explicit ConsoleWindow(QWidget *parent = 0); + ~ConsoleWindow(); - explicit ConsoleWindow(QWidget *parent = 0); - ~ConsoleWindow(); - - /** - * @brief specify if the window is allowed to close - * @param mayclose - * used to keep it alive while MC runs - */ - void setMayClose(bool mayclose); + /** + * @brief specify if the window is allowed to close + * @param mayclose + * used to keep it alive while MC runs + */ + void setMayClose(bool mayclose); public slots: - /** - * @brief write a string - * @param data the string - * @param mode the WriteMode - * lines have to be put through this as a whole! - */ - void write(QString data, WriteMode mode=MULTIMC); - - /** - * @brief write a colored paragraph - * @param data the string - * @param color the css color name - * this will only insert a single paragraph. - * \n are ignored. a real \n is always appended. - */ - void writeColor(QString data, const char *color=nullptr); - - /** - * @brief clear the text widget - */ - void clear(); + /** + * @brief write a string + * @param data the string + * @param mode the WriteMode + * lines have to be put through this as a whole! + */ + void write(QString data, MessageLevel::Enum level=MessageLevel::MultiMC); + + /** + * @brief write a colored paragraph + * @param data the string + * @param color the css color name + * this will only insert a single paragraph. + * \n are ignored. a real \n is always appended. + */ + void writeColor(QString data, const char *color=nullptr); + + /** + * @brief clear the text widget + */ + void clear(); private slots: - void on_closeButton_clicked(); + void on_closeButton_clicked(); protected: - void closeEvent(QCloseEvent *); + void closeEvent(QCloseEvent *); private: - Ui::ConsoleWindow *ui; - bool m_mayclose; + Ui::ConsoleWindow *ui; + bool m_mayclose; }; #endif // CONSOLEWINDOW_H diff --git a/libmultimc/include/minecraftprocess.h b/libmultimc/include/minecraftprocess.h index d6b9f612..f6272183 100644 --- a/libmultimc/include/minecraftprocess.h +++ b/libmultimc/include/minecraftprocess.h @@ -6,7 +6,7 @@ * 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 + * 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, @@ -23,74 +23,96 @@ #include "libmmc_config.h" +/** + * @brief the MessageLevel Enum + * defines what level a message is + */ +namespace MessageLevel { +enum LIBMULTIMC_EXPORT Enum { + MultiMC, /**< MultiMC Messages */ + Debug, /**< Debug Messages */ + Info, /**< Info Messages */ + Message, /**< Standard Messages */ + Warning, /**< Warnings */ + Error, /**< Errors */ + Fatal /**< Fatal Errors */ +}; +} + /** * @file data/minecraftprocess.h * @brief The MinecraftProcess class */ class LIBMULTIMC_EXPORT MinecraftProcess : public QProcess { - Q_OBJECT + Q_OBJECT public: - /** - * @brief MinecraftProcess constructor - * @param inst the Instance pointer to launch - * @param user the minecraft username - * @param session the minecraft session id - * @param console the instance console window - */ - MinecraftProcess(InstancePtr inst, QString user, QString session); - - /** - * @brief launch minecraft - */ - void launch(); - - /** - * @brief extract the instance icon - * @param inst the instance - * @param destination the destination path - */ - static inline void extractIcon(InstancePtr inst, QString destination); - - /** - * @brief extract the MultiMC launcher.jar - * @param destination the destination path - */ - static inline void extractLauncher(QString destination); - - /** - * @brief prepare the launch by extracting icon and launcher - * @param inst the instance - */ - static void prepare(InstancePtr inst); - - /** - * @brief split a string into argv items like a shell would do - * @param args the argument string - * @return a QStringList containing all arguments - */ - static QStringList splitArgs(QString args); + /** + * @brief MinecraftProcess constructor + * @param inst the Instance pointer to launch + * @param user the minecraft username + * @param session the minecraft session id + * @param console the instance console window + */ + MinecraftProcess(InstancePtr inst, QString user, QString session); + + /** + * @brief launch minecraft + */ + void launch(); + + /** + * @brief extract the instance icon + * @param inst the instance + * @param destination the destination path + */ + static inline void extractIcon(InstancePtr inst, QString destination); + + /** + * @brief extract the MultiMC launcher.jar + * @param destination the destination path + */ + static inline void extractLauncher(QString destination); + + /** + * @brief prepare the launch by extracting icon and launcher + * @param inst the instance + */ + static void prepare(InstancePtr inst); + + /** + * @brief split a string into argv items like a shell would do + * @param args the argument string + * @return a QStringList containing all arguments + */ + static QStringList splitArgs(QString args); signals: - /** - * @brief emitted when mc has finished and the PostLaunchCommand was run - */ - void ended(); + /** + * @brief emitted when mc has finished and the PostLaunchCommand was run + */ + void ended(); + + /** + * @brief emitted when we want to log something + * @param text the text to log + * @param level the level to log at + */ + void log(QString text, MessageLevel::Enum level=MessageLevel::MultiMC); protected: - InstancePtr m_instance; - QString m_user; - QString m_session; - QProcess m_prepostlaunchprocess; - QStringList m_arguments; + InstancePtr m_instance; + QString m_user; + QString m_session; + QProcess m_prepostlaunchprocess; + QStringList m_arguments; - void genArgs(); - void log(QString text, ConsoleWindow::WriteMode mode = ConsoleWindow::MULTIMC); + void genArgs(); protected slots: - void finish(int, QProcess::ExitStatus status); - void on_stdErr(); - void on_stdOut(); + void finish(int, QProcess::ExitStatus status); + void on_stdErr(); + void on_stdOut(); }; diff --git a/libmultimc/src/minecraftprocess.cpp b/libmultimc/src/minecraftprocess.cpp index 3aecb1ee..e22a536c 100644 --- a/libmultimc/src/minecraftprocess.cpp +++ b/libmultimc/src/minecraftprocess.cpp @@ -125,22 +125,12 @@ MinecraftProcess::MinecraftProcess(InstancePtr inst, QString user, QString sessi // console window void MinecraftProcess::on_stdErr() { -// if (m_console != nullptr) -// m_console->write(readAllStandardError(), ConsoleWindow::ERROR); + emit log(readAllStandardError(), MessageLevel::Error); } void MinecraftProcess::on_stdOut() { -// if (m_console != nullptr) -// m_console->write(readAllStandardOutput(), ConsoleWindow::DEFAULT); -} - -void MinecraftProcess::log(QString text) -{ -// if (m_console != nullptr) -// m_console->write(text); -// else - qDebug(qPrintable(text)); + emit log(readAllStandardOutput(), MessageLevel::Message); } // exit handler @@ -151,7 +141,7 @@ void MinecraftProcess::finish(int code, ExitStatus status) //TODO: error handling } - log("Minecraft exited."); + emit log("Minecraft exited."); m_prepostlaunchprocess.processEnvironment().insert("INST_EXITCODE", QString(code)); @@ -191,13 +181,13 @@ void MinecraftProcess::launch() genArgs(); - log(QString("Minecraft folder is: '%1'").arg(workingDirectory())); - log(QString("Instance launched with arguments: '%1'").arg(m_arguments.join("' '"))); + emit log(QString("Minecraft folder is: '%1'").arg(workingDirectory())); + emit log(QString("Instance launched with arguments: '%1'").arg(m_arguments.join("' '"))); start(m_instance->settings().get("JavaPath").toString(), m_arguments); if (!waitForStarted()) { - log("Could not launch minecraft!", ConsoleWindow::ERROR); + emit log("Could not launch minecraft!"); return; //TODO: error handling } diff --git a/libsettings/CMakeLists.txt b/libsettings/CMakeLists.txt index 9ae48354..e5aae0b7 100644 --- a/libsettings/CMakeLists.txt +++ b/libsettings/CMakeLists.txt @@ -18,6 +18,12 @@ include/overridesetting.h include/basicsettingsobject.h include/inisettingsobject.h + +include/keyring.h +) + +SET(LIBSETTINGS_HEADERS_PRIVATE +src/stubkeyring.h ) SET(LIBSETTINGS_SOURCES @@ -29,6 +35,9 @@ src/overridesetting.cpp src/basicsettingsobject.cpp src/inisettingsobject.cpp + +src/keyring.cpp +src/stubkeyring.cpp ) # Set the include dir path. @@ -37,6 +46,6 @@ include_directories(${LIBSETTINGS_INCLUDE_DIR}) add_definitions(-DLIBSETTINGS_LIBRARY) -add_library(libSettings SHARED ${LIBSETTINGS_SOURCES} ${LIBSETTINGS_HEADERS}) +add_library(libSettings SHARED ${LIBSETTINGS_SOURCES} ${LIBSETTINGS_HEADERS} ${LIBSETTINGS_HEADERS_PRIVATE}) qt5_use_modules(libSettings Core) target_link_libraries(libSettings) diff --git a/libsettings/include/keyring.h b/libsettings/include/keyring.h index afdc3bba..5774e287 100644 --- a/libsettings/include/keyring.h +++ b/libsettings/include/keyring.h @@ -18,7 +18,7 @@ #ifndef KEYRING_H #define KEYRING_H -#include +#include #include "libsettings_config.h" @@ -31,9 +31,8 @@ * @brief The Keyring class * the System Keyring/Keychain/Wallet/Vault/etc */ -class LIBMMCSETTINGS_EXPORT Keyring : public QObject +class LIBSETTINGS_EXPORT Keyring { - Q_OBJECT public: /** * @brief the System Keyring instance diff --git a/libsettings/src/stubkeyring.h b/libsettings/src/stubkeyring.h index 0566d5ab..b5f04e4c 100644 --- a/libsettings/src/stubkeyring.h +++ b/libsettings/src/stubkeyring.h @@ -24,7 +24,6 @@ class StubKeyring : public Keyring { - Q_OBJECT public: virtual bool storePassword(QString service, QString username, QString password); virtual QString getPassword(QString service, QString username); diff --git a/main.cpp b/main.cpp index 7c82d6d8..4239d70f 100644 --- a/main.cpp +++ b/main.cpp @@ -72,6 +72,7 @@ private slots: //if (instance->getShowConsole()) console->show(); connect(proc, SIGNAL(ended()), SLOT(onTerminated())); + connect(proc, SIGNAL(log(QString,MessageLevel::Enum)), console, SLOT(write(QString,MessageLevel::Enum))); proc->launch(); } -- cgit From 40570c321069b832722b807227fd8ff9bbd7c10d Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 24 Mar 2013 15:36:00 +0100 Subject: Fix settings objects, instances can be started from the GUI now --- gui/mainwindow.cpp | 20 ++++++++++++++++++++ gui/mainwindow.h | 4 ++++ libmultimc/src/instance.cpp | 6 ++++++ libmultimc/src/minecraftprocess.cpp | 7 ++++--- libsettings/src/basicsettingsobject.cpp | 5 ++++- libsettings/src/inisettingsobject.cpp | 5 ++++- libsettings/src/setting.cpp | 9 ++++++++- resources/icons/instances/clucker.svg | 12 ++++++------ 8 files changed, 56 insertions(+), 12 deletions(-) (limited to 'libmultimc/src') diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 5a915e8c..408a61c5 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -39,6 +39,7 @@ #include "gui/taskdialog.h" #include "gui/browserdialog.h" #include "gui/aboutdialog.h" +#include "gui/consolewindow.h" #include "kcategorizedview.h" #include "kcategorydrawer.h" @@ -49,6 +50,7 @@ #include "logintask.h" #include +#include "minecraftprocess.h" #include "instancemodel.h" #include "instancedelegate.h" @@ -276,9 +278,27 @@ void MainWindow::doLogin ( QString inst, const QString& errorMsg ) void MainWindow::onLoginComplete ( QString inst, LoginResponse response ) { + // TODO: console + console = new ConsoleWindow(); + auto instance = instList.getInstanceById(inst); + if(instance) + { + proc = new MinecraftProcess(instance, response.username(), response.sessionID()); + + console->show(); + //connect(proc, SIGNAL(ended()), SLOT(onTerminated())); + connect(proc, SIGNAL(log(QString,MessageLevel::Enum)), console, SLOT(write(QString,MessageLevel::Enum))); + proc->launch(); + } + else + { + + } + /* QMessageBox::information ( this, "Login Successful", QString ( "Logged in as %1 with session ID %2. Instance: %3" ). arg ( response.username(), response.sessionID(), inst ) ); + */ } void MainWindow::onLoginFailed ( QString inst, const QString& errorMsg ) diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 5d990639..eec09972 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -26,6 +26,8 @@ class InstanceModel; class InstanceProxyModel; class KCategorizedView; class KCategoryDrawer; +class MinecraftProcess; +class ConsoleWindow; namespace Ui { @@ -94,6 +96,8 @@ private: InstanceModel * model; InstanceProxyModel * proxymodel; InstanceList instList; + MinecraftProcess *proc; + ConsoleWindow *console; }; #endif // MAINWINDOW_H diff --git a/libmultimc/src/instance.cpp b/libmultimc/src/instance.cpp index 1af359d1..f9e105c7 100644 --- a/libmultimc/src/instance.cpp +++ b/libmultimc/src/instance.cpp @@ -48,6 +48,12 @@ Instance::Instance(const QString &rootDir, QObject *parent) : settings().registerSetting(new OverrideSetting("PostExitCommand", globalSettings->getSetting("PostExitCommand"))); + // Window Size + settings().registerSetting(new OverrideSetting("LaunchCompatMode", globalSettings->getSetting("LaunchCompatMode"))); + settings().registerSetting(new OverrideSetting("LaunchMaximized", globalSettings->getSetting("LaunchMaximized"))); + settings().registerSetting(new OverrideSetting("MinecraftWinWidth", globalSettings->getSetting("MinecraftWinWidth"))); + settings().registerSetting(new OverrideSetting("MinecraftWinHeight", globalSettings->getSetting("MinecraftWinHeight"))); + // Memory settings().registerSetting(new OverrideSetting("MinMemAlloc", globalSettings->getSetting("MinMemAlloc"))); settings().registerSetting(new OverrideSetting("MaxMemAlloc", globalSettings->getSetting("MaxMemAlloc"))); diff --git a/libmultimc/src/minecraftprocess.cpp b/libmultimc/src/minecraftprocess.cpp index e22a536c..1239bc3a 100644 --- a/libmultimc/src/minecraftprocess.cpp +++ b/libmultimc/src/minecraftprocess.cpp @@ -182,9 +182,10 @@ void MinecraftProcess::launch() genArgs(); emit log(QString("Minecraft folder is: '%1'").arg(workingDirectory())); - emit log(QString("Instance launched with arguments: '%1'").arg(m_arguments.join("' '"))); - - start(m_instance->settings().get("JavaPath").toString(), m_arguments); + QString JavaPath = m_instance->settings().get("JavaPath").toString(); + emit log(QString("Java path: '%1'").arg(JavaPath)); + emit log(QString("Arguments: '%1'").arg(m_arguments.join("' '"))); + start(JavaPath, m_arguments); if (!waitForStarted()) { emit log("Could not launch minecraft!"); diff --git a/libsettings/src/basicsettingsobject.cpp b/libsettings/src/basicsettingsobject.cpp index 66a2c2c8..484928c8 100644 --- a/libsettings/src/basicsettingsobject.cpp +++ b/libsettings/src/basicsettingsobject.cpp @@ -26,7 +26,10 @@ void BasicSettingsObject::changeSetting(const Setting &setting, QVariant value) { if (contains(setting.id())) { - config.setValue(setting.configKey(), value); + if(value.isValid()) + config.setValue(setting.configKey(), value); + else + config.remove(setting.configKey()); } } diff --git a/libsettings/src/inisettingsobject.cpp b/libsettings/src/inisettingsobject.cpp index 75228865..8c4cc89d 100644 --- a/libsettings/src/inisettingsobject.cpp +++ b/libsettings/src/inisettingsobject.cpp @@ -32,7 +32,10 @@ void INISettingsObject::changeSetting(const Setting &setting, QVariant value) { if (contains(setting.id())) { - m_ini.set(setting.configKey(), value); + if(value.isValid()) + m_ini.set(setting.configKey(), value); + else + m_ini.remove(setting.configKey()); } } diff --git a/libsettings/src/setting.cpp b/libsettings/src/setting.cpp index a224ad39..1a4f9e13 100644 --- a/libsettings/src/setting.cpp +++ b/libsettings/src/setting.cpp @@ -26,9 +26,16 @@ QVariant Setting::get() const { SettingsObject *sbase = qobject_cast(parent()); if (!sbase) + { return defValue(); + } else - return sbase->retrieveValue(*this); + { + QVariant test = sbase->retrieveValue(*this); + if(!test.isValid()) + return defValue(); + return test; + } } QVariant Setting::defValue() const diff --git a/resources/icons/instances/clucker.svg b/resources/icons/instances/clucker.svg index 3ce6ad5c..0c1727eb 100644 --- a/resources/icons/instances/clucker.svg +++ b/resources/icons/instances/clucker.svg @@ -14,7 +14,7 @@ height="32" id="svg2" version="1.1" - inkscape:version="0.48.3.1 r9886" + inkscape:version="0.48.4 r9939" sodipodi:docname="clucker.svg" inkscape:export-filename="/home/peterix/projects/MultiMC4/src/resources/insticons/chicken128.png" inkscape:export-xdpi="360" @@ -234,13 +234,13 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="2" - inkscape:cx="-92.12757" - inkscape:cy="71.871222" + inkscape:zoom="11.313708" + inkscape:cx="2.6058272" + inkscape:cy="11.408405" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="false" - inkscape:window-width="1607" + inkscape:window-width="1614" inkscape:window-height="1030" inkscape:window-x="1676" inkscape:window-y="-3" @@ -261,7 +261,7 @@ image/svg+xml - + -- cgit From d24c4823ef8e144a3ffefc208c5a15e86b0b31b1 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Tue, 26 Mar 2013 14:34:34 +0100 Subject: Filter console output, no more sea of red when there's nothing to report. --- libmultimc/include/minecraftprocess.h | 2 ++ libmultimc/src/minecraftprocess.cpp | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) (limited to 'libmultimc/src') diff --git a/libmultimc/include/minecraftprocess.h b/libmultimc/include/minecraftprocess.h index f6272183..ac4d6be2 100644 --- a/libmultimc/include/minecraftprocess.h +++ b/libmultimc/include/minecraftprocess.h @@ -104,6 +104,8 @@ protected: InstancePtr m_instance; QString m_user; QString m_session; + QString m_err_leftover; + QString m_out_leftover; QProcess m_prepostlaunchprocess; QStringList m_arguments; diff --git a/libmultimc/src/minecraftprocess.cpp b/libmultimc/src/minecraftprocess.cpp index 1239bc3a..f1b63e3d 100644 --- a/libmultimc/src/minecraftprocess.cpp +++ b/libmultimc/src/minecraftprocess.cpp @@ -125,12 +125,41 @@ MinecraftProcess::MinecraftProcess(InstancePtr inst, QString user, QString sessi // console window void MinecraftProcess::on_stdErr() { - emit log(readAllStandardError(), MessageLevel::Error); + QByteArray data = readAllStandardError(); + QString str = m_err_leftover + QString::fromLocal8Bit(data); + m_err_leftover.clear(); + QStringList lines = str.split("\n"); + bool complete = str.endsWith("\n"); + + for(int i = 0; i < lines.size() - 1; i++) + { + QString & line = lines[i]; + MessageLevel::Enum level = MessageLevel::Error; + if(line.contains("[INFO]") || line.contains("[CONFIG]") || line.contains("[FINE]") || line.contains("[FINER]") || line.contains("[FINEST]") ) + level = MessageLevel::Message; + if(line.contains("[SEVERE]") || line.contains("[WARNING]") || line.contains("[STDERR]")) + level = MessageLevel::Error; + emit log(lines[i].toLocal8Bit(), level); + } + if(!complete) + m_err_leftover = lines.last(); } void MinecraftProcess::on_stdOut() { - emit log(readAllStandardOutput(), MessageLevel::Message); + QByteArray data = readAllStandardOutput(); + QString str = m_out_leftover + QString::fromLocal8Bit(data); + m_out_leftover.clear(); + QStringList lines = str.split("\n"); + bool complete = str.endsWith("\n"); + + for(int i = 0; i < lines.size() - 1; i++) + { + QString & line = lines[i]; + emit log(lines[i].toLocal8Bit(), MessageLevel::Message); + } + if(!complete) + m_out_leftover = lines.last(); } // exit handler -- cgit