Commit 91359a6a authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧 Committed by Aleix Pol Gonzalez
Browse files

coredump-gui: Show the app's icon name by the delegate

It can make it easier to find what you're looking for
parent a18aa2d4
Pipeline #181499 passed with stage
in 5 minutes and 49 seconds
......@@ -11,6 +11,7 @@
#include <KTerminalLauncherJob>
#include "../coredump/coredump.h"
#include <KApplicationTrader>
Patient::Patient(const Coredump &dump)
: m_signal(dump.m_rawData["COREDUMP_SIGNAL"].toInt())
......@@ -47,3 +48,25 @@ QString Patient::dateTime() const
time.setMSecsSinceEpoch(m_timestamp / 1000);
return time.toString();
}
QString Patient::iconName() const
{
// Caching it because it's an N² look-up and there generally are tons of duplicates
static QHash<QString, QString> s_cache;
const QString executable = m_appName;
auto it = s_cache.find(executable);
if (it == s_cache.end()) {
const auto servicesFound = KApplicationTrader::query([&executable](const KService::Ptr &service) {
return QFileInfo(service->exec()).fileName() == executable;
});
QString iconName;
if (servicesFound.isEmpty()) {
iconName = QStringLiteral("applications-science");
} else {
iconName = servicesFound.constFirst()->icon();
}
it = s_cache.insert(executable, iconName);
}
return *it;
}
......@@ -23,6 +23,7 @@ class Patient : public QObject
MEMBER_PROPERTY(time_t, timestamp) = 0;
#undef MEMBER_PROPERTY
Q_PROPERTY(QString dateTime READ dateTime NOTIFY changed)
Q_PROPERTY(QString iconName READ iconName CONSTANT)
public:
explicit Patient(const Coredump &dump);
......@@ -30,6 +31,7 @@ public:
Q_INVOKABLE void debug() const;
QString dateTime() const;
QString iconName() const;
Q_SIGNALS:
void changed();
......@@ -37,6 +39,7 @@ Q_SIGNALS:
private:
const QByteArray m_coredumpExe;
const QByteArray m_coredumpCom;
QString m_iconName;
};
Q_DECLARE_METATYPE(time_t)
......
......@@ -36,7 +36,7 @@ Kirigami.ScrollablePage {
delegate: Kirigami.BasicListItem {
label: modelObject.appName
subtitle: modelObject.dateTime
icon: "applications-science" // it may be hot to have signal icons instead
icon: modelObject.iconName
onClicked: pageStack.push("qrc:/DetailsPage.qml", {patient: modelObject})
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment