Commit 615f6ac1 authored by David Edmundson's avatar David Edmundson
Browse files

Fix crash in KAStatsFavouritesModel

Summary:
KAStatsFavouritesModel doesn't initialise a D-pointer for the lifespan
of the KAStatsFavouritesModel, like the name implies.

It is set in initForClient.

If the activity changes before we have a client ID, there's no point
doing anything and trying to use the clientID will crash.

BUG: 386439

Test Plan: None.

Reviewers: #plasma, hein

Reviewed By: #plasma, hein

Subscribers: anthonyfieroni, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D8608
parent 065a0fcf
...@@ -470,8 +470,10 @@ KAStatsFavoritesModel::KAStatsFavoritesModel(QObject *parent) ...@@ -470,8 +470,10 @@ KAStatsFavoritesModel::KAStatsFavoritesModel(QObject *parent)
this, [&] (const QString &currentActivity) { this, [&] (const QString &currentActivity) {
DEBUG << "Activity just got changed to" << currentActivity; DEBUG << "Activity just got changed to" << currentActivity;
Q_UNUSED(currentActivity); Q_UNUSED(currentActivity);
auto clientId = d->m_clientId; if (d) {
initForClient(clientId); auto clientId = d->m_clientId;
initForClient(clientId);
}
}); });
} }
...@@ -501,7 +503,7 @@ QString KAStatsFavoritesModel::description() const ...@@ -501,7 +503,7 @@ QString KAStatsFavoritesModel::description() const
bool KAStatsFavoritesModel::trigger(int row, const QString &actionId, const QVariant &argument) bool KAStatsFavoritesModel::trigger(int row, const QString &actionId, const QVariant &argument)
{ {
return d->trigger(row, actionId, argument); return d && d->trigger(row, actionId, argument);
} }
bool KAStatsFavoritesModel::enabled() const bool KAStatsFavoritesModel::enabled() const
...@@ -547,6 +549,7 @@ bool KAStatsFavoritesModel::isFavorite(const QString &id) const ...@@ -547,6 +549,7 @@ bool KAStatsFavoritesModel::isFavorite(const QString &id) const
void KAStatsFavoritesModel::portOldFavorites(const QStringList &ids) void KAStatsFavoritesModel::portOldFavorites(const QStringList &ids)
{ {
if (!d) return;
DEBUG << "portOldFavorites" << ids; DEBUG << "portOldFavorites" << ids;
const auto activityId = ":global"; const auto activityId = ":global";
...@@ -617,6 +620,8 @@ void KAStatsFavoritesModel::addFavoriteTo(const QString &id, const Activity &act ...@@ -617,6 +620,8 @@ void KAStatsFavoritesModel::addFavoriteTo(const QString &id, const Activity &act
void KAStatsFavoritesModel::removeFavoriteFrom(const QString &id, const Activity &activity) void KAStatsFavoritesModel::removeFavoriteFrom(const QString &id, const Activity &activity)
{ {
if (!d || id.isEmpty()) return;
const auto url = d->normalizedId(id).value(); const auto url = d->normalizedId(id).value();
Q_ASSERT(!activity.values.isEmpty()); Q_ASSERT(!activity.values.isEmpty());
...@@ -631,6 +636,8 @@ void KAStatsFavoritesModel::removeFavoriteFrom(const QString &id, const Activity ...@@ -631,6 +636,8 @@ void KAStatsFavoritesModel::removeFavoriteFrom(const QString &id, const Activity
void KAStatsFavoritesModel::setFavoriteOn(const QString &id, const QString &activityId) void KAStatsFavoritesModel::setFavoriteOn(const QString &id, const QString &activityId)
{ {
if (!d || id.isEmpty()) return;
const auto url = d->normalizedId(id).value(); const auto url = d->normalizedId(id).value();
DEBUG << "setFavoriteOn" << id << activityId << url << " (actual)"; DEBUG << "setFavoriteOn" << id << activityId << url << " (actual)";
...@@ -650,6 +657,8 @@ void KAStatsFavoritesModel::setFavoriteOn(const QString &id, const QString &acti ...@@ -650,6 +657,8 @@ void KAStatsFavoritesModel::setFavoriteOn(const QString &id, const QString &acti
void KAStatsFavoritesModel::moveRow(int from, int to) void KAStatsFavoritesModel::moveRow(int from, int to)
{ {
if (!d) return;
d->move(from, to); d->move(from, to);
} }
......
Markdown is supported
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