on xenial help sign in
Changed DBus-interface for launcher-item from alert-flag to alert-method upon request in MP-comment.
commit4a5f0b18f95ca68716090e349251f115a52b882c authorMirco Müller <mirco.mueller@ubuntu.com> dateThu 16 Jul 2015, 16:31 (11 years ago) parentc67efbb
4 files changed+34−22
plugins/Unity/Launcher/dbusinterface.cpp+21−21 plugins/Unity/Launcher/dbusinterface.h+1−1 plugins/Unity/Launcher/launchermodel.cpp+11 plugins/Unity/Launcher/launchermodel.h+1
plugins/Unity/Launcher/dbusinterface.cpp+21−21
@@ -66,7 +66,7 @@ QString DBusInterface::introspect(const QString &path) const
6666 "<interface name=\"com.canonical.Unity.Launcher.Item\">"
6767 "<property name=\"count\" type=\"i\" access=\"readwrite\" />"
6868 "<property name=\"countVisible\" type=\"b\" access=\"readwrite\" />"
69− "<property name=\"alerting\" type=\"b\" access=\"readwrite\" />"
69+ "<method name=\"Alert\" />"
7070 "</interface>";
7171 return nodeiface;
7272}
@@ -127,6 +127,19 @@ bool DBusInterface::handleMessage(const QDBusMessage& message, const QDBusConnec
127127 return false;
128128 }
129129
130+ /* Break down the path to just the app id */
131+ QString pathtemp = message.path();
132+ if (!pathtemp.startsWith("/com/canonical/Unity/Launcher/")) {
133+ return false;
134+ }
135+ pathtemp.remove("/com/canonical/Unity/Launcher/");
136+ if (pathtemp.indexOf('/') >= 0) {
137+ return false;
138+ }
139+
140+ /* Find ourselves an appid */
141+ QString appid = decodeAppId(pathtemp);
142+
130143 // First handle methods of the Launcher interface
131144 if (message.interface() == "com.canonical.Unity.Launcher") {
132145 if (message.member() == "Refresh") {
@@ -134,6 +147,13 @@ bool DBusInterface::handleMessage(const QDBusMessage& message, const QDBusConnec
134147 Q_EMIT refreshCalled();
135148 return connection.send(reply);
136149 }
150+ } else if (message.interface() == "com.canonical.Unity.Launcher.Item") {
151+ // Handle methods of the Launcher-Item interface
152+ if (message.member() == "Alert") {
153+ QDBusMessage reply = message.createReply();
154+ Q_EMIT alertCalled(appid);
155+ return connection.send(reply);
156+ }
137157 }
138158
139159 // Now handle dynamic properties (for launcher emblems)
@@ -145,18 +165,6 @@ bool DBusInterface::handleMessage(const QDBusMessage& message, const QDBusConnec
145165 return false;
146166 }
147167
148− /* Break down the path to just the app id */
149− QString pathtemp = message.path();
150− if (!pathtemp.startsWith("/com/canonical/Unity/Launcher/")) {
151− return false;
152− }
153− pathtemp.remove("/com/canonical/Unity/Launcher/");
154− if (pathtemp.indexOf('/') >= 0) {
155− return false;
156− }
157−
158− /* Find ourselves an appid */
159− QString appid = decodeAppId(pathtemp);
160168 int index = m_launcherModel->findApplication(appid);
161169 LauncherItem *item = static_cast<LauncherItem*>(m_launcherModel->get(index));
162170
@@ -169,8 +177,6 @@ bool DBusInterface::handleMessage(const QDBusMessage& message, const QDBusConnec
169177 retval.append(QVariant::fromValue(QDBusVariant(item->count())));
170178 } else if (message.arguments()[1].toString() == "countVisible") {
171179 retval.append(QVariant::fromValue(QDBusVariant(item->countVisible())));
172− } else if (message.arguments()[1].toString() == "alerting") {
173− retval.append(QVariant::fromValue(QDBusVariant(item->alerting())));
174180 }
175181 } else if (message.member() == "Set") {
176182 if (message.arguments()[1].toString() == "count") {
@@ -185,12 +191,6 @@ bool DBusInterface::handleMessage(const QDBusMessage& message, const QDBusConnec
185191 Q_EMIT countVisibleChanged(appid, newVisible);
186192 notifyPropertyChanged("com.canonical.Unity.Launcher.Item", encodeAppId(appid), "countVisible", newVisible);
187193 }
188− } else if (message.arguments()[1].toString() == "alerting") {
189− bool newAlerting = message.arguments()[2].value<QDBusVariant>().variant().toBool();
190− if (!item || newAlerting != item->alerting()) {
191− Q_EMIT alertingChanged(appid, newAlerting);
192− notifyPropertyChanged("com.canonical.Unity.Launcher.Item", encodeAppId(appid), "alerting", newAlerting);
193− }
194194 }
195195 } else if (message.member() == "GetAll") {
196196 if (item) {
plugins/Unity/Launcher/dbusinterface.h+1−1
@@ -36,8 +36,8 @@ public:
3636Q_SIGNALS:
3737 void countChanged(const QString &appId, int count);
3838 void countVisibleChanged(const QString &appId, bool countVisible);
39− void alertingChanged(const QString &appId, bool alerting);
4039 void refreshCalled();
40+ void alertCalled(const QString &appId);
4141
4242private:
4343 static QString decodeAppId(const QString& path);
plugins/Unity/Launcher/launchermodel.cpp+11
@@ -41,6 +41,7 @@ LauncherModel::LauncherModel(QObject *parent):
4141 connect(m_dbusIface, &DBusInterface::countChanged, this, &LauncherModel::countChanged);
4242 connect(m_dbusIface, &DBusInterface::countVisibleChanged, this, &LauncherModel::countVisibleChanged);
4343 connect(m_dbusIface, &DBusInterface::refreshCalled, this, &LauncherModel::refresh);
44+ connect(m_dbusIface, &DBusInterface::alertCalled, this, &LauncherModel::alert);
4445
4546 connect(m_settings, &GSettings::changed, this, &LauncherModel::refresh);
4647
@@ -473,6 +474,16 @@ void LauncherModel::refresh()
473474 m_asAdapter->syncItems(m_list);
474475}
475476
477+void LauncherModel::alert(const QString &appId)
478+{
479+ int idx = findApplication(appId);
480+ if (idx >= 0) {
481+ LauncherItem *item = m_list.at(idx);
482+ setAlerting(item->appId(), true);
483+ Q_EMIT dataChanged(index(idx), index(idx), QVector<int>() << RoleAlerting);
484+ }
485+}
486+
476487void LauncherModel::applicationAdded(const QModelIndex &parent, int row)
477488{
478489 Q_UNUSED(parent);
plugins/Unity/Launcher/launchermodel.h+1
@@ -64,6 +64,7 @@ public:
6464public Q_SLOTS:
6565 void requestRemove(const QString &appId) override;
6666 Q_INVOKABLE void refresh();
67+ Q_INVOKABLE void alert(const QString &appId);
6768
6869private:
6970 void storeAppList();