/****f* pekwm-menu/get_item_icon_path * OUTPUT * return the path for the themed icon if item. * If no icon found, it returns the "empty" icon path. * * The returned string should be freed when no longer needed * * NOTES * Imlib2, used by OpenBox to display icons, doesn't load SVG graphics. * We have to use GTK_ICON_LOOKUP_NO_SVG flag to look up icons. * * Notes * Pekwm uses libpng, libjpeg, and libXpm directly rather than Imlib2. * The net effect is the same, just a clarification. * * TODO * The "2nd fallback" is annoying, I have to think about this. ****/ gchar * get_item_icon_path (MenuCacheItem *item) { GtkIconInfo *icon_info = NULL; gchar *icon = NULL; gchar *tmp_name = NULL; /* type changed from gchar to const char due to removal of get_safe_name function - NF 2013-08-21 */ const gchar *name = menu_cache_item_get_icon (MENU_CACHE_ITEM(item)); if (name) { if (g_path_is_absolute (name)) return g_strdup (name); /* We remove the file extension as gtk_icon_theme_lookup_icon can't * lookup a theme icon for, ie, 'geany.png'. It has to be 'geany'. */ tmp_name = strndup (name, strrchr (name, '.') - name); /* Pekwm has no svg support so disabled svg ifdef code completely * NF 2013-08-29*/ icon_info = gtk_icon_theme_lookup_icon (icon_theme, tmp_name, 16, GTK_ICON_LOOKUP_NO_SVG | GTK_ICON_LOOKUP_GENERIC_FALLBACK); g_free (tmp_name); } if (!icon_info) /* 2nd fallback */ icon_info = gtk_icon_theme_lookup_icon (icon_theme, "empty", 16, GTK_ICON_LOOKUP_NO_SVG); icon = g_strdup (gtk_icon_info_get_filename (icon_info)); gtk_icon_info_free (icon_info); return icon; }
void XdgCachedMenuAction::updateIcon() { if(icon().isNull()) { QIcon icon = XdgIcon::fromTheme(menu_cache_item_get_icon(item_)); setIcon(icon); } }
/* called with lock held */ static void add_menu_items(GtkTreeIter* parent_it, MenuCacheDir* dir) { GtkTreeIter it; GSList * l; #if MENU_CACHE_CHECK_VERSION(0, 4, 0) GSList *list; #endif GIcon* gicon; /* Iterate over all menu items in this directory. */ #if MENU_CACHE_CHECK_VERSION(0, 4, 0) for (l = list = menu_cache_dir_list_children(dir); l != NULL; l = l->next) #else for (l = menu_cache_dir_get_children(dir); l != NULL; l = l->next) #endif { /* Get the menu item. */ MenuCacheItem* item = MENU_CACHE_ITEM(l->data); switch(menu_cache_item_get_type(item)) { case MENU_CACHE_TYPE_NONE: case MENU_CACHE_TYPE_SEP: break; case MENU_CACHE_TYPE_APP: case MENU_CACHE_TYPE_DIR: if(menu_cache_item_get_icon(item)) gicon = G_ICON(fm_icon_from_name(menu_cache_item_get_icon(item))); else gicon = NULL; gtk_tree_store_append(store, &it, parent_it); gtk_tree_store_set(store, &it, COL_ICON, gicon, COL_TITLE, menu_cache_item_get_name(item), COL_ITEM, item, -1); if(gicon) g_object_unref(gicon); if(menu_cache_item_get_type(item) == MENU_CACHE_TYPE_DIR) add_menu_items(&it, MENU_CACHE_DIR(item)); break; } } #if MENU_CACHE_CHECK_VERSION(0, 4, 0) g_slist_free_full(list, (GDestroyNotify)menu_cache_item_unref); #endif }
XdgCachedMenuAction::XdgCachedMenuAction(MenuCacheItem* item, QObject* parent): QAction(parent), item_(menu_cache_item_ref(item)) { QString title = QString::fromUtf8(menu_cache_item_get_name(item)); setText(title); // Only set tooltips for app items if(menu_cache_item_get_type(item) == MENU_CACHE_TYPE_APP) { QString comment = QString::fromUtf8(menu_cache_item_get_comment(item)); setToolTip(comment); } QIcon icon = XdgIcon::fromTheme(menu_cache_item_get_icon(item)); setIcon(icon); }
AppLinkItem::AppLinkItem(MenuCacheApp* app): CommandProviderItem() { MenuCacheItem* item = MENU_CACHE_ITEM(app); mIconName = QString::fromUtf8(menu_cache_item_get_icon(item)); mTitle = QString::fromUtf8(menu_cache_item_get_name(item)); mComment = QString::fromUtf8(menu_cache_item_get_comment(item)); mToolTip = mComment; mCommand = menu_cache_app_get_exec(app); mProgram = QFileInfo(mCommand).baseName().section(" ", 0, 0); char* path = menu_cache_item_get_file_path(MENU_CACHE_ITEM(app)); mDesktopFile = QString::fromLocal8Bit(path); g_free(path); QMetaObject::invokeMethod(this, "updateIcon", Qt::QueuedConnection); // qDebug() << "FOUND: " << mIconName << ", " << mCommand; }
static void add_menu_items(GtkTreeIter* parent_it, MenuCacheDir* dir) { GtkTreeIter it; GSList * l; GIcon* gicon; /* Iterate over all menu items in this directory. */ for (l = menu_cache_dir_get_children(dir); l != NULL; l = l->next) { /* Get the menu item. */ MenuCacheItem* item = MENU_CACHE_ITEM(l->data); switch(menu_cache_item_get_type(item)) { case MENU_CACHE_TYPE_NONE: case MENU_CACHE_TYPE_SEP: break; case MENU_CACHE_TYPE_APP: case MENU_CACHE_TYPE_DIR: if(menu_cache_item_get_icon(item)) { if(g_path_is_absolute(menu_cache_item_get_icon(item))) { GFile* gf = g_file_new_for_path(menu_cache_item_get_icon(item)); gicon = g_file_icon_new(gf); g_object_unref(gf); } else { char* dot = strrchr((char*)menu_cache_item_get_icon(item), '.'); if(dot && (strcmp(dot+1, "png") == 0 || strcmp(dot+1, "svg") == 0 || strcmp(dot+1, "xpm") == 0)) { char* name = g_strndup(menu_cache_item_get_icon(item), dot - menu_cache_item_get_icon(item)); gicon = g_themed_icon_new(name); g_free(name); } else gicon = g_themed_icon_new(menu_cache_item_get_icon(item)); } } else gicon = NULL; gtk_tree_store_append(store, &it, parent_it); gtk_tree_store_set(store, &it, COL_ICON, gicon, COL_TITLE, menu_cache_item_get_name(item), COL_ITEM, item, -1); if(gicon) g_object_unref(gicon); if(menu_cache_item_get_type(item) == MENU_CACHE_TYPE_DIR) add_menu_items(&it, MENU_CACHE_DIR(item)); break; } } }
static void on_entry_changed( GtkEntry* entry, GtkImage* img ) { const char* str = gtk_entry_get_text(entry); MenuCacheApp* app = NULL; if( str && *str ) app = match_app_by_exec(str); if( app ) { int w, h; GdkPixbuf* pix; gtk_icon_size_lookup(GTK_ICON_SIZE_DIALOG, &w, &h); pix = lxpanel_load_icon(menu_cache_item_get_icon(MENU_CACHE_ITEM(app)), w, h, TRUE); gtk_image_set_from_pixbuf(img, pix); g_object_unref(pix); } else { gtk_image_set_from_stock(img, GTK_STOCK_EXECUTE, GTK_ICON_SIZE_DIALOG); } }