Improve group changing, update instance on version change

Gives a list of existing groups to choose from.
Instances are updated as long as there is at least one valid account.
This commit is contained in:
Petr Mrázek
2013-12-15 18:10:51 +01:00
parent 5a3043398e
commit dd9e04000c
7 changed files with 123 additions and 65 deletions

View File

@ -149,7 +149,7 @@ public:
*/
virtual SettingsObject &settings() const;
/// returns a valid update task if update is needed, NULL otherwise
/// returns a valid update task
virtual std::shared_ptr<Task> doUpdate(bool only_prepare) = 0;
/// returns a valid minecraft process, ready for launch with the given account.

View File

@ -54,11 +54,9 @@ void OneSixUpdate::executeTask()
if (m_only_prepare)
{
if (m_inst->shouldUpdate())
{
emitFailed("Unable to update instance in offline mode.");
return;
}
/*
* FIXME: in offline mode, do not proceed!
*/
setStatus("Testing the Java installation.");
QString java_path = m_inst->settings().get("JavaPath").toString();

View File

@ -414,3 +414,13 @@ void MojangAccountList::setListFilePath(QString path, bool autosave)
m_listFilePath = path;
m_autosave = autosave;
}
bool MojangAccountList::anyAccountIsValid()
{
for(auto account:m_accounts)
{
if(account->accountStatus() != NotVerified)
return true;
}
return false;
}

View File

@ -126,6 +126,11 @@ public:
* If the username given is an empty string, sets the active account to nothing.
*/
virtual void setActiveAccount(const QString &username);
/*!
* Returns true if any of the account is at least Validated
*/
bool anyAccountIsValid();
signals:
/*!

View File

@ -117,6 +117,11 @@ void InstanceList::groupChanged()
saveGroupList();
}
QStringList InstanceList::getGroups()
{
return m_groups.toList();
}
void InstanceList::saveGroupList()
{
QString groupFileName = m_instDir + "/instgroups.json";
@ -126,7 +131,7 @@ void InstanceList::saveGroupList()
if (!groupFile.open(QIODevice::WriteOnly | QIODevice::Truncate))
{
// An error occurred. Ignore it.
QLOG_ERROR() << "Failed to read instance group file.";
QLOG_ERROR() << "Failed to save instance group file.";
return;
}
QTextStream out(&groupFile);
@ -137,6 +142,10 @@ void InstanceList::saveGroupList()
QString group = instance->group();
if (group.isEmpty())
continue;
// keep a list/set of groups for choosing
m_groups.insert(group);
if (!groupMap.count(group))
{
QSet<QString> set;
@ -253,6 +262,9 @@ void InstanceList::loadGroupList(QMap<QString, QString> &groupMap)
continue;
}
// keep a list/set of groups for choosing
m_groups.insert(groupName);
// Iterate through the list of instances in the group.
QJsonArray instancesArray = groupObj.value("instances").toArray();

View File

@ -17,6 +17,7 @@
#include <QObject>
#include <QAbstractListModel>
#include <QSet>
#include "categorizedsortfilterproxymodel.h"
#include <QIcon>
@ -97,6 +98,9 @@ public:
InstancePtr getInstanceById(QString id) const;
QModelIndex getInstanceIndexById(const QString &id) const;
// FIXME: instead of iterating through all instances and forming a set, keep the set around
QStringList getGroups();
signals:
void dataIsInvalid();
@ -116,6 +120,7 @@ private:
protected:
QString m_instDir;
QList<InstancePtr> m_instances;
QSet<QString> m_groups;
};
class InstanceProxyModel : public KCategorizedSortFilterProxyModel