on xenial help sign in
Pulling some common code into a helper function
9248751Ted Gould
plugins/Unity/Launcher/backend/launcherbackend.cpp+23−41
@@ -133,16 +133,9 @@ QString LauncherBackend::displayName(const QString &appId) const
133QString LauncherBackend::icon(const QString &appId) const
133QString LauncherBackend::icon(const QString &appId) const
134{
134{
135 QString iconName;
135 QString iconName;
136− LauncherBackendItem *item = m_itemCache.value(appId);
136+ LauncherBackendItem *item = getItem(appId);
137 if (item) {
137 if (item) {
138 iconName = item->icon;
138 iconName = item->icon;
139− } else {
140− QString df = findDesktopFile(appId);
141− if (!df.isEmpty()) {
142− LauncherBackendItem *item = parseDesktopFile(df);
143− m_itemCache.insert(appId, item);
144− iconName = item->icon;
145− }
146 }
139 }
147
140
148 return iconName;
141 return iconName;
@@ -169,14 +162,7 @@ int LauncherBackend::progress(const QString &appId) const
169int LauncherBackend::count(const QString &appId) const
162int LauncherBackend::count(const QString &appId) const
170{
163{
171 int count = -1;
164 int count = -1;
172− LauncherBackendItem *item = m_itemCache.value(appId);
165+ LauncherBackendItem *item = getItem(appId);
173− if (!item) {
174− QString df = findDesktopFile(appId);
175− if (!df.isEmpty()) {
176− item = parseDesktopFile(df);
177− m_itemCache.insert(appId, item);
178− }
179− }
180
166
181 if (!item) {
167 if (!item) {
182 if (item->countVisible) {
168 if (item->countVisible) {
@@ -189,14 +175,7 @@ int LauncherBackend::count(const QString &appId) const
189
175
190void LauncherBackend::setCount(const QString &appId, int count) const
176void LauncherBackend::setCount(const QString &appId, int count) const
191{
177{
192− LauncherBackendItem *item = m_itemCache.value(appId);
178+ LauncherBackendItem *item = getItem(appId);
193− if (!item) {
194− QString df = findDesktopFile(appId);
195− if (!df.isEmpty()) {
196− item = parseDesktopFile(df);
197− m_itemCache.insert(appId, item);
198− }
199− }
200
179
201 bool emitchange = false;
180 bool emitchange = false;
202 if (!item) {
181 if (!item) {
@@ -217,14 +196,7 @@ void LauncherBackend::setCount(const QString &appId, int count) const
217bool LauncherBackend::countVisible(const QString &appId) const
196bool LauncherBackend::countVisible(const QString &appId) const
218{
197{
219 bool visible = false;
198 bool visible = false;
220− LauncherBackendItem *item = m_itemCache.value(appId);
199+ LauncherBackendItem *item = getItem(appId);
221− if (!item) {
222− QString df = findDesktopFile(appId);
223− if (!df.isEmpty()) {
224− item = parseDesktopFile(df);
225− m_itemCache.insert(appId, item);
226− }
227− }
228
200
229 if (!item) {
201 if (!item) {
230 visible = item->countVisible;
202 visible = item->countVisible;
@@ -235,20 +207,13 @@ bool LauncherBackend::countVisible(const QString &appId) const
235
207
236void LauncherBackend::setCountVisible(const QString &appId, bool visible) const
208void LauncherBackend::setCountVisible(const QString &appId, bool visible) const
237{
209{
238− LauncherBackendItem *item = m_itemCache.value(appId);
210+ LauncherBackendItem *item = getItem(appId);
239− if (!item) {
240− QString df = findDesktopFile(appId);
241− if (!df.isEmpty()) {
242− item = parseDesktopFile(df);
243− m_itemCache.insert(appId, item);
244− }
245− }
246
211
247 bool emitchange = false;
212 bool emitchange = false;
248 if (!item) {
213 if (!item) {
249 emitchange = (item->countVisible != visible);
214 emitchange = (item->countVisible != visible);
250 item->countVisible = visible;
215 item->countVisible = visible;
251− }
216+ }
252
217
253 if (emitchange) {
218 if (emitchange) {
254 /* TODO: Because we're using visible in determining the
219 /* TODO: Because we're using visible in determining the
@@ -384,6 +349,23 @@ LauncherBackendItem* LauncherBackend::parseDesktopFile(const QString &desktopFil
384 return item;
349 return item;
385}
350}
386
351
352+/* Gets an item, and tries to create a new one if we need it to */
353+LauncherBackendItem* LauncherBackend::getItem (const QString &appId) const
354+{
355+ LauncherBackendItem *item = m_itemCache.value(appId);
356+ if (!item) {
357+ QString df = findDesktopFile(appId);
358+ if (!df.isEmpty()) {
359+ item = parseDesktopFile(df);
360+ if (item) {
361+ m_itemCache.insert(appId, item);
362+ }
363+ }
364+ }
365+
366+ return item;
367+}
368+
387void LauncherBackend::loadFromVariant(const QVariantMap &details)
369void LauncherBackend::loadFromVariant(const QVariantMap &details)
388{
370{
389 if (!details.contains("id")) {
371 if (!details.contains("id")) {
plugins/Unity/Launcher/backend/launcherbackend.h+1
@@ -168,6 +168,7 @@ Q_SIGNALS:
168private:
168private:
169 QString findDesktopFile(const QString &appId) const;
169 QString findDesktopFile(const QString &appId) const;
170 LauncherBackendItem* parseDesktopFile(const QString &desktopFile) const;
170 LauncherBackendItem* parseDesktopFile(const QString &desktopFile) const;
171+ LauncherBackendItem* getItem (const QString& appId) const;
171
172
172 QVariantMap itemToVariant(const QString &appId) const;
173 QVariantMap itemToVariant(const QString &appId) const;
173 void loadFromVariant(const QVariantMap &details);
174 void loadFromVariant(const QVariantMap &details);