on xenial help sign in
update launcher on app install/update/removal
commit36ba1aac458039e62da87f6ab53f2212a64bbf30 authorMichael Zanetti <michael.zanetti@canonical.com> dateFri 22 Aug 2014, 13:19 (12 years ago) parent3e0d35c
5 files changed+47−1
data/unity8-filewatcher.conf+8 plugins/Unity/Launcher/backend/launcherbackend.cpp+33 plugins/Unity/Launcher/backend/launcherbackend.h+2 plugins/Unity/Launcher/launchermodel.cpp+1 plugins/Unity/Launcher/launchermodel.h+3−1
data/unity8-filewatcher.confnew file+8
@@ -0,0 +1,8 @@
1+description "File system watcher for unity8"
2+author "Michael Zanetti <michael.zanetti@canonical.com>"
3+
4+# Workaround for bug 1360208. ~ and * in one expression doesn't work currently
5+start on (file FILE=/home/phablet/.local/share/applications/*.desktop) or (file FILE=/usr/share/applications/*.desktop)
6+
7+exec dbus-send --type=method_call --dest=com.canonical.Unity.Launcher /com/canonical/Unity/Launcher com.canonical.Unity.Launcher.Refresh
8+
plugins/Unity/Launcher/backend/launcherbackend.cpp+33
@@ -314,6 +314,19 @@ void LauncherBackend::syncToAccounts()
314314 }
315315}
316316
317+void LauncherBackend::refresh()
318+{
319+ QList<QString> removedApps;
320+ Q_FOREACH (const QString &appId, m_storedApps) {
321+ if (findDesktopFile(appId).isEmpty()) {
322+ removedApps << appId;
323+ }
324+ }
325+ Q_FOREACH (const QString &appId, removedApps) {
326+ Q_EMIT appUninstalled(appId);
327+ }
328+}
329+
317330QString LauncherBackend::findDesktopFile(const QString &appId) const
318331{
319332 int dashPos = -1;
@@ -400,6 +413,10 @@ void LauncherBackend::loadFromVariant(const QVariantMap &details)
400413 }
401414 QString appId = details.value("id").toString();
402415
416+ if (findDesktopFile(appId).isEmpty()) {
417+ return;
418+ }
419+
403420 LauncherBackendItem *item = m_itemCache.value(appId, nullptr);
404421 if (item) {
405422 delete item;
@@ -442,6 +459,16 @@ bool LauncherBackend::handleMessage(const QDBusMessage& message, const QDBusConn
442459 if (message.type() != QDBusMessage::MessageType::MethodCallMessage) {
443460 return false;
444461 }
462+ // First handle methods of the Launcher interface
463+ if (message.interface() == "com.canonical.Unity.Launcher") {
464+ if (message.member() == "Refresh") {
465+ QDBusMessage reply = message.createReply();
466+ refresh();
467+ return connection.send(reply);
468+ }
469+ }
470+
471+ // Now handle dynamic properties (for launcher emblems)
445472 if (message.interface() != "org.freedesktop.DBus.Properties") {
446473 return false;
447474 }
@@ -491,6 +518,12 @@ QString LauncherBackend::introspect(const QString &path) const
491518 if (path == "/com/canonical/Unity/Launcher/" || path == "/com/canonical/Unity/Launcher") {
492519 QString nodes;
493520
521+ // Add Refresh to introspect
522+ nodes = "<interface name=\"com.canonical.Unity.Launcher\">"
523+ "<method name=\"Refresh\"/>"
524+ "</interface>";
525+
526+ // Add dynamic properties for launcher emblems
494527 Q_FOREACH(const QString &appId, m_itemCache.keys()) {
495528 nodes.append("<node name=\"");
496529 nodes.append(encodeAppId(appId));
plugins/Unity/Launcher/backend/launcherbackend.h+2
@@ -166,6 +166,7 @@ Q_SIGNALS:
166166 void progressChanged(const QString &appId, int progress) const;
167167 void countChanged(const QString &appId, int count) const;
168168 void countVisibleChanged(const QString &appId, bool visible) const;
169+ void appUninstalled(const QString &appId);
169170
170171private:
171172 QString findDesktopFile(const QString &appId) const;
@@ -177,6 +178,7 @@ private:
177178 bool isDefaultsItem(const QList<QVariantMap> &apps) const;
178179 void syncFromAccounts();
179180 void syncToAccounts();
181+ void refresh();
180182
181183 QList<QString> m_storedApps;
182184 mutable QHash<QString, LauncherBackendItem*> m_itemCache;
plugins/Unity/Launcher/launchermodel.cpp+1
@@ -34,6 +34,7 @@ LauncherModel::LauncherModel(QObject *parent):
3434{
3535 connect(m_backend, SIGNAL(countChanged(QString,int)), SLOT(countChanged(QString,int)));
3636 connect(m_backend, SIGNAL(progressChanged(QString,int)), SLOT(progressChanged(QString,int)));
37+ connect(m_backend, SIGNAL(appUninstalled(QString)), SLOT(requestRemove(QString)));
3738
3839 Q_FOREACH (const QString &entry, m_backend->storedApplications()) {
3940 LauncherItem *item = new LauncherItem(entry,
plugins/Unity/Launcher/launchermodel.h+3−1
@@ -48,7 +48,6 @@ public:
4848 Q_INVOKABLE unity::shell::launcher::LauncherItemInterface* get(int index) const;
4949 Q_INVOKABLE void move(int oldIndex, int newIndex);
5050 Q_INVOKABLE void pin(const QString &appId, int index = -1);
51− Q_INVOKABLE void requestRemove(const QString &appId);
5251 Q_INVOKABLE void quickListActionInvoked(const QString &appId, int actionIndex);
5352 Q_INVOKABLE void setUser(const QString &username);
5453 Q_INVOKABLE QString getUrlForAppId(const QString &appId) const;
@@ -56,6 +55,9 @@ public:
5655 unity::shell::application::ApplicationManagerInterface* applicationManager() const;
5756 void setApplicationManager(unity::shell::application::ApplicationManagerInterface *appManager);
5857
58+public Q_SLOTS:
59+ void requestRemove(const QString &appId);
60+
5961private:
6062 void storeAppList();
6163 int findApplication(const QString &appId);