on xenial help sign in
Pulling some common code into a helper function
commit924875142e9ba5f09b6d8b780128bad05d37bd54 authorTed Gould <ted@gould.cx> dateThu 10 Apr 2014, 16:32 (13 years ago) parent23d6b54
2 files changed+24−41
plugins/Unity/Launcher/backend/launcherbackend.cpp+23−41 plugins/Unity/Launcher/backend/launcherbackend.h+1
plugins/Unity/Launcher/backend/launcherbackend.cpp+23−41
@@ -133,16 +133,9 @@ QString LauncherBackend::displayName(const QString &appId) const
133133QString LauncherBackend::icon(const QString &appId) const
134134{
135135 QString iconName;
136− LauncherBackendItem *item = m_itemCache.value(appId);
136+ LauncherBackendItem *item = getItem(appId);
137137 if (item) {
138138 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− }
146139 }
147140
148141 return iconName;
@@ -169,14 +162,7 @@ int LauncherBackend::progress(const QString &appId) const
169162int LauncherBackend::count(const QString &appId) const
170163{
171164 int count = -1;
172− LauncherBackendItem *item = m_itemCache.value(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− }
165+ LauncherBackendItem *item = getItem(appId);
180166
181167 if (!item) {
182168 if (item->countVisible) {
@@ -189,14 +175,7 @@ int LauncherBackend::count(const QString &appId) const
189175
190176void LauncherBackend::setCount(const QString &appId, int count) const
191177{
192− LauncherBackendItem *item = m_itemCache.value(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− }
178+ LauncherBackendItem *item = getItem(appId);
200179
201180 bool emitchange = false;
202181 if (!item) {
@@ -217,14 +196,7 @@ void LauncherBackend::setCount(const QString &appId, int count) const
217196bool LauncherBackend::countVisible(const QString &appId) const
218197{
219198 bool visible = false;
220− LauncherBackendItem *item = m_itemCache.value(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− }
199+ LauncherBackendItem *item = getItem(appId);
228200
229201 if (!item) {
230202 visible = item->countVisible;
@@ -235,20 +207,13 @@ bool LauncherBackend::countVisible(const QString &appId) const
235207
236208void LauncherBackend::setCountVisible(const QString &appId, bool visible) const
237209{
238− LauncherBackendItem *item = m_itemCache.value(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− }
210+ LauncherBackendItem *item = getItem(appId);
246211
247212 bool emitchange = false;
248213 if (!item) {
249214 emitchange = (item->countVisible != visible);
250215 item->countVisible = visible;
251− }
216+ }
252217
253218 if (emitchange) {
254219 /* TODO: Because we're using visible in determining the
@@ -384,6 +349,23 @@ LauncherBackendItem* LauncherBackend::parseDesktopFile(const QString &desktopFil
384349 return item;
385350}
386351
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+
387369void LauncherBackend::loadFromVariant(const QVariantMap &details)
388370{
389371 if (!details.contains("id")) {
plugins/Unity/Launcher/backend/launcherbackend.h+1
@@ -168,6 +168,7 @@ Q_SIGNALS:
168168private:
169169 QString findDesktopFile(const QString &appId) const;
170170 LauncherBackendItem* parseDesktopFile(const QString &desktopFile) const;
171+ LauncherBackendItem* getItem (const QString& appId) const;
171172
172173 QVariantMap itemToVariant(const QString &appId) const;
173174 void loadFromVariant(const QVariantMap &details);