summaryrefslogtreecommitdiffstats
path: root/logic/lists
diff options
context:
space:
mode:
authorAndrew <forkk@forkk.net>2013-11-22 12:47:39 -0600
committerAndrew <forkk@forkk.net>2013-11-22 12:47:39 -0600
commit75e7932607bdd84d2867765eb6f07dcec95ee193 (patch)
tree9ee711dac0a07f6797eedf3ee61d277bb3b63c2c /logic/lists
parent23bc195b3c8558cb997789ca8772342612716993 (diff)
downloadMultiMC-75e7932607bdd84d2867765eb6f07dcec95ee193.tar
MultiMC-75e7932607bdd84d2867765eb6f07dcec95ee193.tar.gz
MultiMC-75e7932607bdd84d2867765eb6f07dcec95ee193.tar.lz
MultiMC-75e7932607bdd84d2867765eb6f07dcec95ee193.tar.xz
MultiMC-75e7932607bdd84d2867765eb6f07dcec95ee193.zip
Properly implement launching and downloading
Also added a system to select an active account to log in with.
Diffstat (limited to 'logic/lists')
-rw-r--r--logic/lists/MojangAccountList.cpp37
-rw-r--r--logic/lists/MojangAccountList.h29
2 files changed, 60 insertions, 6 deletions
diff --git a/logic/lists/MojangAccountList.cpp b/logic/lists/MojangAccountList.cpp
index 442ef3af..1d67c70f 100644
--- a/logic/lists/MojangAccountList.cpp
+++ b/logic/lists/MojangAccountList.cpp
@@ -33,7 +33,7 @@ MojangAccountList::MojangAccountList(QObject *parent) : QAbstractListModel(paren
{
}
-MojangAccountPtr MojangAccountList::findAccount(const QString &username)
+MojangAccountPtr MojangAccountList::findAccount(const QString &username) const
{
for (int i = 0; i < count(); i++)
{
@@ -41,7 +41,7 @@ MojangAccountPtr MojangAccountList::findAccount(const QString &username)
if (account->username() == username)
return account;
}
- return MojangAccountPtr();
+ return nullptr;
}
@@ -82,6 +82,25 @@ void MojangAccountList::removeAccount(QModelIndex index)
}
+MojangAccountPtr MojangAccountList::activeAccount() const
+{
+ if (m_activeAccount.isEmpty())
+ return nullptr;
+ else
+ return findAccount(m_activeAccount);
+}
+
+void MojangAccountList::setActiveAccount(const QString& username)
+{
+ beginResetModel();
+ for (MojangAccountPtr account : m_accounts)
+ if (account->username() == username)
+ m_activeAccount = username;
+ endResetModel();
+ onListChanged();
+}
+
+
void MojangAccountList::onListChanged()
{
if (m_autosave)
@@ -112,6 +131,9 @@ QVariant MojangAccountList::data(const QModelIndex &index, int role) const
case Qt::DisplayRole:
switch (index.column())
{
+ case ActiveColumn:
+ return account->username() == m_activeAccount;
+
case NameColumn:
return account->username();
@@ -137,6 +159,9 @@ QVariant MojangAccountList::headerData(int section, Qt::Orientation orientation,
case Qt::DisplayRole:
switch (section)
{
+ case ActiveColumn:
+ return "Active?";
+
case NameColumn:
return "Name";
@@ -167,7 +192,7 @@ int MojangAccountList::rowCount(const QModelIndex &parent) const
int MojangAccountList::columnCount(const QModelIndex &parent) const
{
- return 1;
+ return 2;
}
void MojangAccountList::updateListData(QList<MojangAccountPtr> versions)
@@ -251,6 +276,9 @@ bool MojangAccountList::loadList(const QString& filePath)
}
}
endResetModel();
+
+ // Load the active account.
+ m_activeAccount = root.value("activeAccount").toString("");
return true;
}
@@ -285,6 +313,9 @@ bool MojangAccountList::saveList(const QString& filePath)
// Insert the account list into the root object.
root.insert("accounts", accounts);
+ // Save the active account.
+ root.insert("activeAccount", m_activeAccount);
+
// Create a JSON document object to convert our JSON to bytes.
QJsonDocument doc(root);
diff --git a/logic/lists/MojangAccountList.h b/logic/lists/MojangAccountList.h
index bccc2f9a..71f472f7 100644
--- a/logic/lists/MojangAccountList.h
+++ b/logic/lists/MojangAccountList.h
@@ -44,8 +44,12 @@ public:
enum VListColumns
{
// TODO: Add icon column.
- // First column - Name
- NameColumn = 0,
+
+ // First column - Active?
+ ActiveColumn = 0,
+
+ // Second column - Name
+ NameColumn,
};
explicit MojangAccountList(QObject *parent = 0);
@@ -83,7 +87,7 @@ public:
* \return A const pointer to the account with the given username. NULL if
* one doesn't exist.
*/
- virtual MojangAccountPtr findAccount(const QString &username);
+ virtual MojangAccountPtr findAccount(const QString &username) const;
/*!
* Sets the default path to save the list file to.
@@ -108,6 +112,19 @@ public:
*/
virtual bool saveList(const QString& file="");
+ /*!
+ * \brief Gets a pointer to the account that the user has selected as their "active" account.
+ * Which account is active can be overridden on a per-instance basis, but this will return the one that
+ * is set as active globally.
+ * \return The currently active MojangAccount. If there isn't an active account, returns a null pointer.
+ */
+ virtual MojangAccountPtr activeAccount() const;
+
+ /*!
+ * Sets the given account as the current active account.
+ */
+ virtual void setActiveAccount(const QString& username);
+
signals:
/*!
* Signal emitted to indicate that the account list has changed.
@@ -124,6 +141,12 @@ protected:
QList<MojangAccountPtr> m_accounts;
+ /*!
+ * Username of the account that is currently active.
+ * Empty string if no account is active.
+ */
+ QString m_activeAccount;
+
//! Path to the account list file. Empty string if there isn't one.
QString m_listFilePath;