From 88318561724cae6d19f892adf778d85e6c736391 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Wed, 27 Nov 2013 15:00:44 +0100 Subject: Remember the last selected instance and select it on startup --- logic/lists/InstanceList.cpp | 9 +++++++-- logic/lists/InstanceList.h | 6 ++++-- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'logic/lists') diff --git a/logic/lists/InstanceList.cpp b/logic/lists/InstanceList.cpp index 7081dc6f..200b02df 100644 --- a/logic/lists/InstanceList.cpp +++ b/logic/lists/InstanceList.cpp @@ -362,7 +362,7 @@ int InstanceList::add(InstancePtr t) return count() - 1; } -InstancePtr InstanceList::getInstanceById(QString instId) +InstancePtr InstanceList::getInstanceById(QString instId) const { QListIterator iter(m_instances); InstancePtr inst; @@ -378,7 +378,12 @@ InstancePtr InstanceList::getInstanceById(QString instId) return iter.peekPrevious(); } -int InstanceList::getInstIndex(BaseInstance *inst) +QModelIndex InstanceList::getInstanceIndexById(const QString &id) const +{ + return index(getInstIndex(getInstanceById(id).get())); +} + +int InstanceList::getInstIndex(BaseInstance *inst) const { for (int i = 0; i < m_instances.count(); i++) { diff --git a/logic/lists/InstanceList.h b/logic/lists/InstanceList.h index d08501eb..8cd39746 100644 --- a/logic/lists/InstanceList.h +++ b/logic/lists/InstanceList.h @@ -91,7 +91,9 @@ public: int add(InstancePtr t); /// Get an instance by ID - InstancePtr getInstanceById(QString id); + InstancePtr getInstanceById(QString id) const; + + QModelIndex getInstanceIndexById(const QString &id) const; signals: void dataIsInvalid(); @@ -106,7 +108,7 @@ slots: void groupChanged(); private: - int getInstIndex(BaseInstance *inst); + int getInstIndex(BaseInstance *inst) const; protected: QString m_instDir; -- cgit v1.2.3 From 8334b6a09f2a74ad7a6652f3d4a3d5ab9beca1a0 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Wed, 27 Nov 2013 15:41:36 +0100 Subject: Fix crash when no instances are available --- logic/lists/InstanceList.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'logic/lists') diff --git a/logic/lists/InstanceList.cpp b/logic/lists/InstanceList.cpp index 200b02df..72748b5f 100644 --- a/logic/lists/InstanceList.cpp +++ b/logic/lists/InstanceList.cpp @@ -364,6 +364,11 @@ int InstanceList::add(InstancePtr t) InstancePtr InstanceList::getInstanceById(QString instId) const { + if (m_instances.isEmpty()) + { + return InstancePtr(); + } + QListIterator iter(m_instances); InstancePtr inst; while (iter.hasNext()) -- cgit v1.2.3 From f27a6c39ea796f946893ced1d9f80441ad9aa18c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 1 Dec 2013 02:00:42 +0100 Subject: Fix login and startup logging issues Auth uses the refresh endpoint instead of validate. This means less password entering. Console will now only autoscroll when already scrolled all the way down. Better conformance with the Yggdrasil auth protocol (not complete yet, but Mojang launcher isn't complete either). Fix bug that prevented saving the account data (uninitialized variable). Accounts can now trigger account list saving, this is used for the refresh endpoint. --- logic/lists/MojangAccountList.cpp | 33 ++++++++++++++++++--------------- logic/lists/MojangAccountList.h | 30 ++++++++++++++++++------------ 2 files changed, 36 insertions(+), 27 deletions(-) (limited to 'logic/lists') diff --git a/logic/lists/MojangAccountList.cpp b/logic/lists/MojangAccountList.cpp index ec1937ad..466cc934 100644 --- a/logic/lists/MojangAccountList.cpp +++ b/logic/lists/MojangAccountList.cpp @@ -44,7 +44,6 @@ MojangAccountPtr MojangAccountList::findAccount(const QString &username) const return nullptr; } - const MojangAccountPtr MojangAccountList::at(int i) const { return MojangAccountPtr(m_accounts.at(i)); @@ -53,12 +52,13 @@ const MojangAccountPtr MojangAccountList::at(int i) const void MojangAccountList::addAccount(const MojangAccountPtr account) { beginResetModel(); + connect(account.get(), SIGNAL(changed()), SLOT(accountChanged())); m_accounts.append(account); endResetModel(); onListChanged(); } -void MojangAccountList::removeAccount(const QString& username) +void MojangAccountList::removeAccount(const QString &username) { beginResetModel(); for (auto account : m_accounts) @@ -81,7 +81,6 @@ void MojangAccountList::removeAccount(QModelIndex index) onListChanged(); } - MojangAccountPtr MojangAccountList::activeAccount() const { if (m_activeAccount.isEmpty()) @@ -90,7 +89,7 @@ MojangAccountPtr MojangAccountList::activeAccount() const return findAccount(m_activeAccount); } -void MojangAccountList::setActiveAccount(const QString& username) +void MojangAccountList::setActiveAccount(const QString &username) { beginResetModel(); if (username.isEmpty()) @@ -109,6 +108,11 @@ void MojangAccountList::setActiveAccount(const QString& username) onActiveChanged(); } +void MojangAccountList::accountChanged() +{ + // the list changed. there is no doubt. + onListChanged(); +} void MojangAccountList::onListChanged() { @@ -127,13 +131,11 @@ void MojangAccountList::onActiveChanged() emit activeAccountChanged(); } - int MojangAccountList::count() const { return m_accounts.count(); } - QVariant MojangAccountList::data(const QModelIndex &index, int role) const { if (!index.isValid()) @@ -220,10 +222,11 @@ void MojangAccountList::updateListData(QList versions) endResetModel(); } -bool MojangAccountList::loadList(const QString& filePath) +bool MojangAccountList::loadList(const QString &filePath) { QString path = filePath; - if (path.isEmpty()) path = m_listFilePath; + if (path.isEmpty()) + path = m_listFilePath; if (path.isEmpty()) { QLOG_ERROR() << "Can't load Mojang account list. No file path given and no default set."; @@ -231,7 +234,7 @@ bool MojangAccountList::loadList(const QString& filePath) } QFile file(path); - + // Try to open the file and fail if we can't. // TODO: We should probably report this error to the user. if (!file.open(QIODevice::ReadOnly)) @@ -286,6 +289,7 @@ bool MojangAccountList::loadList(const QString& filePath) MojangAccountPtr account = MojangAccount::loadFromJson(accountObj); if (account.get() != nullptr) { + connect(account.get(), SIGNAL(changed()), SLOT(accountChanged())); m_accounts.append(account); } else @@ -297,14 +301,15 @@ bool MojangAccountList::loadList(const QString& filePath) // Load the active account. m_activeAccount = root.value("activeAccount").toString(""); - + return true; } -bool MojangAccountList::saveList(const QString& filePath) +bool MojangAccountList::saveList(const QString &filePath) { QString path(filePath); - if (path.isEmpty()) path = m_listFilePath; + if (path.isEmpty()) + path = m_listFilePath; if (path.isEmpty()) { QLOG_ERROR() << "Can't save Mojang account list. No file path given and no default set."; @@ -337,7 +342,6 @@ bool MojangAccountList::saveList(const QString& filePath) // Create a JSON document object to convert our JSON to bytes. QJsonDocument doc(root); - // Now that we're done building the JSON object, we can write it to the file. QLOG_DEBUG() << "Writing account list to file."; QFile file(path); @@ -362,6 +366,5 @@ bool MojangAccountList::saveList(const QString& filePath) void MojangAccountList::setListFilePath(QString path, bool autosave) { m_listFilePath = path; - autosave = autosave; + m_autosave = autosave; } - diff --git a/logic/lists/MojangAccountList.h b/logic/lists/MojangAccountList.h index 908f5a7a..744f3c51 100644 --- a/logic/lists/MojangAccountList.h +++ b/logic/lists/MojangAccountList.h @@ -22,7 +22,6 @@ #include "logic/auth/MojangAccount.h" - /*! * \brief List of available Mojang accounts. * This should be loaded in the background by MultiMC on startup. @@ -44,10 +43,10 @@ public: enum VListColumns { // TODO: Add icon column. - + // First column - Active? ActiveColumn = 0, - + // Second column - Name NameColumn, }; @@ -74,7 +73,7 @@ public: /*! * Removes the mojang account with the given username from the account list. */ - virtual void removeAccount(const QString& username); + virtual void removeAccount(const QString &username); /*! * Removes the account at the given QModelIndex. @@ -88,7 +87,7 @@ public: * one doesn't exist. */ virtual MojangAccountPtr findAccount(const QString &username) const; - + /*! * Sets the default path to save the list file to. * If autosave is true, this list will automatically save to the given path whenever it changes. @@ -96,21 +95,21 @@ public: * after calling this function to ensure an autosaved change doesn't overwrite the list you intended * to load. */ - virtual void setListFilePath(QString path, bool autosave=false); + virtual void setListFilePath(QString path, bool autosave = false); /*! * \brief Loads the account list from the given file path. * If the given file is an empty string (default), will load from the default account list file. * \return True if successful, otherwise false. */ - virtual bool loadList(const QString& file=""); + virtual bool loadList(const QString &file = ""); /*! * \brief Saves the account list to the given file. * If the given file is an empty string (default), will save from the default account list file. * \return True if successful, otherwise false. */ - virtual bool saveList(const QString& file=""); + virtual bool saveList(const QString &file = ""); /*! * \brief Gets a pointer to the account that the user has selected as their "active" account. @@ -124,12 +123,13 @@ public: * Sets the given account as the current active account. * If the username given is an empty string, sets the active account to nothing. */ - virtual void setActiveAccount(const QString& username); + virtual void setActiveAccount(const QString &username); signals: /*! * Signal emitted to indicate that the account list has changed. - * This will also fire if the value of an element in the list changes (will be implemented later). + * This will also fire if the value of an element in the list changes (will be implemented + * later). */ void listChanged(); @@ -138,6 +138,13 @@ signals: */ void activeAccountChanged(); +public +slots: + /** + * This is called when one of the accounts changes and the list needs to be updated + */ + void accountChanged(); + protected: /*! * Called whenever the list changes. @@ -166,7 +173,7 @@ protected: * If true, the account list will automatically save to the account list path when it changes. * Ignored if m_listFilePath is blank. */ - bool m_autosave; + bool m_autosave = false; protected slots: @@ -184,4 +191,3 @@ slots: */ virtual void updateListData(QList versions); }; - -- cgit v1.2.3 From f56eff04ef4d23b62a6e095eca5d4b9f2b52e023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 1 Dec 2013 16:34:51 +0100 Subject: Fix (hopefully) library dependency resolution. Installing libs is now enabled, hardcoded. Enable -Wall for all builds. Fix many warnings and latent bugs. --- logic/lists/InstanceList.cpp | 8 -------- 1 file changed, 8 deletions(-) (limited to 'logic/lists') diff --git a/logic/lists/InstanceList.cpp b/logic/lists/InstanceList.cpp index 72748b5f..b9595578 100644 --- a/logic/lists/InstanceList.cpp +++ b/logic/lists/InstanceList.cpp @@ -281,14 +281,6 @@ InstanceList::InstListError InstanceList::loadList() auto &loader = InstanceFactory::get(); auto error = loader.loadInstance(instPtr, subDir); - switch (error) - { - case InstanceFactory::NoLoadError: - break; - case InstanceFactory::NotAnInstance: - break; - } - if (error != InstanceFactory::NoLoadError && error != InstanceFactory::NotAnInstance) { QString errorMsg = QString("Failed to load instance %1: ") -- cgit v1.2.3