[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
wilder
David Edmundson 4 years ago
parent 00a5d1607c
commit 28560c5d1c
  1. 12
      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

Loading…
Cancel
Save