diff options
author | Jan Dalheimer <jan@dalheimer.de> | 2015-05-28 19:38:29 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2015-06-06 21:23:05 +0200 |
commit | 3a8b238052163952831fb5924b2483a375e86ebd (patch) | |
tree | ab120b4fac3a5345a20e7a09e1e7477e67d9ed6f /logic/resources/IconResourceHandler.cpp | |
parent | 161dc66c2c8d5f973ee69dab36c3969a7efd7495 (diff) | |
download | MultiMC-3a8b238052163952831fb5924b2483a375e86ebd.tar MultiMC-3a8b238052163952831fb5924b2483a375e86ebd.tar.gz MultiMC-3a8b238052163952831fb5924b2483a375e86ebd.tar.lz MultiMC-3a8b238052163952831fb5924b2483a375e86ebd.tar.xz MultiMC-3a8b238052163952831fb5924b2483a375e86ebd.zip |
NOISSUE Various changes from multiauth that are unrelated to it
Diffstat (limited to 'logic/resources/IconResourceHandler.cpp')
-rw-r--r-- | logic/resources/IconResourceHandler.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/logic/resources/IconResourceHandler.cpp b/logic/resources/IconResourceHandler.cpp new file mode 100644 index 00000000..d47dcc3d --- /dev/null +++ b/logic/resources/IconResourceHandler.cpp @@ -0,0 +1,60 @@ +#include "IconResourceHandler.h" + +#include <QDir> +#include <QDebug> + +QString IconResourceHandler::m_theme = "multimc"; +QList<std::weak_ptr<IconResourceHandler>> IconResourceHandler::m_iconHandlers; + +IconResourceHandler::IconResourceHandler(const QString &key) + : m_key(key) +{ +} + +void IconResourceHandler::setTheme(const QString &theme) +{ + m_theme = theme; + + for (auto handler : m_iconHandlers) + { + std::shared_ptr<IconResourceHandler> ptr = handler.lock(); + if (ptr) + { + ptr->setResult(ptr->get()); + } + } +} + +void IconResourceHandler::init(std::shared_ptr<ResourceHandler> &ptr) +{ + m_iconHandlers.append(std::dynamic_pointer_cast<IconResourceHandler>(ptr)); + setResult(get()); +} + +QVariant IconResourceHandler::get() const +{ + const QDir iconsDir = QDir(":/icons/" + m_theme); + + QVariantMap out; + for (const QFileInfo &sizeInfo : iconsDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot)) + { + const QDir dir = QDir(sizeInfo.absoluteFilePath()); + const QString dirName = sizeInfo.fileName(); + const int size = dirName.left(dirName.indexOf('x')).toInt(); + if (dir.exists(m_key + ".png") && dirName != "scalable") + { + out.insert(dir.absoluteFilePath(m_key + ".png"), size); + } + else if (dir.exists(m_key + ".svg") && dirName == "scalable") + { + out.insert(dir.absoluteFilePath(m_key + ".svg"), size); + } + } + + if (out.isEmpty()) + { + qWarning() << "Couldn't find any icons for" << m_key; + } + + return out; +} |