From 28560c5d1c2e3a22593c716b399e73cb3e27f32f Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Mon, 5 Sep 2022 10:00:20 +0100 Subject: [PATCH] [applets/kickoff] Always instantiate KService::Ptr member Code uses m_service unconditionally in many branches, it is exposed as public API. Given KService is a data class with an isValid method, it's clearer to ensure that KService::Ptr always returns a valid object which in turn can then be valid rather than having two paths for the same goal. This can be relevant in a situation where an entry using the "preferred" schema references an entry that doesn't exist. BUG: 423524 --- applets/kicker/plugin/appentry.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/applets/kicker/plugin/appentry.cpp b/applets/kicker/plugin/appentry.cpp index 997b484cc..592014fdd 100644 --- a/applets/kicker/plugin/appentry.cpp +++ b/applets/kicker/plugin/appentry.cpp @@ -133,9 +133,8 @@ AppEntry::AppEntry(AbstractModel *owner, KService::Ptr service, NameFormat nameF : AbstractEntry(owner) , m_service(service) { - if (m_service) { - init(nameFormat); - } + Q_ASSERT(service); + init(nameFormat); } AppEntry::AppEntry(AbstractModel *owner, const QString &id) @@ -158,8 +157,11 @@ AppEntry::AppEntry(AbstractModel *owner, const QString &id) } else { m_service = KService::serviceByStorageId(id); } + if (!m_service) { + m_service = new KService(QString()); + } - if (m_service) { + if (m_service->isValid()) { init((NameFormat)owner->rootModel()->property("appNameFormat").toInt()); } } @@ -177,7 +179,7 @@ void AppEntry::init(NameFormat nameFormat) bool AppEntry::isValid() const { - return m_service; + return m_service->isValid(); } QIcon AppEntry::icon() const