From bce6367036483490ff5a41fc182cfa97282313fb Mon Sep 17 00:00:00 2001 From: mfritzsch Date: Fri, 5 May 2017 16:49:03 +0200 Subject: Home: Use icon from AFM, display a black area with text if icon unloadable * Try to find icons in the AFM_ICON_PATH. * If none was found, use the builtin. * If Home.qml cannot load the icon, display a shaded circle that approximates the size of the icons, and contains the icon name as text. * Enables proper scrolling of Home icons (and clipping to its dimensions). Change-Id: Ic921b357870648e675cda41985da2e985f4a0e6c --- homescreen/src/applicationmodel.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'homescreen/src/applicationmodel.cpp') diff --git a/homescreen/src/applicationmodel.cpp b/homescreen/src/applicationmodel.cpp index c43e1bc..e74411a 100644 --- a/homescreen/src/applicationmodel.cpp +++ b/homescreen/src/applicationmodel.cpp @@ -36,8 +36,23 @@ public: }; namespace { + QString find_icon_file(QString s) + { + auto f = QFileInfo(QString(AFM_ICON_DIR), s); + if (f.exists()) { + return f.absoluteFilePath(); + } + return QString(); + } + QString get_icon_name(QJsonObject const &i) { + QString icon_file_name = find_icon_file(i["id"].toString()); + + if (! icon_file_name.isEmpty()) { + return QStringLiteral("file:") + icon_file_name; + } + QString icon = i["id"].toString().split("@").front(); if (icon == "hvac" || icon == "poi") { icon = icon.toUpper(); @@ -46,6 +61,7 @@ namespace { } else { icon[0] = icon[0].toUpper(); } + return icon; } } @@ -55,7 +71,7 @@ ApplicationModel::Private::Private() QString apps = afm_user_daemon_proxy->runnables(QStringLiteral("")); QJsonDocument japps = QJsonDocument::fromJson(apps.toUtf8()); for (auto const &app : japps.array()) { - QJsonObject const &jso = app.toObject(); + auto const &jso = app.toObject(); auto const name = jso["name"].toString(); auto const id = jso["id"].toString(); auto const icon = get_icon_name(jso); -- cgit 1.2.3-korg