void AppLinkProvider::update() { emit aboutToBeChanged(); QHash<QString, AppLinkItem*> newItems; #ifdef HAVE_MENU_CACHE // libmenu-cache is available, use it to get cached app list GSList* apps = menu_cache_list_all_apps(mMenuCache); for(GSList* l = apps; l; l = l->next) { MenuCacheApp* app = MENU_CACHE_APP(l->data); AppLinkItem *item = new AppLinkItem(app); AppLinkItem *prevItem = newItems[item->command()]; if(prevItem) delete prevItem; // delete previous item; newItems.insert(item->command(), item); menu_cache_item_unref(MENU_CACHE_ITEM(app)); } g_slist_free(apps); #else // use libqtxdg XdgMenu to get installed apps doUpdate(mXdgMenu->xml().documentElement(), newItems); #endif { QMutableListIterator<CommandProviderItem*> i(*this); while (i.hasNext()) { AppLinkItem *item = static_cast<AppLinkItem*>(i.next()); AppLinkItem *newItem = newItems.take(item->command()); if (newItem) { *(item) = *newItem; // Copy by value, not pointer! // After the item is copied, the original "updateIcon" call queued // on the newItem object is never called since the object iss going to // be deleted. Hence we need to call it on the copied item manually. // Otherwise the copied item will have no icon. // FIXME: this is a dirty hack and it should be made cleaner later. if(item->icon().isNull()) QMetaObject::invokeMethod(item, "updateIcon", Qt::QueuedConnection); delete newItem; } else { i.remove(); delete item; } } } { QHashIterator<QString, AppLinkItem*> i(newItems); while (i.hasNext()) { append(i.next().value()); } } emit changed(); }
void AppLinkProvider::update() { emit aboutToBeChanged(); QHash<QString, AppLinkItem*> newItems; doUpdate(mXdgMenu->xml().documentElement(), newItems); { QMutableListIterator<CommandProviderItem*> i(*this); while (i.hasNext()) { AppLinkItem *item = static_cast<AppLinkItem*>(i.next()); AppLinkItem *newItem = newItems.take(item->command()); if (newItem) { *(item) = *newItem; // Copy by value, not pointer! delete newItem; } else { i.remove(); delete item; } } } { QHashIterator<QString, AppLinkItem*> i(newItems); while (i.hasNext()) { append(i.next().value()); } } emit changed(); }
void doUpdate(const QDomElement &xml, QHash<QString, AppLinkItem*> &items) { DomElementIterator it(xml, ""); while (it.hasNext()) { QDomElement e = it.next(); // Build submenu ........................ if (e.tagName() == "Menu") doUpdate(e, items); //Build application link ................ else if (e.tagName() == "AppLink") { AppLinkItem *item = new AppLinkItem(e); delete items[item->command()]; // delete previous item; items.insert(item->command(), item); } } }