summaryrefslogtreecommitdiffstats
path: root/api/gui
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2016-11-10 02:54:53 +0100
committerPetr Mrázek <peterix@gmail.com>2016-11-10 02:54:53 +0100
commitf9d94a45eebd5fb7b14d4bcc6ad77cb96ecdd771 (patch)
tree0b8f492b470c835bc814ebc786dc73bfe2b0f3f4 /api/gui
parent27e26a656b8d9f0aef1dd6a18b50ecc9465494bd (diff)
downloadMultiMC-f9d94a45eebd5fb7b14d4bcc6ad77cb96ecdd771.tar
MultiMC-f9d94a45eebd5fb7b14d4bcc6ad77cb96ecdd771.tar.gz
MultiMC-f9d94a45eebd5fb7b14d4bcc6ad77cb96ecdd771.tar.lz
MultiMC-f9d94a45eebd5fb7b14d4bcc6ad77cb96ecdd771.tar.xz
MultiMC-f9d94a45eebd5fb7b14d4bcc6ad77cb96ecdd771.zip
NOISSUE allow using icon themes for instances and instance badges
Diffstat (limited to 'api/gui')
-rw-r--r--api/gui/icons/IconList.cpp47
-rw-r--r--api/gui/icons/IconList.h3
-rw-r--r--api/gui/icons/MMCIcon.cpp21
-rw-r--r--api/gui/icons/MMCIcon.h5
4 files changed, 64 insertions, 12 deletions
diff --git a/api/gui/icons/IconList.cpp b/api/gui/icons/IconList.cpp
index bdcada32..100a69c3 100644
--- a/api/gui/icons/IconList.cpp
+++ b/api/gui/icons/IconList.cpp
@@ -25,15 +25,23 @@
#define MAX_SIZE 1024
-IconList::IconList(QString builtinPath, QString path, QObject *parent) : QAbstractListModel(parent)
+IconList::IconList(const QStringList &builtinPaths, QString path, QObject *parent) : QAbstractListModel(parent)
{
+ QSet<QString> builtinNames;
+
// add builtin icons
- QDir instance_icons(builtinPath);
- auto file_info_list = instance_icons.entryInfoList(QDir::Files, QDir::Name);
- for (auto file_info : file_info_list)
+ for(auto & builtinPath: builtinPaths)
{
- QString key = file_info.baseName();
- addIcon(key, key, file_info.absoluteFilePath(), IconType::Builtin);
+ QDir instance_icons(builtinPath);
+ auto file_info_list = instance_icons.entryInfoList(QDir::Files, QDir::Name);
+ for (auto file_info : file_info_list)
+ {
+ builtinNames.insert(file_info.baseName());
+ }
+ }
+ for(auto & builtinName : builtinNames)
+ {
+ addThemeIcon(builtinName);
}
m_watcher.reset(new QFileSystemWatcher());
@@ -292,6 +300,33 @@ bool IconList::deleteIcon(const QString &key)
return false;
}
+bool IconList::addThemeIcon(const QString& key)
+{
+ auto iter = name_index.find(key);
+ if (iter != name_index.end())
+ {
+ auto &oldOne = icons[*iter];
+ oldOne.replace(Builtin, key);
+ dataChanged(index(*iter), index(*iter));
+ return true;
+ }
+ else
+ {
+ // add a new icon
+ beginInsertRows(QModelIndex(), icons.size(), icons.size());
+ {
+ MMCIcon mmc_icon;
+ mmc_icon.m_name = key;
+ mmc_icon.m_key = key;
+ mmc_icon.replace(Builtin, key);
+ icons.push_back(mmc_icon);
+ name_index[key] = icons.size() - 1;
+ }
+ endInsertRows();
+ return true;
+ }
+}
+
bool IconList::addIcon(const QString &key, const QString &name, const QString &path, const IconType type)
{
// replace the icon even? is the input valid?
diff --git a/api/gui/icons/IconList.h b/api/gui/icons/IconList.h
index 7b07797f..f6b2ed0a 100644
--- a/api/gui/icons/IconList.h
+++ b/api/gui/icons/IconList.h
@@ -34,7 +34,7 @@ class MULTIMC_GUI_EXPORT IconList : public QAbstractListModel, public IIconList
{
Q_OBJECT
public:
- explicit IconList(QString builtinPath, QString path, QObject *parent = 0);
+ explicit IconList(const QStringList &builtinPaths, QString path, QObject *parent = 0);
virtual ~IconList() {};
QIcon getIcon(const QString &key) const;
@@ -44,6 +44,7 @@ public:
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;
+ bool addThemeIcon(const QString &key);
bool addIcon(const QString &key, const QString &name, const QString &path, const IconType type) override;
void saveIcon(const QString &key, const QString &path, const char * format) const override;
bool deleteIcon(const QString &key) override;
diff --git a/api/gui/icons/MMCIcon.cpp b/api/gui/icons/MMCIcon.cpp
index f71281d0..11ad93e2 100644
--- a/api/gui/icons/MMCIcon.cpp
+++ b/api/gui/icons/MMCIcon.cpp
@@ -15,6 +15,7 @@
#include "MMCIcon.h"
#include <QFileInfo>
+#include <xdgicon.h>
IconType operator--(IconType &t, int)
{
@@ -58,7 +59,11 @@ QIcon MMCIcon::icon() const
{
if (m_current_type == IconType::ToBeDeleted)
return QIcon();
- return m_images[m_current_type].icon;
+ auto & icon = m_images[m_current_type].icon;
+ if(!icon.isNull())
+ return icon;
+ // FIXME: inject this.
+ return XdgIcon::fromTheme(m_images[m_current_type].key);
}
void MMCIcon::remove(IconType rm_type)
@@ -78,12 +83,22 @@ void MMCIcon::remove(IconType rm_type)
void MMCIcon::replace(IconType new_type, QIcon icon, QString path)
{
- QFileInfo foo(path);
if (new_type > m_current_type || m_current_type == IconType::ToBeDeleted)
{
m_current_type = new_type;
}
m_images[new_type].icon = icon;
- m_images[new_type].changed = foo.lastModified();
m_images[new_type].filename = path;
+ m_images[new_type].key = QString();
+}
+
+void MMCIcon::replace(IconType new_type, const QString& key)
+{
+ if (new_type > m_current_type || m_current_type == IconType::ToBeDeleted)
+ {
+ m_current_type = new_type;
+ }
+ m_images[new_type].icon = QIcon();
+ m_images[new_type].filename = QString();
+ m_images[new_type].key = key;
}
diff --git a/api/gui/icons/MMCIcon.h b/api/gui/icons/MMCIcon.h
index 4bc7ecdc..23231945 100644
--- a/api/gui/icons/MMCIcon.h
+++ b/api/gui/icons/MMCIcon.h
@@ -24,11 +24,11 @@
struct MULTIMC_GUI_EXPORT MMCImage
{
QIcon icon;
+ QString key;
QString filename;
- QDateTime changed;
bool present() const
{
- return !icon.isNull();
+ return !icon.isNull() && !key.isEmpty();
}
};
@@ -45,4 +45,5 @@ struct MULTIMC_GUI_EXPORT MMCIcon
QIcon icon() const;
void remove(IconType rm_type);
void replace(IconType new_type, QIcon icon, QString path = QString());
+ void replace(IconType new_type, const QString &key);
};