From acdc7613659181ddb5bd24484b180567dacf0108 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 23 May 2018 22:27:56 +0200 Subject: Register the icons resource from the frameworks plugin So we have the icons also available from the test views. --- applications/kube/main.cpp | 13 ------------- framework/src/frameworkplugin.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/applications/kube/main.cpp b/applications/kube/main.cpp index 411e2d6a..e0d37fc2 100644 --- a/applications/kube/main.cpp +++ b/applications/kube/main.cpp @@ -169,19 +169,6 @@ int main(int argc, char *argv[]) app.setApplicationVersion(kube_VERSION_STRING); app.setFont(QFont{"Noto Sans", app.font().pointSize(), QFont::Normal}); - QString kubeIcons = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("kube-icons.rcc")); - //For windows - if (kubeIcons.isEmpty()) { - kubeIcons = findFile(QStringLiteral("/kube/kube-icons.rcc"), QStandardPaths::standardLocations(QStandardPaths::AppDataLocation)); - } - if (!QResource::registerResource(kubeIcons, "/icons/kube")) { - qWarning() << "Failed to register icon resource!" << kubeIcons; - qWarning() << "Searched paths: " << QStandardPaths::standardLocations(QStandardPaths::AppDataLocation); - Q_ASSERT(false); - } else { - QIcon::setThemeSearchPaths(QStringList() << QStringLiteral(":/icons")); - QIcon::setThemeName(QStringLiteral("kube")); - } QCommandLineParser parser; parser.setApplicationDescription("A communication and collaboration client."); diff --git a/framework/src/frameworkplugin.cpp b/framework/src/frameworkplugin.cpp index 91d7a5dd..92c6df3a 100644 --- a/framework/src/frameworkplugin.cpp +++ b/framework/src/frameworkplugin.cpp @@ -112,10 +112,36 @@ static QObject *keyring_singletontype_provider(QQmlEngine *engine, QJSEngine *sc return instance; } +static QString findFile(const QString file, const QStringList importPathList) +{ + for (const auto &path : importPathList) { + const QString f = path + file; + if (QFileInfo::exists(f)) { + return f; + } + } + return {}; +} + void FrameworkPlugin::initializeEngine(QQmlEngine *engine, const char *uri) { Q_UNUSED(uri); engine->addImageProvider(QLatin1String("kube"), new KubeImageProvider); + + QString kubeIcons = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("kube-icons.rcc")); + //For windows + if (kubeIcons.isEmpty()) { + const auto locations = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation) + QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation); + kubeIcons = findFile(QStringLiteral("/kube/kube-icons.rcc"), locations); + } + if (!QResource::registerResource(kubeIcons, "/icons/kube")) { + qWarning() << "Failed to register icon resource!" << kubeIcons; + qWarning() << "Searched paths: " << QStandardPaths::standardLocations(QStandardPaths::AppDataLocation) + QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation); + Q_ASSERT(false); + } else { + QIcon::setThemeSearchPaths(QStringList() << QStringLiteral(":/icons")); + QIcon::setThemeName(QStringLiteral("kube")); + } } void FrameworkPlugin::registerTypes (const char *uri) -- cgit v1.2.3