on xenial help sign in
All of the set and get stuff
commitb668264a8226d63ee454d9bc3904ff46bdfed111 authorTed Gould <ted@gould.cx> dateThu 10 Apr 2014, 12:21 (13 years ago) parentc8082f9
2 files changed+122−6
plugins/Unity/Launcher/backend/launcherbackend.cpp+95−3 plugins/Unity/Launcher/backend/launcherbackend.h+27−3
plugins/Unity/Launcher/backend/launcherbackend.cpp+95−3
@@ -166,9 +166,7 @@ int LauncherBackend::progress(const QString &appId) const
166166
167167int LauncherBackend::count(const QString &appId) const
168168{
169− // TODO: emit countChanged() when this value changes.
170−
171− int count = 0;
169+ int count = -1;
172170 LauncherBackendItem *item = m_itemCache.value(appId);
173171 if (!item) {
174172 QString df = findDesktopFile(appId);
@@ -187,6 +185,79 @@ int LauncherBackend::count(const QString &appId) const
187185 return count;
188186}
189187
188+void LauncherBackend::setCount(const QString &appId, int count) const
189+{
190+ LauncherBackendItem *item = m_itemCache.value(appId);
191+ if (!item) {
192+ QString df = findDesktopFile(appId);
193+ if (!df.isEmpty()) {
194+ item = parseDesktopFile(df);
195+ m_itemCache.insert(appId, item);
196+ }
197+ }
198+
199+ bool emitchange = false;
200+ if (!item) {
201+ emitchange = (item->count != count);
202+ item->count = count;
203+ }
204+
205+ if (emitchange) {
206+ /* TODO: This needs to use the accessor to handle the visibility
207+ correctly, but when we have the two properties we can just use
208+ the local value */
209+ Q_EMIT countChanged(appId, this->count(appId));
210+ QVariant vcount(item->count);
211+ emitPropChangedDbus(appId, "count", vcount);
212+ }
213+}
214+
215+bool LauncherBackend::countVisible(const QString &appId) const
216+{
217+ bool visible = false;
218+ LauncherBackendItem *item = m_itemCache.value(appId);
219+ if (!item) {
220+ QString df = findDesktopFile(appId);
221+ if (!df.isEmpty()) {
222+ item = parseDesktopFile(df);
223+ m_itemCache.insert(appId, item);
224+ }
225+ }
226+
227+ if (!item) {
228+ visible = item->countVisible;
229+ }
230+
231+ return visible;
232+}
233+
234+void LauncherBackend::setCountVisible(const QString &appId, bool visible) const
235+{
236+ LauncherBackendItem *item = m_itemCache.value(appId);
237+ if (!item) {
238+ QString df = findDesktopFile(appId);
239+ if (!df.isEmpty()) {
240+ item = parseDesktopFile(df);
241+ m_itemCache.insert(appId, item);
242+ }
243+ }
244+
245+ bool emitchange = false;
246+ if (!item) {
247+ emitchange = (item->countVisible != visible);
248+ item->countVisible = visible;
249+ }
250+
251+ if (emitchange) {
252+ /* TODO: Because we're using visible in determining the
253+ count we need to emit a count changed as well */
254+ Q_EMIT countChanged(appId, this->count(appId));
255+ Q_EMIT countVisibleChanged(appId, item->countVisible);
256+ QVariant vCountVisible(item->countVisible);
257+ emitPropChangedDbus(appId, "countVisible", vCountVisible);
258+ }
259+}
260+
190261void LauncherBackend::setUser(const QString &username)
191262{
192263 if (qgetenv("USER") == "lightdm" && m_user != username) {
@@ -470,3 +541,24 @@ QString LauncherBackend::encodeAppId (const QString& appId) const
470541
471542 return encoded;
472543}
544+
545+void LauncherBackend::emitPropChangedDbus (const QString& appId, const QString& property, QVariant &value) const
546+{
547+ QString path("/com/canonical/unity/launcher/");
548+ path.append(encodeAppId(appId));
549+
550+ QDBusMessage message = QDBusMessage::createSignal(path, "org.freedesktop.DBus.Properties", "PropertiesChanged");
551+
552+ QList<QVariant> arguments;
553+ QVariantHash changedprops;
554+ changedprops[property] = value;
555+ QVariantList deletedprops;
556+
557+ arguments.append(changedprops);
558+ arguments.append(deletedprops);
559+
560+ message.setArguments(arguments);
561+
562+ QDBusConnection con = QDBusConnection::sessionBus();
563+ con.send(message);
564+}
plugins/Unity/Launcher/backend/launcherbackend.h+27−3
@@ -117,6 +117,27 @@ public:
117117 */
118118 int count(const QString &appId) const;
119119
120+ /**
121+ * @brief Set the count on an item
122+ * @param appId The ID of the application
123+ * @param count Count to show on the application
124+ */
125+ void setCount(const QString &appId, int count) const;
126+
127+ /**
128+ * @brief Get whether the count should be visible
129+ * @param appId The ID of the application.
130+ * @returns Whether to show a count on the launcher
131+ */
132+ bool countVisible(const QString &appId) const;
133+
134+ /**
135+ * @brief Set the visibility of the count item
136+ * @param appId The ID of the application
137+ * @param visible Whether the count should be visible
138+ */
139+ void setCountVisible(const QString &appId, bool visible) const;
140+
120141 /**
121142 * @brief Sets the username for which to look up launcher items.
122143 * @param username The username to use.
@@ -139,9 +160,10 @@ public:
139160 virtual QString introspect (const QString &path) const;
140161
141162Q_SIGNALS:
142− void quickListChanged(const QString &appId, const QList<QuickListEntry> &quickList);
143− void progressChanged(const QString &appId, int progress);
144− void countChanged(const QString &appId, int count);
163+ void quickListChanged(const QString &appId, const QList<QuickListEntry> &quickList) const;
164+ void progressChanged(const QString &appId, int progress) const;
165+ void countChanged(const QString &appId, int count) const;
166+ void countVisibleChanged(const QString &appId, bool visible) const;
145167
146168private:
147169 QString findDesktopFile(const QString &appId) const;
@@ -162,6 +184,8 @@ private:
162184
163185 QString decodeAppId (const QString& path) const;
164186 QString encodeAppId (const QString& appId) const;
187+
188+ void emitPropChangedDbus (const QString& appId, const QString& property, QVariant &value) const;
165189};
166190
167191#endif // LAUNCHERBACKEND_H