static gint egg_compare_app_infos (gconstpointer a, gconstpointer b, gpointer user_data) { return strcmp (g_app_info_get_display_name (G_APP_INFO (a)), g_app_info_get_display_name (G_APP_INFO (b))); }
static MxAction * _action_new_from_desktop_file (const gchar *desktop_file_id) { GDesktopAppInfo *dai; dai = g_desktop_app_info_new (desktop_file_id); if (dai) { MxAction *action; GAppInfo *ai; GIcon *icon; ai = G_APP_INFO (dai); action = mx_action_new_full (g_app_info_get_name (ai), g_app_info_get_display_name (ai), G_CALLBACK (_app_launcher_cb), (gpointer)g_app_info_get_commandline (ai)); icon = g_app_info_get_icon (ai); if (icon) { gchar *icon_name; icon_name = g_icon_to_string (icon); mx_action_set_icon (action, icon_name); g_free (icon_name); } return action; } return NULL; }
static void add_clicked_cb (GtkButton *button, gpointer user_data) { NautilusMimeApplicationChooser *chooser = user_data; GAppInfo *info; gchar *message; GError *error = NULL; info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (chooser->details->open_with_widget)); if (info == NULL) return; g_app_info_set_as_last_used_for_type (info, chooser->details->content_type, &error); if (error != NULL) { message = g_strdup_printf (_("Error while adding “%s”: %s"), g_app_info_get_display_name (info), error->message); eel_show_error_dialog (_("Could not add application"), message, GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (chooser)))); g_error_free (error); g_free (message); } else { gtk_app_chooser_refresh (GTK_APP_CHOOSER (chooser->details->open_with_widget)); g_signal_emit_by_name (nautilus_signaller_get_current (), "mime-data-changed"); } g_object_unref (info); }
/* Now we implement a set of iterator functions that will handle item lookup hell for us. */ void menu_iterate_begin(pqi inst, menu_iter *it, int showfirst) { it->reverse = FALSE; it->showfirst = showfirst; it->si = (inst->items->next? showfirst? inst->items : inst->items->next : inst->items); it->valid = (it->si != NULL); if (it->valid) it->text = g_app_info_get_display_name(G_APP_INFO(it->si->dfile)), it->icon = g_app_info_get_icon(G_APP_INFO(it->si->dfile)); }
void menu_iterate_rbegin(pqi inst, menu_iter *it, int showfirst) { it->reverse = TRUE; it->showfirst = showfirst; it->si = inst->lastitem; it->valid = (it->si != NULL); /* Wehther or not we show the first item, whether or not this is the first item, if it exists, we return it. */ if (it->valid) it->text = g_app_info_get_display_name(G_APP_INFO(it->si->dfile)), it->icon = g_app_info_get_icon(G_APP_INFO(it->si->dfile)); }
void menu_iter_next(menu_iter* it) { if (it->reverse) it->si = it->si->prev, it->valid = (it->si != NULL && (it->showfirst || it->si->prev)); else it->si = it->si->next, it->valid = (it->si != NULL); if (it->valid) it->text = g_app_info_get_display_name(G_APP_INFO(it->si->dfile)), it->icon = g_app_info_get_icon(G_APP_INFO(it->si->dfile)); }
JS_EXPORT_API double launcher_weight(GDesktopAppInfo* info, const char* key) { double weight = 0.0; /* desktop file information */ const char* path = g_desktop_app_info_get_filename(info); char* basename = g_path_get_basename(path); *strchr(basename, '.') = '\0'; weight += _get_weight(basename, key, _pred, FILENAME_WEIGHT); g_free(basename); const char* gname = g_desktop_app_info_get_generic_name(info); weight += _get_weight(gname, key, _pred, GENERIC_NAME_WEIGHT); const char* const* keys = g_desktop_app_info_get_keywords(info); if (keys != NULL) { size_t n = g_strv_length((char**)keys); for (size_t i=0; i<n; i++) { weight += _get_weight(keys[i], key, _pred, KEYWORD_WEIGHT); } } const char* categories = g_desktop_app_info_get_categories(info); if (categories) { gchar** category_names = g_strsplit(categories, ";", -1); gsize len = g_strv_length(category_names) - 1; for (gsize i = 0; i < len; ++i) { weight += _get_weight(category_names[i], key, _pred, CATEGORY_WEIGHT); } g_strfreev(category_names); } /* application information */ const char* name = g_app_info_get_name((GAppInfo*)info); weight += _get_weight(name, key, _pred, NAME_WEIGHT); const char* dname = g_app_info_get_display_name((GAppInfo*)info); weight += _get_weight(dname, key, _pred, DISPLAY_NAME_WEIGHT); const char* desc = g_app_info_get_description((GAppInfo*)info); weight += _get_weight(desc, key, _pred, DESCRIPTION_WEIGHT); const char* exec = g_app_info_get_executable((GAppInfo*)info); weight += _get_weight(exec, key, _pred, EXECUTABLE_WEIGHT); return weight; }
static void combo_changed_cb (GtkAppChooserButton *button, gpointer user_data) { GAppInfo *app_info; app_info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (button)); if (app_info == NULL) return; gtk_image_set_from_gicon (GTK_IMAGE (sel_image), g_app_info_get_icon (app_info)); gtk_label_set_text (GTK_LABEL (sel_name), g_app_info_get_display_name (app_info)); g_object_unref (app_info); }
static void combo_changed_cb (GtkComboBox *cb, gpointer user_data) { GAppInfo *app_info; app_info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (cb)); if (app_info == NULL) return; gtk_image_set_from_gicon (GTK_IMAGE (sel_image), g_app_info_get_icon (app_info), GTK_ICON_SIZE_DIALOG); gtk_label_set_text (GTK_LABEL (sel_name), g_app_info_get_display_name (app_info)); g_object_unref (app_info); }
static void populate_mime_handlers (GMenu *menu, GbProjectFile *project_file) { g_autofree gchar *content_type = NULL; GList *list; GList *iter; GFile *file; g_assert (G_IS_MENU (menu)); g_assert (GB_IS_PROJECT_FILE (project_file)); g_menu_remove_all (menu); file = gb_project_file_get_file (project_file); if (file == NULL) return; content_type = get_content_type (file); if (content_type == NULL) return; list = g_app_info_get_all_for_type (content_type); for (iter = list; iter; iter = iter->next) { g_autoptr(GMenuItem) menu_item = NULL; g_autofree gchar *detailed_action = NULL; GAppInfo *app_info = iter->data; const gchar *display_name; const gchar *app_id; display_name = g_app_info_get_display_name (app_info); app_id = g_app_info_get_id (app_info); detailed_action = g_strdup_printf ("project-tree.open-with('%s')", app_id); menu_item = g_menu_item_new (display_name, detailed_action); g_menu_append_item (menu, menu_item); } g_list_free_full (list, g_object_unref); }
static gboolean launch_app_info (GAppInfo *app_info, GError **error) { GdkAppLaunchContext *context = NULL; GdkDisplay *display; GError *err = NULL; display = gdk_display_get_default (); context = gdk_display_get_app_launch_context (display); if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context, &err)) { DEBUG ("Failed to launch %s: %s", g_app_info_get_display_name (app_info), err->message); g_propagate_error (error, err); return FALSE; } tp_clear_object (&context); return TRUE; }
void ephy_web_application_setup_from_desktop_file (GDesktopAppInfo *desktop_info) { GAppInfo *app_info; const char *wm_class; GIcon *icon; g_assert (G_IS_DESKTOP_APP_INFO (desktop_info)); app_info = G_APP_INFO (desktop_info); g_set_prgname (g_app_info_get_name (app_info)); g_set_application_name (g_app_info_get_display_name (app_info)); icon = g_app_info_get_icon (app_info); if (G_IS_FILE_ICON (icon)) { GFile *file = g_file_icon_get_file (G_FILE_ICON (icon)); char *path = file ? g_file_get_path (file) : NULL; if (path) { gtk_window_set_default_icon_from_file (path, NULL); g_free (path); } g_clear_object (&file); } else if (G_IS_THEMED_ICON (icon)) { const char * const *names = g_themed_icon_get_names (G_THEMED_ICON (icon)); if (names) gtk_window_set_default_icon_name (names[0]); } g_clear_object (&icon); /* We need to re-set this because we have already parsed the * options, which inits GTK+ and sets this as a side effect. */ wm_class = g_desktop_app_info_get_startup_wm_class (desktop_info); if (wm_class) gdk_set_program_class (wm_class); }
/* * This function inherit from gnome-menus/util/test-menu-spec.c */ static void traverse_directory(GMenuTreeDirectory *dir, GtkWidget *parent) { GMenuTreeIter *iter = NULL; GtkWidget *dir_submenu = parent ? gtk_menu_new() : NULL; GtkWidget *entry_submenu = gtk_menu_new(); GIcon *icon = NULL; const char *text = NULL; GtkWidget *menuitem = NULL; iter = gmenu_tree_directory_iter(dir); while (TRUE) { gpointer item = NULL; switch (gmenu_tree_iter_next(iter)) { case GMENU_TREE_ITEM_INVALID: goto done; case GMENU_TREE_ITEM_ENTRY: item = gmenu_tree_iter_get_entry(iter); GDesktopAppInfo *appinfo = gmenu_tree_entry_get_app_info((GMenuTreeEntry *)item); icon = g_app_info_get_icon((GAppInfo *)appinfo); text = g_app_info_get_display_name((GAppInfo *)appinfo); menuitem = menu_item_new_with_icon_text(icon, text); gtk_menu_shell_append(GTK_MENU_SHELL(entry_submenu), menuitem); g_object_connect(G_OBJECT(menuitem), "signal::activate", G_CALLBACK(menu_item_activate), appinfo, NULL); break; case GMENU_TREE_ITEM_DIRECTORY: item = gmenu_tree_iter_get_directory(iter); icon = gmenu_tree_directory_get_icon((GMenuTreeDirectory *)item); text = gmenu_tree_directory_get_name((GMenuTreeDirectory *)item); menuitem = menu_item_new_with_icon_text(icon, text); gtk_menu_shell_append(dir_submenu ? GTK_MENU_SHELL(dir_submenu) : GTK_MENU_SHELL(popup), menuitem); traverse_directory(item, menuitem); break; } if (item) { gmenu_tree_item_unref(item); item = NULL; } continue; done: break; } if (parent) { if (dir_submenu) gtk_menu_item_set_submenu(GTK_MENU_ITEM(parent), dir_submenu); gtk_menu_item_set_submenu(GTK_MENU_ITEM(parent), entry_submenu); } if (iter) { gmenu_tree_iter_unref(iter); iter = NULL; } }
static void fill_open_with_menu (GtkTreeView *view, GtkBuilder *builder, GtkTreePath *path) { GtkTreeModel *model = gtk_tree_view_get_model (view); if (!model) { return; } GtkTreeIter iter; if (!gtk_tree_model_get_iter(model, &iter, path)) { return; } DatabaseSearchEntry *entry = (DatabaseSearchEntry *)iter.user_data; if (!entry) { return; } BTreeNode * node = db_search_entry_get_node (entry); GList *app_list = NULL; char *content_type = NULL; if (node->is_dir) { content_type = g_content_type_from_mime_type ("inode/directory"); } else { content_type = g_content_type_guess (node->name, NULL, 0, NULL); } if (!content_type) { goto clean_up; } app_list = g_app_info_get_all_for_type (content_type); if (!app_list) { goto clean_up; } GMenu *menu_mime = G_MENU (gtk_builder_get_object (builder, "fsearch_listview_menu_open_with_mime_section")); for (GList *list_iter = app_list; list_iter; list_iter = list_iter->next) { GAppInfo *app_info = list_iter->data; const char *display_name = g_app_info_get_display_name (app_info); const char *app_id = g_app_info_get_id (app_info); char detailed_action[1024] = ""; snprintf (detailed_action, sizeof (detailed_action), "win.open_with('%s')", app_id); GMenuItem *menu_item = g_menu_item_new (display_name, detailed_action); g_menu_item_set_icon (menu_item, g_app_info_get_icon (app_info)); g_menu_append_item (menu_mime, menu_item); g_object_unref (menu_item); } clean_up: if (content_type) { g_free (content_type); content_type = NULL; } if (app_list) { g_list_free_full (app_list, g_object_unref); app_list = NULL; } }
gint ol_app_info_cmp (GAppInfo *a, GAppInfo *b) { return strcasecmp (g_app_info_get_display_name (a), g_app_info_get_display_name (b)); }
static void create_custom_desktop_file (NemoMimeApplicationChooser *chooser, gboolean def) { GKeyFile *keyfile = g_key_file_new (); g_key_file_set_string (keyfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_EXEC, g_app_info_get_commandline (chooser->details->custom_info)); g_key_file_set_string (keyfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, g_app_info_get_display_name (chooser->details->custom_info)); g_key_file_set_string (keyfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_MIME_TYPE, chooser->details->content_type); g_key_file_set_string (keyfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_TYPE, G_KEY_FILE_DESKTOP_TYPE_APPLICATION); gsize size; gchar *buffer = g_key_file_to_data (keyfile, &size, NULL); gint32 rn = g_random_int_range (0, G_MAXINT32 - 1); gchar *fn = g_strdup_printf ("nemo_%s_%d.desktop", g_app_info_get_display_name (chooser->details->custom_info), rn); gchar *path = g_build_filename (g_get_user_data_dir (), "applications", fn, NULL); GFile *outfile = g_file_new_for_path (path); g_free (path); GFileOutputStream *out; gboolean res; out = g_file_create (outfile, G_FILE_CREATE_NONE, NULL, NULL); if (out) { res = g_output_stream_write_all (G_OUTPUT_STREAM (out), buffer, size, NULL, NULL, NULL); if (res) { res = g_output_stream_close (G_OUTPUT_STREAM (out), NULL, NULL); update_mimelist (chooser, fn, def); } g_object_unref (out); } g_object_unref (outfile); g_free (fn); g_free (buffer); }
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; }
/** * application_cannot_open_location * * Handle the case where an application has been selected to be launched, * and it cannot handle the current uri scheme. This can happen * because the default application for a file type may not be able * to handle some kinds of locations. We want to tell users that their * default application doesn't work here, rather than switching off to * a different one without them noticing. * * @application: The application that was to be launched. * @file: The file whose location was passed as a parameter to the application * @parent_window: A window to use as the parent for any error dialogs. * */ static void application_cannot_open_location (GAppInfo *application, CajaFile *file, const char *uri_scheme, GtkWindow *parent_window) { #ifdef NEW_MIME_COMPLETE GtkDialog *message_dialog; LaunchParameters *launch_parameters; char *prompt; char *message; char *file_name; int response; file_name = caja_file_get_display_name (file); if (caja_mime_has_any_applications_for_file (file)) { if (application != NULL) { prompt = _("Open Failed, would you like to choose another application?"); message = g_strdup_printf (_("\"%s\" cannot open \"%s\" because \"%s\" cannot access files at \"%s\" " "locations."), g_app_info_get_display_name (application), file_name, g_app_info_get_display_name (application), uri_scheme); } else { prompt = _("Open Failed, would you like to choose another action?"); message = g_strdup_printf (_("The default action cannot open \"%s\" because it cannot access files at \"%s\" " "locations."), file_name, uri_scheme); } message_dialog = eel_show_yes_no_dialog (prompt, message, GTK_STOCK_OK, GTK_STOCK_CANCEL, parent_window); response = gtk_dialog_run (message_dialog); gtk_widget_destroy (GTK_WIDGET (message_dialog)); if (response == GTK_RESPONSE_YES) { launch_parameters = launch_parameters_new (file, parent_window); caja_choose_application_for_file (file, parent_window, launch_application_callback, launch_parameters); } g_free (message); } else { if (application != NULL) { prompt = g_strdup_printf (_("\"%s\" cannot open \"%s\" because \"%s\" cannot access files at \"%s\" " "locations."), g_app_info_get_display_name (application), file_name, g_app_info_get_display_name (application), uri_scheme); message = _("No other applications are available to view this file. " "If you copy this file onto your computer, you may be able to open " "it."); } else { prompt = g_strdup_printf (_("The default action cannot open \"%s\" because it cannot access files at \"%s\" " "locations."), file_name, uri_scheme); message = _("No other actions are available to view this file. " "If you copy this file onto your computer, you may be able to open " "it."); } eel_show_info_dialog (prompt, message, parent_window); g_free (prompt); } g_free (file_name); #endif }
static void create_menuitem (GtkWidget *menu, GMenuTreeEntry *entry, GMenuTreeDirectory *alias_directory) { GtkWidget *menuitem; menuitem = panel_image_menu_item_new2 (); if (alias_directory) panel_load_menu_image_deferred (menuitem, panel_menu_icon_get_size (), gmenu_tree_directory_get_icon (alias_directory), NULL, NULL); else panel_load_menu_image_deferred (menuitem, panel_menu_icon_get_size (), g_app_info_get_icon (G_APP_INFO (gmenu_tree_entry_get_app_info (entry))), NULL, NULL); setup_menuitem (menuitem, panel_menu_icon_get_size (), NULL, alias_directory ? gmenu_tree_directory_get_name (alias_directory) : g_app_info_get_display_name (G_APP_INFO (gmenu_tree_entry_get_app_info (entry)))); if (alias_directory && gmenu_tree_directory_get_comment (alias_directory)) panel_util_set_tooltip_text (menuitem, gmenu_tree_directory_get_comment (alias_directory)); else if (!alias_directory) { const char *description = g_app_info_get_description (G_APP_INFO (gmenu_tree_entry_get_app_info (entry))); if (!description) description = g_desktop_app_info_get_generic_name (gmenu_tree_entry_get_app_info (entry)); if (description) panel_util_set_tooltip_text (menuitem, description); } g_signal_connect_after (menuitem, "button_press_event", G_CALLBACK (menu_dummy_button_press_event), NULL); if (!panel_lockdown_get_panels_locked_down_s ()) { GIcon *icon; static GtkTargetEntry menu_item_targets[] = { { "text/uri-list", 0, 0 } }; gtk_drag_source_set (menuitem, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, menu_item_targets, 1, GDK_ACTION_COPY); icon = g_app_info_get_icon (G_APP_INFO (gmenu_tree_entry_get_app_info (entry))); if (icon != NULL) gtk_drag_source_set_icon_gicon (menuitem, icon); g_signal_connect (G_OBJECT (menuitem), "drag_begin", G_CALLBACK (drag_begin_menu_cb), NULL); g_signal_connect (menuitem, "drag_data_get", G_CALLBACK (drag_data_get_menu_cb), entry); g_signal_connect (menuitem, "drag_end", G_CALLBACK (drag_end_menu_cb), NULL); } gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); g_signal_connect (menuitem, "activate", G_CALLBACK (activate_app_def), entry); gtk_widget_show (menuitem); }
static void fill_combo_box(GtkIconTheme* theme, GtkComboBox* combo_box, GList* app_list, gchar* mime) { guint index = 0; GList* entry; GtkTreeModel* model; GtkCellRenderer* renderer; GtkTreeIter iter; GdkPixbuf* pixbuf; GAppInfo* default_app; default_app = g_app_info_get_default_for_type(mime, FALSE); if (theme == NULL) { theme = gtk_icon_theme_get_default(); } model = GTK_TREE_MODEL(gtk_list_store_new(4, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING)); gtk_combo_box_set_model(combo_box, model); renderer = gtk_cell_renderer_pixbuf_new(); /* not all cells have a pixbuf, this prevents the combo box to shrink */ gtk_cell_renderer_set_fixed_size(renderer, -1, 22); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_box), renderer, FALSE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo_box), renderer, "pixbuf", PIXBUF_COL, NULL); renderer = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_box), renderer, TRUE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo_box), renderer, "text", TEXT_COL, NULL); for (entry = app_list; entry != NULL; entry = g_list_next(entry)) { GAppInfo* item = (GAppInfo*) entry->data; // icon GIcon* icon = g_app_info_get_icon(item); gchar* icon_name = g_icon_to_string(icon); if (icon_name == NULL) { icon_name = g_strdup("binary"); // default icon } pixbuf = gtk_icon_theme_load_icon(theme, icon_name, 22, 0, NULL); gtk_list_store_append(GTK_LIST_STORE(model), &iter); gtk_list_store_set(GTK_LIST_STORE(model), &iter, PIXBUF_COL, pixbuf, TEXT_COL, g_app_info_get_display_name(item), ID_COL, g_app_info_get_id(item), ICONAME_COL, icon_name, -1); if (pixbuf) { g_object_unref(pixbuf); } /* set the index */ if (default_app != NULL && g_app_info_equal(item, default_app)) { gtk_combo_box_set_active(combo_box, index); } g_free(icon_name); index++; } }
static VALUE appinfo_get_display_name(VALUE self) { return CSTR2RVAL(g_app_info_get_display_name(_SELF(self))); }
void caja_autorun_prepare_combo_box (GtkWidget *combo_box, const char *x_content_type, gboolean include_ask, gboolean include_open_with_other_app, gboolean update_settings, CajaAutorunComboBoxChanged changed_cb, gpointer user_data) { GList *l; GList *app_info_list; GAppInfo *default_app_info; GtkListStore *list_store; GtkTreeIter iter; GdkPixbuf *pixbuf; int icon_size; int set_active; int n; int num_apps; gboolean pref_ask; gboolean pref_start_app; gboolean pref_ignore; gboolean pref_open_folder; CajaAutorunComboBoxData *data; GtkCellRenderer *renderer; gboolean new_data; caja_autorun_get_preferences (x_content_type, &pref_start_app, &pref_ignore, &pref_open_folder); pref_ask = !pref_start_app && !pref_ignore && !pref_open_folder; icon_size = caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU); set_active = -1; data = NULL; new_data = TRUE; app_info_list = g_app_info_get_all_for_type (x_content_type); default_app_info = g_app_info_get_default_for_type (x_content_type, FALSE); num_apps = g_list_length (app_info_list); list_store = gtk_list_store_new (5, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_APP_INFO, G_TYPE_STRING, G_TYPE_INT); /* no apps installed */ if (num_apps == 0) { gtk_list_store_append (list_store, &iter); pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), GTK_STOCK_DIALOG_ERROR, icon_size, 0, NULL); /* TODO: integrate with PackageKit-mate to find applications */ gtk_list_store_set (list_store, &iter, COLUMN_AUTORUN_PIXBUF, pixbuf, COLUMN_AUTORUN_NAME, _("No applications found"), COLUMN_AUTORUN_APP_INFO, NULL, COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type, COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_ASK, -1); g_object_unref (pixbuf); } else { if (include_ask) { gtk_list_store_append (list_store, &iter); pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), GTK_STOCK_DIALOG_QUESTION, icon_size, 0, NULL); gtk_list_store_set (list_store, &iter, COLUMN_AUTORUN_PIXBUF, pixbuf, COLUMN_AUTORUN_NAME, _("Ask what to do"), COLUMN_AUTORUN_APP_INFO, NULL, COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type, COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_ASK, -1); g_object_unref (pixbuf); } gtk_list_store_append (list_store, &iter); pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), GTK_STOCK_CLOSE, icon_size, 0, NULL); gtk_list_store_set (list_store, &iter, COLUMN_AUTORUN_PIXBUF, pixbuf, COLUMN_AUTORUN_NAME, _("Do Nothing"), COLUMN_AUTORUN_APP_INFO, NULL, COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type, COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_IGNORE, -1); g_object_unref (pixbuf); gtk_list_store_append (list_store, &iter); pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), "folder-open", icon_size, 0, NULL); gtk_list_store_set (list_store, &iter, COLUMN_AUTORUN_PIXBUF, pixbuf, COLUMN_AUTORUN_NAME, _("Open Folder"), COLUMN_AUTORUN_APP_INFO, NULL, COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type, COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_OPEN_FOLDER, -1); g_object_unref (pixbuf); gtk_list_store_append (list_store, &iter); gtk_list_store_set (list_store, &iter, COLUMN_AUTORUN_PIXBUF, NULL, COLUMN_AUTORUN_NAME, NULL, COLUMN_AUTORUN_APP_INFO, NULL, COLUMN_AUTORUN_X_CONTENT_TYPE, NULL, COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_SEP, -1); for (l = app_info_list, n = include_ask ? 4 : 3; l != NULL; l = l->next, n++) { GIcon *icon; CajaIconInfo *icon_info; char *open_string; GAppInfo *app_info = l->data; /* we deliberately ignore should_show because some apps might want * to install special handlers that should be hidden in the regular * application launcher menus */ icon = g_app_info_get_icon (app_info); icon_info = caja_icon_info_lookup (icon, icon_size); pixbuf = caja_icon_info_get_pixbuf_at_size (icon_info, icon_size); g_object_unref (icon_info); open_string = g_strdup_printf (_("Open %s"), g_app_info_get_display_name (app_info)); gtk_list_store_append (list_store, &iter); gtk_list_store_set (list_store, &iter, COLUMN_AUTORUN_PIXBUF, pixbuf, COLUMN_AUTORUN_NAME, open_string, COLUMN_AUTORUN_APP_INFO, app_info, COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type, COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_APP, -1); if (pixbuf != NULL) { g_object_unref (pixbuf); } g_free (open_string); if (g_app_info_equal (app_info, default_app_info)) { set_active = n; } } } if (include_open_with_other_app) { gtk_list_store_append (list_store, &iter); gtk_list_store_set (list_store, &iter, COLUMN_AUTORUN_PIXBUF, NULL, COLUMN_AUTORUN_NAME, NULL, COLUMN_AUTORUN_APP_INFO, NULL, COLUMN_AUTORUN_X_CONTENT_TYPE, NULL, COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_SEP, -1); gtk_list_store_append (list_store, &iter); pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), "application-x-executable", icon_size, 0, NULL); gtk_list_store_set (list_store, &iter, COLUMN_AUTORUN_PIXBUF, pixbuf, COLUMN_AUTORUN_NAME, _("Open with other Application..."), COLUMN_AUTORUN_APP_INFO, NULL, COLUMN_AUTORUN_X_CONTENT_TYPE, x_content_type, COLUMN_AUTORUN_ITEM_TYPE, AUTORUN_OTHER_APP, -1); g_object_unref (pixbuf); } if (default_app_info != NULL) { g_object_unref (default_app_info); } g_list_foreach (app_info_list, (GFunc) g_object_unref, NULL); g_list_free(app_info_list); gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box), GTK_TREE_MODEL (list_store)); g_object_unref (G_OBJECT (list_store)); gtk_cell_layout_clear (GTK_CELL_LAYOUT (combo_box)); renderer = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, FALSE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer, "pixbuf", COLUMN_AUTORUN_PIXBUF, NULL); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer, "text", COLUMN_AUTORUN_NAME, NULL); gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo_box), combo_box_separator_func, NULL, NULL); if (num_apps == 0) { gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), 0); gtk_widget_set_sensitive (combo_box, FALSE); } else { gtk_widget_set_sensitive (combo_box, TRUE); if (pref_ask && include_ask) { gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), 0); } else if (pref_ignore) { gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), include_ask ? 1 : 0); } else if (pref_open_folder) { gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), include_ask ? 2 : 1); } else if (set_active != -1) { gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), set_active); } else { gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), include_ask ? 1 : 0); } /* See if we have an old data around */ data = g_object_get_data (G_OBJECT (combo_box), "caja_autorun_combobox_data"); if (data) { new_data = FALSE; g_free (data->x_content_type); } else { data = g_new0 (CajaAutorunComboBoxData, 1); } data->x_content_type = g_strdup (x_content_type); data->include_ask = include_ask; data->include_open_with_other_app = include_open_with_other_app; data->update_settings = update_settings; data->changed_cb = changed_cb; data->user_data = user_data; data->combo_box = combo_box; if (data->changed_signal_id == 0) { data->changed_signal_id = g_signal_connect (G_OBJECT (combo_box), "changed", G_CALLBACK (combo_box_changed), data); } } if (new_data) { g_object_set_data_full (G_OBJECT (combo_box), "caja_autorun_combobox_data", data, (GDestroyNotify) caja_autorun_combobox_data_destroy); } }
static void fill_combo_box(GtkIconTheme* theme, GtkComboBox* combo_box, GList* app_list, gchar* mime) { guint index = 0; GList* entry; GtkTreeModel* model; GtkCellRenderer* renderer; GtkTreeIter iter; GdkPixbuf* pixbuf; GAppInfo* default_app; default_app = NULL; if (g_strcmp0(mime, "terminal") == 0) { GSettings *terminal_settings = g_settings_new (TERMINAL_SCHEMA); gchar *default_terminal = g_settings_get_string (terminal_settings, TERMINAL_KEY); for (entry = app_list; entry != NULL; entry = g_list_next(entry)) { GAppInfo* item = (GAppInfo*) entry->data; if (g_strcmp0 (g_app_info_get_executable (item), default_terminal) == 0) { default_app = item; } } g_free (default_terminal); g_object_unref (terminal_settings); } else if (g_strcmp0(mime, "visual") == 0) { GSettings *visual_settings = g_settings_new (VISUAL_SCHEMA); gchar *default_visual = g_settings_get_string (visual_settings, VISUAL_KEY); for (entry = app_list; entry != NULL; entry = g_list_next(entry)) { GAppInfo* item = (GAppInfo*) entry->data; if (g_strcmp0 (g_app_info_get_executable (item), default_visual) == 0) { default_app = item; } } g_free (default_visual); g_object_unref (visual_settings); } else if (g_strcmp0(mime, "mobility") == 0) { GSettings *mobility_settings = g_settings_new (MOBILITY_SCHEMA); gchar *default_mobility = g_settings_get_string (mobility_settings, MOBILITY_KEY); for (entry = app_list; entry != NULL; entry = g_list_next(entry)) { GAppInfo* item = (GAppInfo*) entry->data; if (g_strcmp0 (g_app_info_get_executable (item), default_mobility) == 0) { default_app = item; } } g_free (default_mobility); g_object_unref (mobility_settings); } else { default_app = g_app_info_get_default_for_type (mime, FALSE); } if (theme == NULL) { theme = gtk_icon_theme_get_default(); } model = GTK_TREE_MODEL(gtk_list_store_new(4, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING)); gtk_combo_box_set_model(combo_box, model); renderer = gtk_cell_renderer_pixbuf_new(); /* Not all cells have a pixbuf, this prevents the combo box to shrink */ gtk_cell_renderer_set_fixed_size(renderer, -1, 22); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_box), renderer, FALSE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo_box), renderer, "pixbuf", PIXBUF_COL, NULL); renderer = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_box), renderer, TRUE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo_box), renderer, "text", TEXT_COL, NULL); for (entry = app_list; entry != NULL; entry = g_list_next(entry)) { GAppInfo* item = (GAppInfo*) entry->data; /* Icon */ GIcon* icon = g_app_info_get_icon(item); gchar* icon_name = g_icon_to_string(icon); if (icon_name == NULL) { /* Default icon */ icon_name = g_strdup("binary"); } pixbuf = gtk_icon_theme_load_icon(theme, icon_name, 22, 0, NULL); gtk_list_store_append(GTK_LIST_STORE(model), &iter); gtk_list_store_set(GTK_LIST_STORE(model), &iter, PIXBUF_COL, pixbuf, TEXT_COL, g_app_info_get_display_name(item), ID_COL, g_app_info_get_id(item), ICONAME_COL, icon_name, -1); if (pixbuf) { g_object_unref(pixbuf); } /* Set the index for the default app */ if (default_app != NULL && g_app_info_equal(item, default_app)) { gtk_combo_box_set_active(combo_box, index); } g_free(icon_name); index++; } }
void nautilus_x_content_bar_set_x_content_type (NautilusXContentBar *bar, const char *x_content_type) { char *message; char *description; GAppInfo *default_app; g_free (bar->priv->x_content_type); bar->priv->x_content_type = g_strdup (x_content_type); description = g_content_type_get_description (x_content_type); /* Customize greeting for well-known x-content types */ if (strcmp (x_content_type, "x-content/audio-cdda") == 0) { message = g_strdup (_("These files are on an Audio CD.")); } else if (strcmp (x_content_type, "x-content/audio-dvd") == 0) { message = g_strdup (_("These files are on an Audio DVD.")); } else if (strcmp (x_content_type, "x-content/video-dvd") == 0) { message = g_strdup (_("These files are on a Video DVD.")); } else if (strcmp (x_content_type, "x-content/video-vcd") == 0) { message = g_strdup (_("These files are on a Video CD.")); } else if (strcmp (x_content_type, "x-content/video-svcd") == 0) { message = g_strdup (_("These files are on a Super Video CD.")); } else if (strcmp (x_content_type, "x-content/image-photocd") == 0) { message = g_strdup (_("These files are on a Photo CD.")); } else if (strcmp (x_content_type, "x-content/image-picturecd") == 0) { message = g_strdup (_("These files are on a Picture CD.")); } else if (strcmp (x_content_type, "x-content/image-dcf") == 0) { message = g_strdup (_("The media contains digital photos.")); } else if (strcmp (x_content_type, "x-content/audio-player") == 0) { message = g_strdup (_("These files are on a digital audio player.")); } else if (strcmp (x_content_type, "x-content/software") == 0) { message = g_strdup (_("The media contains software.")); } else { /* fallback to generic greeting */ message = g_strdup_printf (_("The media has been detected as \"%s\"."), description); } gtk_label_set_text (GTK_LABEL (bar->priv->label), message); gtk_widget_show (bar->priv->label); /* TODO: We really need a GtkBrowserBackButton-ish widget here.. until then, we only * show the default application. */ default_app = g_app_info_get_default_for_type (x_content_type, FALSE); if (default_app != NULL) { char *button_text; const char *name; GIcon *icon; GtkWidget *image; icon = g_app_info_get_icon (default_app); if (icon != NULL) { GdkPixbuf *pixbuf; int icon_size; NautilusIconInfo *icon_info; icon_size = nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_BUTTON); icon_info = nautilus_icon_info_lookup (icon, icon_size); pixbuf = nautilus_icon_info_get_pixbuf_at_size (icon_info, icon_size); image = gtk_image_new_from_pixbuf (pixbuf); g_object_unref (pixbuf); g_object_unref (icon_info); } else { image = NULL; } name = g_app_info_get_display_name (default_app); button_text = g_strdup_printf (_("Open %s"), name); gtk_button_set_image (GTK_BUTTON (bar->priv->button), image); gtk_button_set_label (GTK_BUTTON (bar->priv->button), button_text); gtk_widget_show (bar->priv->button); g_free (button_text); g_object_unref (default_app); } else { gtk_widget_hide (bar->priv->button); } g_free (message); g_free (description); }
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; }