on xenial help sign in
All of the set and get stuff
b668264Ted Gould
plugins/Unity/Launcher/backend/launcherbackend.cpp+95−3
@@ -166,9 +166,7 @@ int LauncherBackend::progress(const QString &appId) const
166
166
167int LauncherBackend::count(const QString &appId) const
167int LauncherBackend::count(const QString &appId) const
168{
168{
169− // TODO: emit countChanged() when this value changes.
170−
171− int count = 0;
169+ int count = -1;
172 LauncherBackendItem *item = m_itemCache.value(appId);
170 LauncherBackendItem *item = m_itemCache.value(appId);
173 if (!item) {
171 if (!item) {
174 QString df = findDesktopFile(appId);
172 QString df = findDesktopFile(appId);
@@ -187,6 +185,79 @@ int LauncherBackend::count(const QString &appId) const
187 return count;
185 return count;
188}
186}
189
187
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+
190void LauncherBackend::setUser(const QString &username)
261void LauncherBackend::setUser(const QString &username)
191{
262{
192 if (qgetenv("USER") == "lightdm" && m_user != username) {
263 if (qgetenv("USER") == "lightdm" && m_user != username) {
@@ -470,3 +541,24 @@ QString LauncherBackend::encodeAppId (const QString& appId) const
470
541
471 return encoded;
542 return encoded;
472}
543}
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:
117 */
117 */
118 int count(const QString &appId) const;
118 int count(const QString &appId) const;
119
119
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+
120 /**
141 /**
121 * @brief Sets the username for which to look up launcher items.
142 * @brief Sets the username for which to look up launcher items.
122 * @param username The username to use.
143 * @param username The username to use.
@@ -139,9 +160,10 @@ public:
139 virtual QString introspect (const QString &path) const;
160 virtual QString introspect (const QString &path) const;
140
161
141Q_SIGNALS:
162Q_SIGNALS:
142− void quickListChanged(const QString &appId, const QList<QuickListEntry> &quickList);
163+ void quickListChanged(const QString &appId, const QList<QuickListEntry> &quickList) const;
143− void progressChanged(const QString &appId, int progress);
164+ void progressChanged(const QString &appId, int progress) const;
144− void countChanged(const QString &appId, int count);
165+ void countChanged(const QString &appId, int count) const;
166+ void countVisibleChanged(const QString &appId, bool visible) const;
145
167
146private:
168private:
147 QString findDesktopFile(const QString &appId) const;
169 QString findDesktopFile(const QString &appId) const;
@@ -162,6 +184,8 @@ private:
162
184
163 QString decodeAppId (const QString& path) const;
185 QString decodeAppId (const QString& path) const;
164 QString encodeAppId (const QString& appId) const;
186 QString encodeAppId (const QString& appId) const;
187+
188+ void emitPropChangedDbus (const QString& appId, const QString& property, QVariant &value) const;
165};
189};
166
190
167#endif // LAUNCHERBACKEND_H
191#endif // LAUNCHERBACKEND_H