PRIVATE JSObjectRef _init_category_table() { JSObjectRef items = json_array_create(); GList* app_infos = g_app_info_get_all(); GList* iter = app_infos; for (gsize i=0, skip=0; iter != NULL; i++, iter = g_list_next(iter)) { GAppInfo* info = iter->data; if (!g_app_info_should_show(info)) { skip++; continue; } record_category_info(G_DESKTOP_APP_INFO(info)); json_array_insert_nobject(items, i - skip, info, g_object_ref, g_object_unref); g_object_unref(info); } g_list_free(app_infos); //the element of GAppInfo should free by JSRunTime not here! return items; }
GAppInfo * problem_create_app_from_cmdline (const char *cmdline) { GAppInfo *app; GList *apps, *l; GList *shortlist; char *binary; char **cmdargs; binary = problem_get_argv0(cmdline); apps = g_app_info_get_all (); shortlist = NULL; app = NULL; for (l = apps; l != NULL; l = l->next) { GAppInfo *a = l->data; if (!g_app_info_should_show(a)) continue; if (!compare_binaries (binary, g_app_info_get_executable (a))) continue; shortlist = g_list_prepend (shortlist, a); } if (shortlist == NULL) { g_list_free_full (apps, g_object_unref); return NULL; } cmdargs = g_strsplit (cmdline, " ", -1); remove_quotes (cmdargs); for (l = shortlist; l != NULL; l = l->next) { GAppInfo *a = l->data; char **dcmdargs; const char *commandline = g_app_info_get_commandline (a); if (commandline == NULL) continue; dcmdargs = g_strsplit (commandline, " ", -1); remove_quotes (dcmdargs); if (compare_args (cmdargs, dcmdargs)) app = g_object_ref (a); g_strfreev (dcmdargs); if (app != NULL) break; } g_list_free (shortlist); g_list_free_full (apps, g_object_unref); return app; }
void _cinnamon_app_do_match (CinnamonApp *app, GSList *terms, GSList **prefix_results, GSList **substring_results) { CinnamonAppSearchMatch match; GAppInfo *appinfo; g_assert (app != NULL); /* Skip window-backed apps */ appinfo = (GAppInfo*)cinnamon_app_get_app_info (app); if (appinfo == NULL) return; /* Skip not-visible apps */ if (!g_app_info_should_show (appinfo)) return; match = _cinnamon_app_match_search_terms (app, terms); switch (match) { case MATCH_NONE: break; case MATCH_PREFIX: *prefix_results = g_slist_prepend (*prefix_results, app); break; case MATCH_SUBSTRING: *substring_results = g_slist_prepend (*substring_results, app); break; } }
/** * pk_plugin_sqlite_add_filename_details: **/ static gint pk_plugin_sqlite_add_filename_details (PkPlugin *plugin, const gchar *filename, const gchar *package, const gchar *md5) { gchar *statement; gchar *error_msg = NULL; sqlite3_stmt *sql_statement = NULL; gint rc = -1; gint show; GDesktopAppInfo *info; /* find out if we should show desktop file in menus */ info = g_desktop_app_info_new_from_filename (filename); if (info == NULL) { g_warning ("could not load desktop file %s", filename); goto out; } show = g_app_info_should_show (G_APP_INFO (info)); g_object_unref (info); g_debug ("add filename %s from %s with md5: %s (show: %i)", filename, package, md5, show); /* the row might already exist */ statement = g_strdup_printf ("DELETE FROM cache WHERE filename = '%s'", filename); sqlite3_exec (plugin->priv->db, statement, NULL, NULL, NULL); g_free (statement); /* prepare the query, as we don't escape it */ rc = sqlite3_prepare_v2 (plugin->priv->db, "INSERT INTO cache (filename, package, show, md5) " "VALUES (?, ?, ?, ?)", -1, &sql_statement, NULL); if (rc != SQLITE_OK) { g_warning ("SQL failed to prepare: %s", sqlite3_errmsg (plugin->priv->db)); goto out; } /* add data */ sqlite3_bind_text (sql_statement, 1, filename, -1, SQLITE_STATIC); sqlite3_bind_text (sql_statement, 2, package, -1, SQLITE_STATIC); sqlite3_bind_int (sql_statement, 3, show); sqlite3_bind_text (sql_statement, 4, md5, -1, SQLITE_STATIC); /* save this */ sqlite3_step (sql_statement); rc = sqlite3_finalize (sql_statement); if (rc != SQLITE_OK) { g_warning ("SQL error: %s\n", error_msg); sqlite3_free (error_msg); goto out; } out: return rc; }
static GList * xde_entry(MenuContext *ctx, GMenuTreeEntry *ent) { GDesktopAppInfo *info; GList *text = NULL, *acts; const char *name; char *esc1, *esc2, *cmd, *p; char *s, *icon = NULL; GIcon *gicon = NULL; char *appid; if (!(info = gmenu_tree_entry_get_app_info(ent)) || g_desktop_app_info_get_is_hidden(info) || g_desktop_app_info_get_nodisplay(info) || !g_desktop_app_info_get_show_in(info, NULL) || !g_app_info_should_show(G_APP_INFO(info))) return (text); name = g_app_info_get_name(G_APP_INFO(info)); esc1 = xde_character_escape(name, ')'); if ((appid = strdup(gmenu_tree_entry_get_desktop_file_id(ent))) && (p = strstr(appid, ".desktop"))) *p = '\0'; if (ctx->stack) gicon = gmenu_tree_directory_get_icon(ctx->stack->data); icon = xde_get_app_icon(ctx, info, gicon, "exec", "unknown", GET_ENTRY_ICON_FLAG_XPM | GET_ENTRY_ICON_FLAG_PNG | GET_ENTRY_ICON_FLAG_JPG | GET_ENTRY_ICON_FLAG_SVG); if (options.launch) { cmd = g_strdup_printf("xdg-launch --pointer %s", appid); } else { cmd = xde_get_command(info, appid, icon); } esc2 = xde_character_escape(cmd, '}'); icon = ctx->wmm.wrap(ctx, icon); if (options.actions && (acts = ctx->wmm.ops.actions(ctx, ent, info))) { xde_increase_indent(ctx); s = g_strdup_printf("%s[exec] (%s) {%s}%s\n", ctx->indent, esc1, esc2, icon); xde_decrease_indent(ctx); acts = g_list_prepend(acts, s); s = g_strdup_printf("%s[submenu] (%s) {%s}%s\n", ctx->indent, esc1, esc1, icon); acts = g_list_prepend(acts, s); s = g_strdup_printf("%s[end]\n", ctx->indent); acts = g_list_append(acts, s); text = g_list_concat(text, acts); } else { s = g_strdup_printf("%s[exec] (%s) {%s}%s\n", ctx->indent, esc1, esc2, icon); text = g_list_append(text, s); } free(icon); free(appid); free(esc1); free(esc2); free(cmd); return (text); }
void egg_app_info_model_changed (GAppInfoMonitor *monitor, gpointer user_data) { EggKeyedListStore *store = user_data; GHashTable *old_app_ids; GList *new_apps; GList *it; guint n_items; gint i; GHashTableIter iter; const gchar *id; old_app_ids = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref); n_items = g_list_model_get_n_items (G_LIST_MODEL (store)); for (i = 0; i < n_items; i++) { GAppInfo *info; info = g_list_model_get_item (G_LIST_MODEL (store), i); g_hash_table_insert (old_app_ids, (gpointer) g_app_info_get_id (info), info); } new_apps = g_app_info_get_all (); for (it = new_apps; it; it = it->next) { GAppInfo *info = it->data; if (!g_app_info_should_show (info)) continue; id = g_app_info_get_id (info); /* only add the application if we didn't have it before */ if (!g_hash_table_remove (old_app_ids, id)) egg_keyed_list_store_insert (store, id, info); } /* remove app ids that aren't in new_apps */ g_hash_table_iter_init (&iter, old_app_ids); while (g_hash_table_iter_next (&iter, (gpointer) &id, NULL)) egg_keyed_list_store_remove (store, id); g_list_free_full (new_apps, g_object_unref); g_hash_table_destroy (old_app_ids); }
static GList * xde_entry(MenuContext *ctx, GMenuTreeEntry *ent) { GDesktopAppInfo *info; GList *text = NULL; const char *name; char *esc1, *qname, *esc2, *cmd, *p; char *s, *icon = NULL; GIcon *gicon = NULL; char *appid; if (!(info = gmenu_tree_entry_get_app_info(ent)) || g_desktop_app_info_get_is_hidden(info) || g_desktop_app_info_get_nodisplay(info) || !g_desktop_app_info_get_show_in(info, NULL) || !g_app_info_should_show(G_APP_INFO(info))) return (text); name = g_app_info_get_name(G_APP_INFO(info)); esc1 = xde_character_escape(name, '"'); qname = g_strdup_printf("\"%s\"", esc1); if ((appid = strdup(gmenu_tree_entry_get_desktop_file_id(ent))) && (p = strstr(appid, ".desktop"))) *p = '\0'; if (ctx->stack) gicon = gmenu_tree_directory_get_icon(ctx->stack->data); icon = xde_get_app_icon(ctx, info, gicon, "exec", "unknown", GET_ENTRY_ICON_FLAG_XPM | GET_ENTRY_ICON_FLAG_PNG | GET_ENTRY_ICON_FLAG_JPG | GET_ENTRY_ICON_FLAG_SVG); if (options.launch) { cmd = g_strdup_printf("xdg-launch --pointer %s", appid); } else { cmd = xde_get_command(info, appid, icon); } esc2 = xde_character_escape(cmd, '"'); s = g_strdup_printf(" %-32s f.exec \"exec %s &\"\n", qname, esc2); text = g_list_append(text, s); free(icon); free(appid); g_free(qname); free(esc1); free(esc2); free(cmd); return (text); }
static GList * xde_entry(MenuContext *ctx, GMenuTreeEntry *ent) { GDesktopAppInfo *info; GList *text = NULL; const char *name; char *esc1, *esc2, *cmd, *p; char *icon = NULL, *wrap, *s; GIcon *gicon = NULL; gboolean notify; char *wmclass, *appid; if (!(info = gmenu_tree_entry_get_app_info(ent)) || g_desktop_app_info_get_is_hidden(info) || g_desktop_app_info_get_nodisplay(info) || !g_desktop_app_info_get_show_in(info, NULL) || !g_app_info_should_show(G_APP_INFO(info))) return (text); name = g_app_info_get_name(G_APP_INFO(info)); esc1 = g_markup_escape_text(name, -1); if (ctx->stack) gicon = gmenu_tree_directory_get_icon(ctx->stack->data); icon = xde_get_app_icon(ctx, info, gicon, "exec", "unknown", GET_ENTRY_ICON_FLAG_XPM | GET_ENTRY_ICON_FLAG_PNG | GET_ENTRY_ICON_FLAG_JPG | GET_ENTRY_ICON_FLAG_SVG); wrap = ctx->wmm.wrap(ctx, strdup(icon)); notify = g_desktop_app_info_get_boolean(info, G_KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY); wmclass = g_desktop_app_info_get_string(info, G_KEY_FILE_DESKTOP_KEY_STARTUP_WM_CLASS); if ((appid = strdup(gmenu_tree_entry_get_desktop_file_id(ent))) && (p = strstr(appid, ".desktop"))) *p = '\0'; if (options.launch) { cmd = g_strdup_printf("xdg-launch --pointer %s", appid); } else { cmd = xde_get_command(info, appid, icon); } esc2 = g_markup_escape_text(cmd, -1); s = g_strdup_printf("%s<item label=\"%s\"%s>\n", ctx->indent, esc1, wrap); text = g_list_append(text, s); s = g_strdup_printf("%s <action name=\"Execute\">\n", ctx->indent); text = g_list_append(text, s); s = g_strdup_printf("%s <command>%s</command>\n", ctx->indent, esc2); text = g_list_append(text, s); if (!options.launch && (notify || wmclass)) { /* don't put launch specifics if we are launching with xdg-launch */ s = g_strdup_printf("%s <startupnotify>\n", ctx->indent); text = g_list_append(text, s); if (notify) { s = g_strdup_printf("%s <enabled>yes</enabled>\n", ctx->indent); text = g_list_append(text, s); } if (wmclass) { s = g_strdup_printf("%s <wmclass>%s</wmclass>\n", ctx->indent, wmclass); text = g_list_append(text, s); } s = g_strdup_printf("%s <name>%s</name>\n", ctx->indent, esc1); text = g_list_append(text, s); if (icon) { s = g_strdup_printf("%s <icon>%s</icon>\n", ctx->indent, icon); text = g_list_append(text, s); } s = g_strdup_printf("%s </startupnotify>\n", ctx->indent); text = g_list_append(text, s); } s = g_strdup_printf("%s </action>\n", ctx->indent); text = g_list_append(text, s); s = g_strdup_printf("%s</item>\n", ctx->indent); text = g_list_append(text, s); free(wrap); free(icon); g_free(wmclass); free(appid); g_free(esc1); g_free(esc2); free(cmd); return (text); }
static VALUE appinfo_should_show(VALUE self) { return CBOOL2RVAL(g_app_info_should_show(_SELF(self))); }
static gboolean gtk_app_chooser_widget_add_section (GtkAppChooserWidget *self, const gchar *heading_title, gboolean show_headings, gboolean recommended, gboolean fallback, GList *applications, GList *exclude_apps) { gboolean heading_added, unref_icon; GtkTreeIter iter; GAppInfo *app; gchar *app_string, *bold_string; GIcon *icon; GList *l; gboolean retval; retval = FALSE; heading_added = FALSE; bold_string = g_strdup_printf ("<b>%s</b>", heading_title); for (l = applications; l != NULL; l = l->next) { app = l->data; if (!g_app_info_supports_uris (app) && !g_app_info_supports_files (app)) continue; if (!g_app_info_should_show (app)) continue; if (g_list_find_custom (exclude_apps, app, (GCompareFunc) compare_apps_func)) continue; if (!heading_added && show_headings) { gtk_list_store_append (self->priv->program_list_store, &iter); gtk_list_store_set (self->priv->program_list_store, &iter, COLUMN_HEADING_TEXT, bold_string, COLUMN_HEADING, TRUE, COLUMN_RECOMMENDED, recommended, COLUMN_FALLBACK, fallback, -1); heading_added = TRUE; } app_string = g_markup_printf_escaped ("%s", g_app_info_get_name (app) != NULL ? g_app_info_get_name (app) : ""); icon = g_app_info_get_icon (app); unref_icon = FALSE; if (icon == NULL) { icon = g_themed_icon_new ("application-x-executable"); unref_icon = TRUE; } gtk_list_store_append (self->priv->program_list_store, &iter); gtk_list_store_set (self->priv->program_list_store, &iter, COLUMN_APP_INFO, app, COLUMN_GICON, icon, COLUMN_NAME, g_app_info_get_name (app), COLUMN_DESC, app_string, COLUMN_EXEC, g_app_info_get_executable (app), COLUMN_HEADING, FALSE, COLUMN_RECOMMENDED, recommended, COLUMN_FALLBACK, fallback, -1); retval = TRUE; g_free (app_string); if (unref_icon) g_object_unref (icon); } g_free (bold_string); return retval; }
int main (int argc, char **argv) { setlocale (LC_ALL, ""); if (argv[1] == NULL) ; else if (g_str_equal (argv[1], "list")) { GList *all, *i; all = g_app_info_get_all (); for (i = all; i; i = i->next) g_print ("%s%s", g_app_info_get_id (i->data), i->next ? " " : "\n"); g_list_free_full (all, g_object_unref); } else if (g_str_equal (argv[1], "search")) { gchar ***results; gint i, j; results = g_desktop_app_info_search (argv[2]); for (i = 0; results[i]; i++) { for (j = 0; results[i][j]; j++) g_print ("%s%s", j ? " " : "", results[i][j]); g_print ("\n"); g_strfreev (results[i]); } g_free (results); } else if (g_str_equal (argv[1], "implementations")) { GList *results; results = g_desktop_app_info_get_implementations (argv[2]); print_app_list (results); } else if (g_str_equal (argv[1], "show-info")) { GAppInfo *info; info = (GAppInfo *) g_desktop_app_info_new (argv[2]); if (info) { print (g_app_info_get_id (info)); print (g_app_info_get_name (info)); print (g_app_info_get_display_name (info)); print (g_app_info_get_description (info)); g_object_unref (info); } } else if (g_str_equal (argv[1], "default-for-type")) { GAppInfo *info; info = g_app_info_get_default_for_type (argv[2], FALSE); if (info) { print (g_app_info_get_id (info)); g_object_unref (info); } } else if (g_str_equal (argv[1], "recommended-for-type")) { GList *list; list = g_app_info_get_recommended_for_type (argv[2]); print_app_list (list); } else if (g_str_equal (argv[1], "all-for-type")) { GList *list; list = g_app_info_get_all_for_type (argv[2]); print_app_list (list); } else if (g_str_equal (argv[1], "fallback-for-type")) { GList *list; list = g_app_info_get_fallback_for_type (argv[2]); print_app_list (list); } else if (g_str_equal (argv[1], "should-show")) { GAppInfo *info; info = (GAppInfo *) g_desktop_app_info_new (argv[2]); if (info) { g_print ("%s\n", g_app_info_should_show (info) ? "true" : "false"); g_object_unref (info); } } else if (g_str_equal (argv[1], "monitor")) { GAppInfoMonitor *monitor; GAppInfo *info; monitor = g_app_info_monitor_get (); info = (GAppInfo *) g_desktop_app_info_new ("this-desktop-file-does-not-exist"); g_assert (!info); g_signal_connect (monitor, "changed", G_CALLBACK (quit), NULL); while (1) g_main_context_iteration (NULL, TRUE); } return 0; }
int main (int argc, char **argv) { setlocale (LC_ALL, ""); if (argv[1] == NULL) ; else if (g_str_equal (argv[1], "list")) { GList *all, *i; all = g_app_info_get_all (); for (i = all; i; i = i->next) g_print ("%s%s", g_app_info_get_id (i->data), i->next ? " " : "\n"); g_list_free_full (all, g_object_unref); } else if (g_str_equal (argv[1], "search")) { gchar ***results; gint i, j; results = g_desktop_app_info_search (argv[2]); for (i = 0; results[i]; i++) { for (j = 0; results[i][j]; j++) g_print ("%s%s", j ? " " : "", results[i][j]); g_print ("\n"); g_strfreev (results[i]); } g_free (results); } else if (g_str_equal (argv[1], "implementations")) { GList *results; results = g_desktop_app_info_get_implementations (argv[2]); print_app_list (results); } else if (g_str_equal (argv[1], "show-info")) { GAppInfo *info; info = (GAppInfo *) g_desktop_app_info_new (argv[2]); if (info) { print (g_app_info_get_id (info)); print (g_app_info_get_name (info)); print (g_app_info_get_display_name (info)); print (g_app_info_get_description (info)); g_object_unref (info); } } else if (g_str_equal (argv[1], "default-for-type")) { GAppInfo *info; info = g_app_info_get_default_for_type (argv[2], FALSE); if (info) { print (g_app_info_get_id (info)); g_object_unref (info); } } else if (g_str_equal (argv[1], "recommended-for-type")) { GList *list; list = g_app_info_get_recommended_for_type (argv[2]); print_app_list (list); } else if (g_str_equal (argv[1], "all-for-type")) { GList *list; list = g_app_info_get_all_for_type (argv[2]); print_app_list (list); } else if (g_str_equal (argv[1], "fallback-for-type")) { GList *list; list = g_app_info_get_fallback_for_type (argv[2]); print_app_list (list); } else if (g_str_equal (argv[1], "should-show")) { GAppInfo *info; info = (GAppInfo *) g_desktop_app_info_new (argv[2]); if (info) { g_print ("%s\n", g_app_info_should_show (info) ? "true" : "false"); g_object_unref (info); } } return 0; }