SCRATCH move icons over to Env, instance proxy model to gui
This commit is contained in:
@ -18,7 +18,6 @@
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include "MultiMC.h"
|
||||
|
||||
#include "logic/settings/INISettingsObject.h"
|
||||
#include "logic/settings/Setting.h"
|
||||
@ -37,7 +36,7 @@ BaseInstance::BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr s
|
||||
|
||||
m_settings->registerSetting("name", "Unnamed Instance");
|
||||
m_settings->registerSetting("iconKey", "default");
|
||||
connect(MMC->icons().get(), SIGNAL(iconUpdated(QString)), SLOT(iconUpdated(QString)));
|
||||
connect(ENV.icons().get(), SIGNAL(iconUpdated(QString)), SLOT(iconUpdated(QString)));
|
||||
m_settings->registerSetting("notes", "");
|
||||
m_settings->registerSetting("lastLaunchTime", 0);
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "Env.h"
|
||||
#include "logic/net/HttpMetaCache.h"
|
||||
#include "icons/IconList.h"
|
||||
#include <QDir>
|
||||
#include <QNetworkProxy>
|
||||
#include <QNetworkAccessManager>
|
||||
@ -35,6 +36,11 @@ std::shared_ptr< QNetworkAccessManager > Env::qnam()
|
||||
return m_qnam;
|
||||
}
|
||||
|
||||
std::shared_ptr<IconList> Env::icons()
|
||||
{
|
||||
Q_ASSERT(m_icons != nullptr);
|
||||
return m_icons;
|
||||
}
|
||||
|
||||
void Env::initHttpMetaCache(QString rootPath, QString staticDataPath)
|
||||
{
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <memory>
|
||||
#include <QString>
|
||||
|
||||
class IconList;
|
||||
class QNetworkAccessManager;
|
||||
class HttpMetaCache;
|
||||
|
||||
@ -26,6 +27,8 @@ public:
|
||||
|
||||
std::shared_ptr<HttpMetaCache> metacache();
|
||||
|
||||
std::shared_ptr<IconList> icons();
|
||||
|
||||
/// init the cache. FIXME: possible future hook point
|
||||
void initHttpMetaCache(QString rootPath, QString staticDataPath);
|
||||
|
||||
@ -35,4 +38,5 @@ public:
|
||||
protected:
|
||||
std::shared_ptr<QNetworkAccessManager> m_qnam;
|
||||
std::shared_ptr<HttpMetaCache> m_metacache;
|
||||
std::shared_ptr<IconList> m_icons;
|
||||
};
|
||||
|
@ -97,7 +97,7 @@ QVariant InstanceList::data(const QModelIndex &index, int role) const
|
||||
case Qt::DecorationRole:
|
||||
{
|
||||
QString key = pdata->iconKey();
|
||||
return MMC->icons()->getIcon(key);
|
||||
return ENV.icons()->getIcon(key);
|
||||
}
|
||||
// for now.
|
||||
case GroupViewRoles::GroupRole:
|
||||
@ -547,23 +547,3 @@ void InstanceList::propertiesChanged(BaseInstance *inst)
|
||||
emit dataChanged(index(i), index(i));
|
||||
}
|
||||
}
|
||||
|
||||
InstanceProxyModel::InstanceProxyModel(QObject *parent) : GroupedProxyModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
bool InstanceProxyModel::subSortLessThan(const QModelIndex &left,
|
||||
const QModelIndex &right) const
|
||||
{
|
||||
BaseInstance *pdataLeft = static_cast<BaseInstance *>(left.internalPointer());
|
||||
BaseInstance *pdataRight = static_cast<BaseInstance *>(right.internalPointer());
|
||||
QString sortMode = MMC->settings()->get("InstSortMode").toString();
|
||||
if (sortMode == "LastLaunch")
|
||||
{
|
||||
return pdataLeft->lastLaunch() > pdataRight->lastLaunch();
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString::localeAwareCompare(pdataLeft->name(), pdataRight->name()) < 0;
|
||||
}
|
||||
}
|
||||
|
@ -181,12 +181,3 @@ protected:
|
||||
QSet<QString> m_groups;
|
||||
SettingsObjectPtr m_globalSettings;
|
||||
};
|
||||
|
||||
class InstanceProxyModel : public GroupedProxyModel
|
||||
{
|
||||
public:
|
||||
explicit InstanceProxyModel(QObject *parent = 0);
|
||||
|
||||
protected:
|
||||
virtual bool subSortLessThan(const QModelIndex &left, const QModelIndex &right) const;
|
||||
};
|
||||
|
@ -127,7 +127,7 @@ std::shared_ptr<Task> LegacyInstance::doUpdate()
|
||||
BaseProcess *LegacyInstance::prepareForLaunch(AuthSessionPtr account)
|
||||
{
|
||||
QString launchScript;
|
||||
QIcon icon = MMC->icons()->getIcon(iconKey());
|
||||
QIcon icon = ENV.icons()->getIcon(iconKey());
|
||||
auto pixmap = icon.pixmap(128, 128);
|
||||
pixmap.save(PathCombine(minecraftRoot(), "icon.png"), "PNG");
|
||||
|
||||
|
@ -158,7 +158,7 @@ QStringList OneSixInstance::processMinecraftArgs(AuthSessionPtr session)
|
||||
BaseProcess *OneSixInstance::prepareForLaunch(AuthSessionPtr session)
|
||||
{
|
||||
QString launchScript;
|
||||
QIcon icon = MMC->icons()->getIcon(iconKey());
|
||||
QIcon icon = ENV.icons()->getIcon(iconKey());
|
||||
auto pixmap = icon.pixmap(128, 128);
|
||||
pixmap.save(PathCombine(minecraftRoot(), "icon.png"), "PNG");
|
||||
|
||||
|
@ -212,7 +212,7 @@ void FTBPlugin::loadInstances(QMap<QString, QString> &groupMap, QList<InstancePt
|
||||
qDebug() << "Loading FTB instance from " << record.instanceDir;
|
||||
QString iconKey = record.logo;
|
||||
iconKey.remove(QRegularExpression("\\..*"));
|
||||
MMC->icons()->addIcon(iconKey, iconKey, PathCombine(record.templateDir, record.logo),
|
||||
ENV.icons()->addIcon(iconKey, iconKey, PathCombine(record.templateDir, record.logo),
|
||||
MMCIcon::Transient);
|
||||
|
||||
if (!QFileInfo(PathCombine(record.instanceDir, "instance.cfg")).exists())
|
||||
|
@ -20,14 +20,15 @@
|
||||
#include <QMimeData>
|
||||
#include <QUrl>
|
||||
#include <QFileSystemWatcher>
|
||||
#include <MultiMC.h>
|
||||
#include <QSet>
|
||||
#include <logger/QsLog.h>
|
||||
|
||||
#define MAX_SIZE 1024
|
||||
|
||||
IconList::IconList(QString path, QObject *parent) : QAbstractListModel(parent)
|
||||
IconList::IconList(QString builtinPath, QString path, QObject *parent) : QAbstractListModel(parent)
|
||||
{
|
||||
// add builtin icons
|
||||
QDir instance_icons(":/icons/instances/");
|
||||
QDir instance_icons(builtinPath);
|
||||
auto file_info_list = instance_icons.entryInfoList(QDir::Files, QDir::Name);
|
||||
for (auto file_info : file_info_list)
|
||||
{
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <memory>
|
||||
#include "MMCIcon.h"
|
||||
#include "logic/settings/Setting.h"
|
||||
#include "logic/Env.h" // there is a global icon list inside Env.
|
||||
|
||||
class QFileSystemWatcher;
|
||||
|
||||
@ -30,7 +31,7 @@ class IconList : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit IconList(QString path, QObject *parent = 0);
|
||||
explicit IconList(QString builtinPath, QString path, QObject *parent = 0);
|
||||
virtual ~IconList() {};
|
||||
|
||||
QIcon getIcon(QString key);
|
||||
|
Reference in New Issue
Block a user