on xenial help sign in
Watch for launcher item icon changes
commit9b64cbef6136677ce5d28df3db08ea24dcbf1ef1 authorLukáš Tinkl <lukas.tinkl@canonical.com> dateTue 1 Mar 2016, 16:24 (11 years ago) parent57f68ef
3 files changed+15−6
plugins/Unity/Launcher/launcheritem.h+1−1 plugins/Unity/Launcher/launchermodel.cpp+13−4 plugins/Unity/Launcher/launchermodel.h+1−1
plugins/Unity/Launcher/launcheritem.h+1−1
@@ -32,7 +32,7 @@ class LauncherItem: public LauncherItemInterface
3232{
3333 Q_OBJECT
3434public:
35− LauncherItem(const QString &appId, const QString &name, const QString &icon, QObject *parent = 0);
35+ LauncherItem(const QString &appId, const QString &name, const QString &icon, QObject *parent = nullptr);
3636
3737 QString appId() const override;
3838 QString name() const override;
plugins/Unity/Launcher/launchermodel.cpp+13−4
@@ -103,7 +103,7 @@ void LauncherModel::setAlerting(const QString &appId, bool alerting) {
103103 LauncherItem *item = m_list.at(index);
104104 if (!item->focused()) {
105105 item->setAlerting(alerting);
106− Q_EMIT dataChanged(modelIndex, modelIndex, QVector<int>() << RoleAlerting);
106+ Q_EMIT dataChanged(modelIndex, modelIndex, {RoleAlerting});
107107 }
108108 }
109109}
@@ -414,10 +414,19 @@ void LauncherModel::refresh()
414414 } else {
415415 int idx = m_list.indexOf(item);
416416 item->setName(desktopFile.displayName());
417− item->setIcon(desktopFile.icon());
418417 item->setPinned(item->pinned()); // update pinned text if needed
419418 item->setRunning(item->running());
420− Q_EMIT dataChanged(index(idx), index(idx), {RoleName, RoleIcon, RoleRunning});
419+ Q_EMIT dataChanged(index(idx), index(idx), {RoleName, RoleRunning});
420+
421+ const QString oldIcon = item->icon();
422+ if (oldIcon == desktopFile.icon()) { // same icon file, perhaps different contents, simulate changing the icon name to force reload
423+ item->setIcon(QString());
424+ Q_EMIT dataChanged(index(idx), index(idx), {RoleIcon});
425+ }
426+
427+ // now set the icon for real
428+ item->setIcon(desktopFile.icon());
429+ Q_EMIT dataChanged(index(idx), index(idx), {RoleIcon});
421430 }
422431 }
423432
@@ -489,7 +498,7 @@ void LauncherModel::alert(const QString &appId)
489498 if (idx >= 0) {
490499 LauncherItem *item = m_list.at(idx);
491500 setAlerting(item->appId(), true);
492− Q_EMIT dataChanged(index(idx), index(idx), QVector<int>() << RoleAlerting);
501+ Q_EMIT dataChanged(index(idx), index(idx), {RoleAlerting});
493502 }
494503}
495504
plugins/Unity/Launcher/launchermodel.h+1−1
@@ -38,7 +38,7 @@ class LauncherModel: public LauncherModelInterface
3838 Q_OBJECT
3939
4040public:
41− LauncherModel(QObject *parent = 0);
41+ LauncherModel(QObject *parent = nullptr);
4242 ~LauncherModel();
4343
4444 int rowCount(const QModelIndex &parent = QModelIndex()) const override;