static void add_entry(GMenuTreeEntry *entry, const char *path, GSList**p) { GSList* data = *p; char *utf8_path; char *utf8_file_id; Menu_list_item * item; gchar * file_name; utf8_path = g_filename_to_utf8(gmenu_tree_entry_get_desktop_file_path(entry), -1, NULL, NULL, NULL); utf8_file_id = g_filename_to_utf8(gmenu_tree_entry_get_desktop_file_id(entry), -1, NULL, NULL, NULL); file_name = utf8_path ? utf8_path : _("[Invalid Filename]"); item = g_malloc(sizeof(Menu_list_item)); item->item_type = MENU_ITEM_ENTRY; item->name = gmenu_tree_entry_get_name(entry); item->icon = gmenu_tree_entry_get_icon(entry); item->exec = gmenu_tree_entry_get_exec(entry); char *str = item->exec; while (*str) { if (*str == '%') { *str = ' '; if (*(str + 1)) { str++; *str = ' '; } } str++; } item->comment = gmenu_tree_entry_get_comment(entry); item->launch_in_terminal = gmenu_tree_entry_get_launch_in_terminal(entry); item->desktop = g_strdup(file_name); data = g_slist_append(data, item); *p = data; g_free(utf8_file_id); g_free(utf8_path); }
char * shell_app_info_get_description (ShellAppInfo *info) { switch (info->type) { case SHELL_APP_INFO_TYPE_ENTRY: return g_strdup (gmenu_tree_entry_get_comment ((GMenuTreeEntry*)info->entry)); case SHELL_APP_INFO_TYPE_DESKTOP_FILE: return g_key_file_get_locale_string (info->keyfile, DESKTOP_ENTRY_GROUP, "Comment", NULL, NULL); case SHELL_APP_INFO_TYPE_WINDOW: return NULL; } g_assert_not_reached (); return NULL; }
static void shell_app_info_init_search_data (ShellAppInfo *info) { const char *name; const char *exec; const char *comment; char *normalized_exec; g_assert (info->type == SHELL_APP_INFO_TYPE_ENTRY); name = gmenu_tree_entry_get_name ((GMenuTreeEntry*)info->entry); info->casefolded_name = normalize_and_casefold (name); comment = gmenu_tree_entry_get_comment ((GMenuTreeEntry*)info->entry); info->casefolded_description = normalize_and_casefold (comment); exec = gmenu_tree_entry_get_exec ((GMenuTreeEntry*)info->entry); normalized_exec = normalize_and_casefold (exec); info->casefolded_exec = trim_exec_line (normalized_exec); g_free (normalized_exec); }
void slingshot_backend_gmenu_entries_enumerate_apps (GeeArrayList* source, GeeHashMap* icons, gint icon_size, GeeArrayList** list) { GeeArrayList* _vala_list = NULL; GtkIconTheme* _tmp0_ = NULL; GtkIconTheme* _tmp1_; GtkIconTheme* icon_theme; GeeArrayList* _tmp2_; GError * _inner_error_ = NULL; g_return_if_fail (source != NULL); g_return_if_fail (icons != NULL); _tmp0_ = gtk_icon_theme_get_default (); _tmp1_ = _g_object_ref0 (_tmp0_); icon_theme = _tmp1_; _tmp2_ = gee_array_list_new (GEE_TYPE_HASH_MAP, (GBoxedCopyFunc) g_object_ref, g_object_unref, NULL); _g_object_unref0 (_vala_list); _vala_list = _tmp2_; { GeeArrayList* _tmp3_; GeeArrayList* _tmp4_; GeeArrayList* _app_list; GeeArrayList* _tmp5_; gint _tmp6_; gint _tmp7_; gint _app_size; gint _app_index; _tmp3_ = source; _tmp4_ = _g_object_ref0 (_tmp3_); _app_list = _tmp4_; _tmp5_ = _app_list; _tmp6_ = gee_abstract_collection_get_size ((GeeCollection*) _tmp5_); _tmp7_ = _tmp6_; _app_size = _tmp7_; _app_index = -1; while (TRUE) { gint _tmp8_; gint _tmp9_; gint _tmp10_; GeeArrayList* _tmp11_; gint _tmp12_; gpointer _tmp13_ = NULL; GMenuTreeEntry* app; gboolean _tmp14_ = FALSE; gboolean _tmp15_ = FALSE; GMenuTreeEntry* _tmp16_; gboolean _tmp17_ = FALSE; gboolean _tmp20_; gboolean _tmp23_; _tmp8_ = _app_index; _app_index = _tmp8_ + 1; _tmp9_ = _app_index; _tmp10_ = _app_size; if (!(_tmp9_ < _tmp10_)) { break; } _tmp11_ = _app_list; _tmp12_ = _app_index; _tmp13_ = gee_abstract_list_get ((GeeAbstractList*) _tmp11_, _tmp12_); app = (GMenuTreeEntry*) _tmp13_; _tmp16_ = app; _tmp17_ = gmenu_tree_entry_get_is_nodisplay (_tmp16_); if (_tmp17_ == FALSE) { GMenuTreeEntry* _tmp18_; gboolean _tmp19_ = FALSE; _tmp18_ = app; _tmp19_ = gmenu_tree_entry_get_is_excluded (_tmp18_); _tmp15_ = _tmp19_ == FALSE; } else { _tmp15_ = FALSE; } _tmp20_ = _tmp15_; if (_tmp20_) { GMenuTreeEntry* _tmp21_; const gchar* _tmp22_ = NULL; _tmp21_ = app; _tmp22_ = gmenu_tree_entry_get_icon (_tmp21_); _tmp14_ = _tmp22_ != NULL; } else { _tmp14_ = FALSE; } _tmp23_ = _tmp14_; if (_tmp23_) { GeeHashMap* _tmp24_; GeeHashMap* app_to_add; GeeHashMap* _tmp25_; GMenuTreeEntry* _tmp26_; const gchar* _tmp27_ = NULL; GeeHashMap* _tmp28_; GMenuTreeEntry* _tmp29_; const gchar* _tmp30_ = NULL; GeeHashMap* _tmp31_; GMenuTreeEntry* _tmp32_; const gchar* _tmp33_ = NULL; GeeHashMap* _tmp34_; GMenuTreeEntry* _tmp35_; const gchar* _tmp36_ = NULL; GeeHashMap* _tmp37_; GeeHashMap* _tmp38_; gpointer _tmp39_ = NULL; gchar* _tmp40_; gboolean _tmp41_ = FALSE; gboolean _tmp42_; GeeArrayList* _tmp102_; GeeHashMap* _tmp103_; _tmp24_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, NULL, NULL, NULL); app_to_add = _tmp24_; _tmp25_ = app_to_add; _tmp26_ = app; _tmp27_ = gmenu_tree_entry_get_comment (_tmp26_); gee_abstract_map_set ((GeeAbstractMap*) _tmp25_, "description", _tmp27_); _tmp28_ = app_to_add; _tmp29_ = app; _tmp30_ = gmenu_tree_entry_get_name (_tmp29_); gee_abstract_map_set ((GeeAbstractMap*) _tmp28_, "name", _tmp30_); _tmp31_ = app_to_add; _tmp32_ = app; _tmp33_ = gmenu_tree_entry_get_exec (_tmp32_); gee_abstract_map_set ((GeeAbstractMap*) _tmp31_, "command", _tmp33_); _tmp34_ = app_to_add; _tmp35_ = app; _tmp36_ = gmenu_tree_entry_get_desktop_file_path (_tmp35_); gee_abstract_map_set ((GeeAbstractMap*) _tmp34_, "desktop_file", _tmp36_); _tmp37_ = icons; _tmp38_ = app_to_add; _tmp39_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp38_, "command"); _tmp40_ = (gchar*) _tmp39_; _tmp41_ = gee_abstract_map_has_key ((GeeAbstractMap*) _tmp37_, _tmp40_); _tmp42_ = !_tmp41_; _g_free0 (_tmp40_); if (_tmp42_) { GMenuTreeEntry* _tmp43_; const gchar* _tmp44_ = NULL; gchar* _tmp45_; gchar* app_icon; GtkIconTheme* _tmp46_; const gchar* _tmp47_; gboolean _tmp48_ = FALSE; _tmp43_ = app; _tmp44_ = gmenu_tree_entry_get_icon (_tmp43_); _tmp45_ = g_strdup (_tmp44_); app_icon = _tmp45_; _tmp46_ = icon_theme; _tmp47_ = app_icon; _tmp48_ = gtk_icon_theme_has_icon (_tmp46_, _tmp47_); if (_tmp48_) { GtkIconTheme* _tmp49_; const gchar* _tmp50_; gint _tmp51_; GtkIconInfo* _tmp52_ = NULL; GtkIconInfo* _tmp53_; GdkPixbuf* _tmp54_ = NULL; GdkPixbuf* _tmp55_; GdkPixbuf* _tmp56_; GeeHashMap* _tmp57_; GeeHashMap* _tmp58_; gpointer _tmp59_ = NULL; gchar* _tmp60_; GdkPixbuf* _tmp61_; _tmp49_ = icon_theme; _tmp50_ = app_icon; _tmp51_ = icon_size; _tmp52_ = gtk_icon_theme_lookup_icon (_tmp49_, _tmp50_, _tmp51_, 0); _tmp53_ = _tmp52_; _tmp54_ = gtk_icon_info_load_icon (_tmp53_, &_inner_error_); _tmp55_ = _tmp54_; _gtk_icon_info_free0 (_tmp53_); _tmp56_ = _tmp55_; if (_inner_error_ != NULL) { _g_free0 (app_icon); _g_object_unref0 (app_to_add); _gmenu_tree_item_unref0 (app); _g_object_unref0 (_app_list); _g_object_unref0 (icon_theme); g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return; } _tmp57_ = icons; _tmp58_ = app_to_add; _tmp59_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp58_, "command"); _tmp60_ = (gchar*) _tmp59_; _tmp61_ = _tmp56_; gee_abstract_map_set ((GeeAbstractMap*) _tmp57_, _tmp60_, _tmp61_); _g_object_unref0 (_tmp61_); _g_free0 (_tmp60_); } else { const gchar* _tmp62_; GFile* _tmp63_ = NULL; GFile* _tmp64_; gboolean _tmp65_ = FALSE; gboolean _tmp66_; _tmp62_ = app_icon; _tmp63_ = g_file_new_for_path (_tmp62_); _tmp64_ = _tmp63_; _tmp65_ = g_file_query_exists (_tmp64_, NULL); _tmp66_ = _tmp65_; _g_object_unref0 (_tmp64_); if (_tmp66_) { { const gchar* _tmp67_; const gchar* _tmp68_ = NULL; gint _tmp69_; GdkPixbuf* _tmp70_; GdkPixbuf* _tmp71_; GeeHashMap* _tmp72_; GeeHashMap* _tmp73_; gpointer _tmp74_ = NULL; gchar* _tmp75_; GdkPixbuf* _tmp76_; _tmp67_ = app_icon; _tmp68_ = string_to_string (_tmp67_); _tmp69_ = icon_size; _tmp70_ = gdk_pixbuf_new_from_file_at_scale (_tmp68_, -1, _tmp69_, TRUE, &_inner_error_); _tmp71_ = _tmp70_; if (_inner_error_ != NULL) { goto __catch1_g_error; } _tmp72_ = icons; _tmp73_ = app_to_add; _tmp74_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp73_, "command"); _tmp75_ = (gchar*) _tmp74_; _tmp76_ = _tmp71_; gee_abstract_map_set ((GeeAbstractMap*) _tmp72_, _tmp75_, _tmp76_); _g_object_unref0 (_tmp76_); _g_free0 (_tmp75_); } goto __finally1; __catch1_g_error: { GtkIconTheme* _tmp77_; gint _tmp78_; GtkIconInfo* _tmp79_ = NULL; GtkIconInfo* _tmp80_; GdkPixbuf* _tmp81_ = NULL; GdkPixbuf* _tmp82_; GdkPixbuf* _tmp83_; GeeHashMap* _tmp84_; GeeHashMap* _tmp85_; gpointer _tmp86_ = NULL; gchar* _tmp87_; GdkPixbuf* _tmp88_; FILE* _tmp89_; g_clear_error (&_inner_error_); _inner_error_ = NULL; _tmp77_ = icon_theme; _tmp78_ = icon_size; _tmp79_ = gtk_icon_theme_lookup_icon (_tmp77_, "application-default-icon", _tmp78_, 0); _tmp80_ = _tmp79_; _tmp81_ = gtk_icon_info_load_icon (_tmp80_, &_inner_error_); _tmp82_ = _tmp81_; _gtk_icon_info_free0 (_tmp80_); _tmp83_ = _tmp82_; if (_inner_error_ != NULL) { goto __finally1; } _tmp84_ = icons; _tmp85_ = app_to_add; _tmp86_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp85_, "command"); _tmp87_ = (gchar*) _tmp86_; _tmp88_ = _tmp83_; gee_abstract_map_set ((GeeAbstractMap*) _tmp84_, _tmp87_, _tmp88_); _g_object_unref0 (_tmp88_); _g_free0 (_tmp87_); _tmp89_ = stdout; fprintf (_tmp89_, "Failed to load icon from file.\n"); } __finally1: if (_inner_error_ != NULL) { _g_free0 (app_icon); _g_object_unref0 (app_to_add); _gmenu_tree_item_unref0 (app); _g_object_unref0 (_app_list); _g_object_unref0 (icon_theme); g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return; } } else { GtkIconTheme* _tmp90_; gint _tmp91_; GtkIconInfo* _tmp92_ = NULL; GtkIconInfo* _tmp93_; GdkPixbuf* _tmp94_ = NULL; GdkPixbuf* _tmp95_; GdkPixbuf* _tmp96_; GeeHashMap* _tmp97_; GeeHashMap* _tmp98_; gpointer _tmp99_ = NULL; gchar* _tmp100_; GdkPixbuf* _tmp101_; _tmp90_ = icon_theme; _tmp91_ = icon_size; _tmp92_ = gtk_icon_theme_lookup_icon (_tmp90_, "application-default-icon", _tmp91_, 0); _tmp93_ = _tmp92_; _tmp94_ = gtk_icon_info_load_icon (_tmp93_, &_inner_error_); _tmp95_ = _tmp94_; _gtk_icon_info_free0 (_tmp93_); _tmp96_ = _tmp95_; if (_inner_error_ != NULL) { _g_free0 (app_icon); _g_object_unref0 (app_to_add); _gmenu_tree_item_unref0 (app); _g_object_unref0 (_app_list); _g_object_unref0 (icon_theme); g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return; } _tmp97_ = icons; _tmp98_ = app_to_add; _tmp99_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp98_, "command"); _tmp100_ = (gchar*) _tmp99_; _tmp101_ = _tmp96_; gee_abstract_map_set ((GeeAbstractMap*) _tmp97_, _tmp100_, _tmp101_); _g_object_unref0 (_tmp101_); _g_free0 (_tmp100_); } } _g_free0 (app_icon); } _tmp102_ = _vala_list; _tmp103_ = app_to_add; gee_abstract_collection_add ((GeeAbstractCollection*) _tmp102_, _tmp103_); _g_object_unref0 (app_to_add); } _gmenu_tree_item_unref0 (app); } _g_object_unref0 (_app_list); } _g_object_unref0 (icon_theme); if (list) { *list = _vala_list; } else { _g_object_unref0 (_vala_list); } }
/*! \fn gboolean CDesktopAppChooser::m_AddAppsMenuLeafNode(GMenuTreeDirectory *appsDir) \brief To create leaf nodes(applications). \param[in] appsDir \return TRUE or FALSE */ gboolean CDesktopAppChooser::m_AddAppsMenuLeafNode(GMenuTreeDirectory *appsDir) { GSList *itemList = NULL; if( G_UNLIKELY(!appsDir) ) return false; for( itemList = gmenu_tree_directory_get_contents(appsDir); itemList; itemList = itemList->next ) { GMenuTreeItem *item = (GMenuTreeItem*)itemList->data; GMenuTreeItemType type = gmenu_tree_item_get_type(item); if( type == GMENU_TREE_ITEM_DIRECTORY ) { /* To pars sub-directory items and add it to the menu tree. Here using recursive parse. */ m_AddAppsMenuLeafNode( (GMenuTreeDirectory*)item ); } else if( type == GMENU_TREE_ITEM_ENTRY ) { GdkPixbuf *pixbuf = NULL; const gchar *icon_name = gmenu_tree_entry_get_icon( (GMenuTreeEntry*)item ); APP_ITEM_INFO *appInfo = NULL; /* To determine if the current item need not to be shown. If it is, continue. */ if(gmenu_tree_entry_get_is_nodisplay( (GMenuTreeEntry*)item ) || gmenu_tree_entry_get_is_excluded( (GMenuTreeEntry*)item ) ) continue; /* To create the icon for the currently read node. */ if(icon_name) pixbuf = m_LoadIcon(icon_name, IMG_SIZE, TRUE ); else pixbuf = m_LoadIcon(DEFAULT_APP__MIME_ICON, IMG_SIZE, TRUE ); // If there has no icon name in .desktop file, using the system default icon for application. /* To create a object containing information about current leaf node. */ appInfo = new APP_ITEM_INFO ; /* Zero out the new allocated memory. */ memset(appInfo, 0x00, sizeof(APP_ITEM_INFO)); if(appInfo) { gchar *name = (gchar*)gmenu_tree_entry_get_name( (GMenuTreeEntry*)item ) ; gchar *exec = (gchar*)gmenu_tree_entry_get_exec( (GMenuTreeEntry*)item ); gchar *comment = (gchar*)gmenu_tree_entry_get_comment( (GMenuTreeEntry*)item ); #if 1 gchar *desktopfile = (gchar*)gmenu_tree_entry_get_desktop_file_path( (GMenuTreeEntry*)item ); #else gchar *desktopfile = (gchar*)gmenu_tree_entry_get_desktop_file_id( (GMenuTreeEntry*)item ); #endif if(name) appInfo->name = (gchar*)g_strdup(name); if(icon_name) appInfo->icon = (gchar*)g_strdup(icon_name); if(exec) appInfo->exec = (gchar*)g_strdup(exec); if(comment) appInfo->comment = (gchar*)g_strdup(comment); if(desktopfile) appInfo->desktopfile = (gchar*)g_strdup(desktopfile); } /* Add a tree leaf. */ gtk_tree_store_append(m_TreeStore, &m_ChildNodeIter, &m_TopLevelNodeIter); gtk_tree_store_set(m_TreeStore, &m_ChildNodeIter, COLUMN_ICON, pixbuf, COLUMN_TEXT, gmenu_tree_entry_get_name( (GMenuTreeEntry*)item ), COLUMN_NODEDATA, appInfo, -1); /* pixbuf has a referece count of "1" now, as the tree store has added its own reference. So to decrease the reference count of pixbuf. */ g_object_unref(pixbuf); } } // The end of for() return true; }
static void write_entry( FILE* of, GMenuTreeEntry* item ) { const char* cstr; char* str; int flags = 0; // if( gmenu_tree_entry_get_is_nodisplay(item) /* || gmenu_tree_entry_get_is_excluded(item) */ ) // return; /* dekstop id, not necessarily the same as file basename */ fprintf( of, "-%s\n", gmenu_tree_entry_get_desktop_file_id( item ) ); /* Name */ fprintf( of, "%s\n", gmenu_tree_entry_get_name( item ) ); /* Comment */ cstr = gmenu_tree_entry_get_comment( item ); fprintf( of, "%s\n", cstr ? cstr : "" ); /* Icon */ cstr = gmenu_tree_entry_get_icon( item ); fprintf( of, "%s\n", cstr ? cstr : "" ); /* file dir/basename */ if( gmenu_tree_entry_get_desktop_file_path( item ) ) { /* file basenames are the same as desktop ids, except that sometimes * the '/' in paths are replaced with '-'. * for ex, /usr/share/applications/foo/bar.desktop has the app dir * /usr/share/applications, the filename foo/bar.desltop, and the * desktop id: foo-bar.desktop */ /* filename */ str = g_path_get_basename( gmenu_tree_entry_get_desktop_file_path( item ) ); if( strcmp(str, gmenu_tree_entry_get_desktop_file_id(item) ) ) fprintf( of, "%s\n", str ); else fprintf( of, "\n" ); g_free( str ); /* dirname */ str = g_path_get_dirname( gmenu_tree_entry_get_desktop_file_path( item ) ); fprintf( of, "%d\n", dirname_index( str) ); g_free( str ); } else { fprintf( of, "\n-1\n" ); } /* DisplayName */ cstr = gmenu_tree_entry_get_display_name( item ); fprintf( of, "%s\n", cstr ? cstr : "" ); /* Exec */ fprintf( of, "%s\n", gmenu_tree_entry_get_exec( item ) ); /* Terminal/StartupNotify flags */ if( gmenu_tree_entry_get_launch_in_terminal( item ) ) flags |= FLAG_USE_TERMINAL; if( gmenu_tree_entry_get_use_startup_notify( item ) ) flags |= FLAG_USE_SN; if( gmenu_tree_entry_get_is_nodisplay( item ) ) flags |= FLAG_IS_NODISPLAY; fprintf( of, "%u\n", flags ); /* ShowIn info */ fprintf( of, "%d\n", gmenu_tree_entry_get_show_in_flags(item) ); /* if( gmenu_tree_entry_get_desktop_file_path( item ) ) write_item_ex_info(of, gmenu_tree_entry_get_desktop_file_path( item )); fputs( "\n", of ); */ }