summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/gui/icons/IconList.cpp22
-rw-r--r--api/gui/icons/IconList.h18
-rw-r--r--api/gui/icons/MMCIcon.cpp32
-rw-r--r--api/gui/icons/MMCIcon.h19
-rw-r--r--api/logic/Env.cpp10
-rw-r--r--api/logic/Env.h6
-rw-r--r--api/logic/icons/IIconList.h20
-rw-r--r--api/logic/minecraft/ftb/FTBPlugin.cpp6
-rw-r--r--application/MultiMC.cpp1
-rw-r--r--application/dialogs/ExportInstanceDialog.cpp4
10 files changed, 86 insertions, 52 deletions
diff --git a/api/gui/icons/IconList.cpp b/api/gui/icons/IconList.cpp
index 99def3b7..4f9fb09f 100644
--- a/api/gui/icons/IconList.cpp
+++ b/api/gui/icons/IconList.cpp
@@ -33,7 +33,7 @@ IconList::IconList(QString builtinPath, QString path, QObject *parent) : QAbstra
for (auto file_info : file_info_list)
{
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());
@@ -70,9 +70,9 @@ void IconList::directoryChanged(const QString &path)
QList<QString> current_list;
for (auto &it : icons)
{
- if (!it.has(MMCIcon::FileBased))
+ if (!it.has(IconType::FileBased))
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();
@@ -90,8 +90,8 @@ void IconList::directoryChanged(const QString &path)
int idx = getIconIndex(key);
if (idx == -1)
continue;
- icons[idx].remove(MMCIcon::FileBased);
- if (icons[idx].type() == MMCIcon::ToBeDeleted)
+ icons[idx].remove(IconType::FileBased);
+ if (icons[idx].type() == IconType::ToBeDeleted)
{
beginRemoveRows(QModelIndex(), idx, idx);
icons.remove(idx);
@@ -111,7 +111,7 @@ void IconList::directoryChanged(const QString &path)
qDebug() << "Adding " << add;
QFileInfo addfile(add);
QString key = addfile.baseName();
- if (addIcon(key, QString(), addfile.filePath(), MMCIcon::FileBased))
+ if (addIcon(key, QString(), addfile.filePath(), IconType::FileBased))
{
m_watcher->addPath(add);
emit iconUpdated(key);
@@ -133,7 +133,7 @@ void IconList::fileChanged(const QString &path)
if (!icon.availableSizes().size())
return;
- icons[idx].m_images[MMCIcon::FileBased].icon = icon;
+ icons[idx].m_images[IconType::FileBased].icon = icon;
dataChanged(index(idx), index(idx));
emit iconUpdated(key);
}
@@ -268,7 +268,7 @@ bool IconList::iconFileExists(QString key)
{
return false;
}
- return iconEntry->has(MMCIcon::FileBased);
+ return iconEntry->has(IconType::FileBased);
}
const MMCIcon *IconList::icon(QString key)
@@ -285,14 +285,14 @@ bool IconList::deleteIcon(QString key)
if (iconIdx == -1)
return false;
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;
}
-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?
QIcon icon(path);
diff --git a/api/gui/icons/IconList.h b/api/gui/icons/IconList.h
index 04dea2cd..7aeb7067 100644
--- a/api/gui/icons/IconList.h
+++ b/api/gui/icons/IconList.h
@@ -24,12 +24,13 @@
#include "MMCIcon.h"
#include "settings/Setting.h"
#include "Env.h" // there is a global icon list inside Env.
+#include <icons/IIconList.h>
#include "multimc_gui_export.h"
class QFileSystemWatcher;
-class MULTIMC_GUI_EXPORT IconList : public QAbstractListModel
+class MULTIMC_GUI_EXPORT IconList : public QAbstractListModel, public IIconList
{
Q_OBJECT
public:
@@ -40,18 +41,17 @@ public:
QIcon getBigIcon(QString key);
int getIconIndex(QString key);
- virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
- virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
+ 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 iconFileExists(QString key);
- virtual QStringList mimeTypes() const;
- virtual Qt::DropActions supportedDropActions() const;
- virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
- const QModelIndex &parent);
- virtual Qt::ItemFlags flags(const QModelIndex &index) const;
+ virtual QStringList mimeTypes() const override;
+ virtual Qt::DropActions supportedDropActions() const override;
+ virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
+ virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
void installIcons(QStringList iconFiles);
diff --git a/api/gui/icons/MMCIcon.cpp b/api/gui/icons/MMCIcon.cpp
index 6b4eef39..f71281d0 100644
--- a/api/gui/icons/MMCIcon.cpp
+++ b/api/gui/icons/MMCIcon.cpp
@@ -16,19 +16,19 @@
#include "MMCIcon.h"
#include <QFileInfo>
-MMCIcon::Type operator--(MMCIcon::Type &t, int)
+IconType operator--(IconType &t, int)
{
- MMCIcon::Type temp = t;
+ IconType temp = t;
switch (t)
{
- case MMCIcon::Type::Builtin:
- t = MMCIcon::Type::ToBeDeleted;
+ case IconType::Builtin:
+ t = IconType::ToBeDeleted;
break;
- case MMCIcon::Type::Transient:
- t = MMCIcon::Type::Builtin;
+ case IconType::Transient:
+ t = IconType::Builtin;
break;
- case MMCIcon::Type::FileBased:
- t = MMCIcon::Type::Transient;
+ case IconType::FileBased:
+ t = IconType::Transient;
break;
default:
{
@@ -37,7 +37,7 @@ MMCIcon::Type operator--(MMCIcon::Type &t, int)
return temp;
}
-MMCIcon::Type MMCIcon::type() const
+IconType MMCIcon::type() const
{
return m_current_type;
}
@@ -49,23 +49,23 @@ QString MMCIcon::name() const
return m_key;
}
-bool MMCIcon::has(MMCIcon::Type _type) const
+bool MMCIcon::has(IconType _type) const
{
return m_images[_type].present();
}
QIcon MMCIcon::icon() const
{
- if (m_current_type == Type::ToBeDeleted)
+ if (m_current_type == IconType::ToBeDeleted)
return QIcon();
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].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())
{
@@ -73,13 +73,13 @@ void MMCIcon::remove(Type rm_type)
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);
- 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;
}
diff --git a/api/gui/icons/MMCIcon.h b/api/gui/icons/MMCIcon.h
index 6f9617c2..4bc7ecdc 100644
--- a/api/gui/icons/MMCIcon.h
+++ b/api/gui/icons/MMCIcon.h
@@ -17,6 +17,7 @@
#include <QString>
#include <QDateTime>
#include <QIcon>
+#include <icons/IIconList.h>
#include "multimc_gui_export.h"
@@ -33,23 +34,15 @@ struct MULTIMC_GUI_EXPORT MMCImage
struct MULTIMC_GUI_EXPORT MMCIcon
{
- enum Type : unsigned
- {
- Builtin,
- Transient,
- FileBased,
- ICONS_TOTAL,
- ToBeDeleted
- };
QString m_key;
QString m_name;
MMCImage m_images[ICONS_TOTAL];
- Type m_current_type = ToBeDeleted;
+ IconType m_current_type = ToBeDeleted;
- Type type() const;
+ IconType type() const;
QString name() const;
- bool has(Type _type) const;
+ bool has(IconType _type) const;
QIcon icon() const;
- void remove(Type rm_type);
- void replace(Type new_type, QIcon icon, QString path = QString());
+ void remove(IconType rm_type);
+ void replace(IconType new_type, QIcon icon, QString path = QString());
};
diff --git a/api/logic/Env.cpp b/api/logic/Env.cpp
index cc0c5981..b8e07343 100644
--- a/api/logic/Env.cpp
+++ b/api/logic/Env.cpp
@@ -43,6 +43,16 @@ std::shared_ptr< QNetworkAccessManager > Env::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
{
diff --git a/api/logic/Env.h b/api/logic/Env.h
index 4d8945d7..dcf1947f 100644
--- a/api/logic/Env.h
+++ b/api/logic/Env.h
@@ -1,6 +1,7 @@
#pragma once
#include <memory>
+#include "icons/IIconList.h"
#include <QString>
#include <QMap>
@@ -32,6 +33,8 @@ public:
std::shared_ptr<HttpMetaCache> metacache();
+ std::shared_ptr<IIconList> icons();
+
/// init the cache. FIXME: possible future hook point
void initHttpMetaCache();
@@ -46,6 +49,8 @@ public:
void registerVersionList(QString name, std::shared_ptr<BaseVersionList> vlist);
+ void registerIconList(std::shared_ptr<IIconList> iconlist);
+
std::shared_ptr<WonkoIndex> wonkoIndex();
QString wonkoRootUrl() const { return m_wonkoRootUrl; }
@@ -54,6 +59,7 @@ public:
protected:
std::shared_ptr<QNetworkAccessManager> m_qnam;
std::shared_ptr<HttpMetaCache> m_metacache;
+ std::shared_ptr<IIconList> m_iconlist;
QMap<QString, std::shared_ptr<BaseVersionList>> m_versionLists;
std::shared_ptr<WonkoIndex> m_wonkoIndex;
QString m_wonkoRootUrl;
diff --git a/api/logic/icons/IIconList.h b/api/logic/icons/IIconList.h
new file mode 100644
index 00000000..a7e0fa07
--- /dev/null
+++ b/api/logic/icons/IIconList.h
@@ -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;
+};
+
diff --git a/api/logic/minecraft/ftb/FTBPlugin.cpp b/api/logic/minecraft/ftb/FTBPlugin.cpp
index a142c106..134257bf 100644
--- a/api/logic/minecraft/ftb/FTBPlugin.cpp
+++ b/api/logic/minecraft/ftb/FTBPlugin.cpp
@@ -257,7 +257,11 @@ void FTBPlugin::loadInstances(SettingsObjectPtr globalSettings, QMap<QString, QS
{
qDebug() << "Loading FTB instance from " << record.instanceDir;
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");
qDebug() << "ICON get!";
diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp
index b157c83d..c9c7d41b 100644
--- a/application/MultiMC.cpp
+++ b/application/MultiMC.cpp
@@ -344,6 +344,7 @@ void MultiMC::initIcons()
{
m_icons->directoryChanged(value.toString());
});
+ ENV.registerIconList(m_icons);
}
diff --git a/application/dialogs/ExportInstanceDialog.cpp b/application/dialogs/ExportInstanceDialog.cpp
index 2712f24c..0771d037 100644
--- a/application/dialogs/ExportInstanceDialog.cpp
+++ b/application/dialogs/ExportInstanceDialog.cpp
@@ -346,8 +346,8 @@ void SaveIcon(InstancePtr m_instance)
bool saveIcon = false;
switch(mmcIcon->type())
{
- case MMCIcon::FileBased:
- case MMCIcon::Transient:
+ case IconType::FileBased:
+ case IconType::Transient:
saveIcon = true;
default:
break;