GH-1559 Fix FTB icons
This was caused by separation of GUI and logic. Now logic has an interface that GUI implements. It should be expanded upon later.
This commit is contained in:
parent
c50b3cdeec
commit
e1a530f84d
@ -33,7 +33,7 @@ IconList::IconList(QString builtinPath, QString path, QObject *parent) : QAbstra
|
|||||||
for (auto file_info : file_info_list)
|
for (auto file_info : file_info_list)
|
||||||
{
|
{
|
||||||
QString key = file_info.baseName();
|
QString key = file_info.baseName();
|
||||||
addIcon(key, key, file_info.absoluteFilePath(), MMCIcon::Builtin);
|
addIcon(key, key, file_info.absoluteFilePath(), IconType::Builtin);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_watcher.reset(new QFileSystemWatcher());
|
m_watcher.reset(new QFileSystemWatcher());
|
||||||
@ -70,9 +70,9 @@ void IconList::directoryChanged(const QString &path)
|
|||||||
QList<QString> current_list;
|
QList<QString> current_list;
|
||||||
for (auto &it : icons)
|
for (auto &it : icons)
|
||||||
{
|
{
|
||||||
if (!it.has(MMCIcon::FileBased))
|
if (!it.has(IconType::FileBased))
|
||||||
continue;
|
continue;
|
||||||
current_list.push_back(it.m_images[MMCIcon::FileBased].filename);
|
current_list.push_back(it.m_images[IconType::FileBased].filename);
|
||||||
}
|
}
|
||||||
QSet<QString> current_set = current_list.toSet();
|
QSet<QString> current_set = current_list.toSet();
|
||||||
|
|
||||||
@ -90,8 +90,8 @@ void IconList::directoryChanged(const QString &path)
|
|||||||
int idx = getIconIndex(key);
|
int idx = getIconIndex(key);
|
||||||
if (idx == -1)
|
if (idx == -1)
|
||||||
continue;
|
continue;
|
||||||
icons[idx].remove(MMCIcon::FileBased);
|
icons[idx].remove(IconType::FileBased);
|
||||||
if (icons[idx].type() == MMCIcon::ToBeDeleted)
|
if (icons[idx].type() == IconType::ToBeDeleted)
|
||||||
{
|
{
|
||||||
beginRemoveRows(QModelIndex(), idx, idx);
|
beginRemoveRows(QModelIndex(), idx, idx);
|
||||||
icons.remove(idx);
|
icons.remove(idx);
|
||||||
@ -111,7 +111,7 @@ void IconList::directoryChanged(const QString &path)
|
|||||||
qDebug() << "Adding " << add;
|
qDebug() << "Adding " << add;
|
||||||
QFileInfo addfile(add);
|
QFileInfo addfile(add);
|
||||||
QString key = addfile.baseName();
|
QString key = addfile.baseName();
|
||||||
if (addIcon(key, QString(), addfile.filePath(), MMCIcon::FileBased))
|
if (addIcon(key, QString(), addfile.filePath(), IconType::FileBased))
|
||||||
{
|
{
|
||||||
m_watcher->addPath(add);
|
m_watcher->addPath(add);
|
||||||
emit iconUpdated(key);
|
emit iconUpdated(key);
|
||||||
@ -133,7 +133,7 @@ void IconList::fileChanged(const QString &path)
|
|||||||
if (!icon.availableSizes().size())
|
if (!icon.availableSizes().size())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
icons[idx].m_images[MMCIcon::FileBased].icon = icon;
|
icons[idx].m_images[IconType::FileBased].icon = icon;
|
||||||
dataChanged(index(idx), index(idx));
|
dataChanged(index(idx), index(idx));
|
||||||
emit iconUpdated(key);
|
emit iconUpdated(key);
|
||||||
}
|
}
|
||||||
@ -268,7 +268,7 @@ bool IconList::iconFileExists(QString key)
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return iconEntry->has(MMCIcon::FileBased);
|
return iconEntry->has(IconType::FileBased);
|
||||||
}
|
}
|
||||||
|
|
||||||
const MMCIcon *IconList::icon(QString key)
|
const MMCIcon *IconList::icon(QString key)
|
||||||
@ -285,14 +285,14 @@ bool IconList::deleteIcon(QString key)
|
|||||||
if (iconIdx == -1)
|
if (iconIdx == -1)
|
||||||
return false;
|
return false;
|
||||||
auto &iconEntry = icons[iconIdx];
|
auto &iconEntry = icons[iconIdx];
|
||||||
if (iconEntry.has(MMCIcon::FileBased))
|
if (iconEntry.has(IconType::FileBased))
|
||||||
{
|
{
|
||||||
return QFile::remove(iconEntry.m_images[MMCIcon::FileBased].filename);
|
return QFile::remove(iconEntry.m_images[IconType::FileBased].filename);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IconList::addIcon(QString key, QString name, QString path, MMCIcon::Type type)
|
bool IconList::addIcon(QString key, QString name, QString path, IconType type)
|
||||||
{
|
{
|
||||||
// replace the icon even? is the input valid?
|
// replace the icon even? is the input valid?
|
||||||
QIcon icon(path);
|
QIcon icon(path);
|
||||||
|
@ -24,12 +24,13 @@
|
|||||||
#include "MMCIcon.h"
|
#include "MMCIcon.h"
|
||||||
#include "settings/Setting.h"
|
#include "settings/Setting.h"
|
||||||
#include "Env.h" // there is a global icon list inside Env.
|
#include "Env.h" // there is a global icon list inside Env.
|
||||||
|
#include <icons/IIconList.h>
|
||||||
|
|
||||||
#include "multimc_gui_export.h"
|
#include "multimc_gui_export.h"
|
||||||
|
|
||||||
class QFileSystemWatcher;
|
class QFileSystemWatcher;
|
||||||
|
|
||||||
class MULTIMC_GUI_EXPORT IconList : public QAbstractListModel
|
class MULTIMC_GUI_EXPORT IconList : public QAbstractListModel, public IIconList
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
@ -40,18 +41,17 @@ public:
|
|||||||
QIcon getBigIcon(QString key);
|
QIcon getBigIcon(QString key);
|
||||||
int getIconIndex(QString key);
|
int getIconIndex(QString key);
|
||||||
|
|
||||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
|
||||||
bool addIcon(QString key, QString name, QString path, MMCIcon::Type type);
|
virtual bool addIcon(QString key, QString name, QString path, IconType type) override;
|
||||||
bool deleteIcon(QString key);
|
bool deleteIcon(QString key);
|
||||||
bool iconFileExists(QString key);
|
bool iconFileExists(QString key);
|
||||||
|
|
||||||
virtual QStringList mimeTypes() const;
|
virtual QStringList mimeTypes() const override;
|
||||||
virtual Qt::DropActions supportedDropActions() const;
|
virtual Qt::DropActions supportedDropActions() const override;
|
||||||
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
|
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
|
||||||
const QModelIndex &parent);
|
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
|
||||||
|
|
||||||
void installIcons(QStringList iconFiles);
|
void installIcons(QStringList iconFiles);
|
||||||
|
|
||||||
|
@ -16,19 +16,19 @@
|
|||||||
#include "MMCIcon.h"
|
#include "MMCIcon.h"
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
|
||||||
MMCIcon::Type operator--(MMCIcon::Type &t, int)
|
IconType operator--(IconType &t, int)
|
||||||
{
|
{
|
||||||
MMCIcon::Type temp = t;
|
IconType temp = t;
|
||||||
switch (t)
|
switch (t)
|
||||||
{
|
{
|
||||||
case MMCIcon::Type::Builtin:
|
case IconType::Builtin:
|
||||||
t = MMCIcon::Type::ToBeDeleted;
|
t = IconType::ToBeDeleted;
|
||||||
break;
|
break;
|
||||||
case MMCIcon::Type::Transient:
|
case IconType::Transient:
|
||||||
t = MMCIcon::Type::Builtin;
|
t = IconType::Builtin;
|
||||||
break;
|
break;
|
||||||
case MMCIcon::Type::FileBased:
|
case IconType::FileBased:
|
||||||
t = MMCIcon::Type::Transient;
|
t = IconType::Transient;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
@ -37,7 +37,7 @@ MMCIcon::Type operator--(MMCIcon::Type &t, int)
|
|||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
MMCIcon::Type MMCIcon::type() const
|
IconType MMCIcon::type() const
|
||||||
{
|
{
|
||||||
return m_current_type;
|
return m_current_type;
|
||||||
}
|
}
|
||||||
@ -49,23 +49,23 @@ QString MMCIcon::name() const
|
|||||||
return m_key;
|
return m_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MMCIcon::has(MMCIcon::Type _type) const
|
bool MMCIcon::has(IconType _type) const
|
||||||
{
|
{
|
||||||
return m_images[_type].present();
|
return m_images[_type].present();
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon MMCIcon::icon() const
|
QIcon MMCIcon::icon() const
|
||||||
{
|
{
|
||||||
if (m_current_type == Type::ToBeDeleted)
|
if (m_current_type == IconType::ToBeDeleted)
|
||||||
return QIcon();
|
return QIcon();
|
||||||
return m_images[m_current_type].icon;
|
return m_images[m_current_type].icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MMCIcon::remove(Type rm_type)
|
void MMCIcon::remove(IconType rm_type)
|
||||||
{
|
{
|
||||||
m_images[rm_type].filename = QString();
|
m_images[rm_type].filename = QString();
|
||||||
m_images[rm_type].icon = QIcon();
|
m_images[rm_type].icon = QIcon();
|
||||||
for (auto iter = rm_type; iter != Type::ToBeDeleted; iter--)
|
for (auto iter = rm_type; iter != IconType::ToBeDeleted; iter--)
|
||||||
{
|
{
|
||||||
if (m_images[iter].present())
|
if (m_images[iter].present())
|
||||||
{
|
{
|
||||||
@ -73,13 +73,13 @@ void MMCIcon::remove(Type rm_type)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_current_type = Type::ToBeDeleted;
|
m_current_type = IconType::ToBeDeleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MMCIcon::replace(MMCIcon::Type new_type, QIcon icon, QString path)
|
void MMCIcon::replace(IconType new_type, QIcon icon, QString path)
|
||||||
{
|
{
|
||||||
QFileInfo foo(path);
|
QFileInfo foo(path);
|
||||||
if (new_type > m_current_type || m_current_type == MMCIcon::ToBeDeleted)
|
if (new_type > m_current_type || m_current_type == IconType::ToBeDeleted)
|
||||||
{
|
{
|
||||||
m_current_type = new_type;
|
m_current_type = new_type;
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
#include <icons/IIconList.h>
|
||||||
|
|
||||||
#include "multimc_gui_export.h"
|
#include "multimc_gui_export.h"
|
||||||
|
|
||||||
@ -33,23 +34,15 @@ struct MULTIMC_GUI_EXPORT MMCImage
|
|||||||
|
|
||||||
struct MULTIMC_GUI_EXPORT MMCIcon
|
struct MULTIMC_GUI_EXPORT MMCIcon
|
||||||
{
|
{
|
||||||
enum Type : unsigned
|
|
||||||
{
|
|
||||||
Builtin,
|
|
||||||
Transient,
|
|
||||||
FileBased,
|
|
||||||
ICONS_TOTAL,
|
|
||||||
ToBeDeleted
|
|
||||||
};
|
|
||||||
QString m_key;
|
QString m_key;
|
||||||
QString m_name;
|
QString m_name;
|
||||||
MMCImage m_images[ICONS_TOTAL];
|
MMCImage m_images[ICONS_TOTAL];
|
||||||
Type m_current_type = ToBeDeleted;
|
IconType m_current_type = ToBeDeleted;
|
||||||
|
|
||||||
Type type() const;
|
IconType type() const;
|
||||||
QString name() const;
|
QString name() const;
|
||||||
bool has(Type _type) const;
|
bool has(IconType _type) const;
|
||||||
QIcon icon() const;
|
QIcon icon() const;
|
||||||
void remove(Type rm_type);
|
void remove(IconType rm_type);
|
||||||
void replace(Type new_type, QIcon icon, QString path = QString());
|
void replace(IconType new_type, QIcon icon, QString path = QString());
|
||||||
};
|
};
|
||||||
|
@ -43,6 +43,16 @@ std::shared_ptr< QNetworkAccessManager > Env::qnam()
|
|||||||
return m_qnam;
|
return m_qnam;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<IIconList> Env::icons()
|
||||||
|
{
|
||||||
|
return m_iconlist;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Env::registerIconList(std::shared_ptr<IIconList> iconlist)
|
||||||
|
{
|
||||||
|
m_iconlist = iconlist;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
class NullVersion : public BaseVersion
|
class NullVersion : public BaseVersion
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include "icons/IIconList.h"
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
|
||||||
@ -32,6 +33,8 @@ public:
|
|||||||
|
|
||||||
std::shared_ptr<HttpMetaCache> metacache();
|
std::shared_ptr<HttpMetaCache> metacache();
|
||||||
|
|
||||||
|
std::shared_ptr<IIconList> icons();
|
||||||
|
|
||||||
/// init the cache. FIXME: possible future hook point
|
/// init the cache. FIXME: possible future hook point
|
||||||
void initHttpMetaCache();
|
void initHttpMetaCache();
|
||||||
|
|
||||||
@ -46,6 +49,8 @@ public:
|
|||||||
|
|
||||||
void registerVersionList(QString name, std::shared_ptr<BaseVersionList> vlist);
|
void registerVersionList(QString name, std::shared_ptr<BaseVersionList> vlist);
|
||||||
|
|
||||||
|
void registerIconList(std::shared_ptr<IIconList> iconlist);
|
||||||
|
|
||||||
std::shared_ptr<WonkoIndex> wonkoIndex();
|
std::shared_ptr<WonkoIndex> wonkoIndex();
|
||||||
|
|
||||||
QString wonkoRootUrl() const { return m_wonkoRootUrl; }
|
QString wonkoRootUrl() const { return m_wonkoRootUrl; }
|
||||||
@ -54,6 +59,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
std::shared_ptr<QNetworkAccessManager> m_qnam;
|
std::shared_ptr<QNetworkAccessManager> m_qnam;
|
||||||
std::shared_ptr<HttpMetaCache> m_metacache;
|
std::shared_ptr<HttpMetaCache> m_metacache;
|
||||||
|
std::shared_ptr<IIconList> m_iconlist;
|
||||||
QMap<QString, std::shared_ptr<BaseVersionList>> m_versionLists;
|
QMap<QString, std::shared_ptr<BaseVersionList>> m_versionLists;
|
||||||
std::shared_ptr<WonkoIndex> m_wonkoIndex;
|
std::shared_ptr<WonkoIndex> m_wonkoIndex;
|
||||||
QString m_wonkoRootUrl;
|
QString m_wonkoRootUrl;
|
||||||
|
20
api/logic/icons/IIconList.h
Normal file
20
api/logic/icons/IIconList.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
enum IconType : unsigned
|
||||||
|
{
|
||||||
|
Builtin,
|
||||||
|
Transient,
|
||||||
|
FileBased,
|
||||||
|
ICONS_TOTAL,
|
||||||
|
ToBeDeleted
|
||||||
|
};
|
||||||
|
|
||||||
|
class IIconList
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~IIconList(){}
|
||||||
|
virtual bool addIcon(QString key, QString name, QString path, IconType type) = 0;
|
||||||
|
};
|
||||||
|
|
@ -257,7 +257,11 @@ void FTBPlugin::loadInstances(SettingsObjectPtr globalSettings, QMap<QString, QS
|
|||||||
{
|
{
|
||||||
qDebug() << "Loading FTB instance from " << record.instanceDir;
|
qDebug() << "Loading FTB instance from " << record.instanceDir;
|
||||||
QString iconKey = record.iconKey;
|
QString iconKey = record.iconKey;
|
||||||
// MMC->icons()->addIcon(iconKey, iconKey, FS::PathCombine(record.templateDir, record.logo), MMCIcon::Transient);
|
auto icons = ENV.icons();
|
||||||
|
if(icons)
|
||||||
|
{
|
||||||
|
icons->addIcon(iconKey, iconKey, FS::PathCombine(record.templateDir, record.logo), IconType::Transient);
|
||||||
|
}
|
||||||
auto settingsFilePath = FS::PathCombine(record.instanceDir, "instance.cfg");
|
auto settingsFilePath = FS::PathCombine(record.instanceDir, "instance.cfg");
|
||||||
qDebug() << "ICON get!";
|
qDebug() << "ICON get!";
|
||||||
|
|
||||||
|
@ -344,6 +344,7 @@ void MultiMC::initIcons()
|
|||||||
{
|
{
|
||||||
m_icons->directoryChanged(value.toString());
|
m_icons->directoryChanged(value.toString());
|
||||||
});
|
});
|
||||||
|
ENV.registerIconList(m_icons);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -346,8 +346,8 @@ void SaveIcon(InstancePtr m_instance)
|
|||||||
bool saveIcon = false;
|
bool saveIcon = false;
|
||||||
switch(mmcIcon->type())
|
switch(mmcIcon->type())
|
||||||
{
|
{
|
||||||
case MMCIcon::FileBased:
|
case IconType::FileBased:
|
||||||
case MMCIcon::Transient:
|
case IconType::Transient:
|
||||||
saveIcon = true;
|
saveIcon = true;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user