static gboolean thunar_folder_infos_ready (ThunarVfsJob *job, GList *infos, ThunarFolder *folder) { ThunarFile *file; GList *lp; _thunar_return_val_if_fail (THUNAR_IS_FOLDER (folder), FALSE); _thunar_return_val_if_fail (THUNAR_VFS_IS_JOB (job), FALSE); _thunar_return_val_if_fail (folder->handle == NULL, FALSE); _thunar_return_val_if_fail (folder->job == job, FALSE); /* turn the info list into a file list */ for (lp = infos; lp != NULL; lp = lp->next) { /* get the file corresponding to the info... */ file = thunar_file_get_for_info (lp->data); /* ...release the info at the list position... */ thunar_vfs_info_unref (lp->data); /* ...and replace it with the file */ lp->data = file; } /* merge the list with the existing list of new files */ folder->new_files = g_list_concat (folder->new_files, infos); /* TRUE to indicate that we took over ownership of the infos list */ return TRUE; }
static void add_compare_to_menu(GList* actions, GtkWidget* window, GList* files, char* menu_name, GString* (*make_hint)(va_list, char*), GCallback callback, ...) { GtkAction* action; GtkIconTheme* theme = gtk_icon_theme_get_default(); GList* head = g_queue_peek_head_link(_saved); xdiff_ext_submenu_action* submenu; GString* name = g_string_new(""); int n = 1; va_list args; va_start(args, callback); submenu = xdiff_ext_submenu_action_new("xdiff-ext::compare_to_menu", menu_name, "", NULL); actions = g_list_append(actions, submenu); while(head) { gchar* head_file = (gchar*)head->data; ThunarVfsPath* vfs_path = thunar_vfs_path_new(head_file, NULL); ThunarVfsInfo* vfs_info = thunar_vfs_info_new_for_path(vfs_path, NULL); const gchar* icon_name = thunar_vfs_info_get_custom_icon(vfs_info); GString* hint = make_hint(args, head_file); if(icon_name == NULL) { icon_name = thunar_vfs_mime_info_lookup_icon_name(vfs_info->mime_info, theme); } thunar_vfs_path_unref(vfs_path); thunar_vfs_info_unref(vfs_info); g_string_printf(name, "xdiff-ext::compare_to_%d", n); action = gtk_action_new(name->str, head_file, hint->str, icon_name); g_signal_connect(G_OBJECT(action), "activate", callback, window); g_object_set_data_full(G_OBJECT(action), "xdiff-ext::compare_to", thunarx_file_info_list_copy(files),(GDestroyNotify)thunarx_file_info_list_free); g_object_set_data(G_OBJECT(action), "xdiff-ext::saved", head); xdiff_ext_submenu_action_add(submenu, action); g_string_free(hint, TRUE); head = g_list_next(head); n++; } xdiff_ext_submenu_action_add(submenu, NULL); action = gtk_action_new("xdiff-ext::clear", _("Clear"), _("Clear selected files list"), GTK_STOCK_CLEAR); g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(clear), window); xdiff_ext_submenu_action_add(submenu, action); g_string_free(name, TRUE); va_end(args); }
static GList* get_file_actions(ThunarxMenuProvider* provider, GtkWidget* window, GList* files) { GList* actions = 0; if(files != 0) { GtkIconTheme* theme = gtk_icon_theme_get_default(); guint n = g_list_length(files); gchar* three_way_compare_command; xdiff_ext_preferences* p = xdiff_ext_preferences_instance(); g_object_get(G_OBJECT(p), "three-way-compare-command", &three_way_compare_command, NULL); g_object_unref(p); GList* scan = files; gboolean go = TRUE; while(scan && go) { gchar* scheme; scheme = thunarx_file_info_get_uri_scheme((ThunarxFileInfo*)(scan->data)); go = strncmp(scheme, "file", 4) == 0; g_free(scheme); scan = g_list_next(scan); } if(go) { GtkAction* action = gtk_action_new("xdiff-ext::save", _("Compare later"), _("Select file for comparison"), DIFF_EXT_DATA_DIR"/icons/hicolor/16x16/actions/diff_later.png"); g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(compare_later), window); g_object_set_data_full(G_OBJECT(action), "xdiff-ext::save", thunarx_file_info_list_copy(files),(GDestroyNotify)thunarx_file_info_list_free); actions = g_list_append(actions, action); if(n == 1) { if(!g_queue_is_empty(_saved)) { GString* caption = g_string_new(""); GString* hint = g_string_new(""); GList* head = g_queue_peek_head_link(_saved); gchar* head_file = (gchar*)head->data; ThunarVfsInfo* vfs_info = NULL; ThunarVfsPath* vfs_path = NULL; const gchar* icon_name; gchar* uri; gchar* path; uri = thunarx_file_info_get_uri((ThunarxFileInfo*)files->data); path = g_filename_from_uri(uri, NULL, NULL); g_free(uri); g_string_printf(caption,_("Compare to '%s'"), head_file); g_string_printf(hint, _("Compare '%s' and '%s'"), path, head_file); vfs_path = thunar_vfs_path_new(head_file, NULL); vfs_info = thunar_vfs_info_new_for_path(vfs_path, NULL); icon_name = thunar_vfs_info_get_custom_icon(vfs_info); if(icon_name == NULL) { icon_name = thunar_vfs_mime_info_lookup_icon_name(vfs_info->mime_info, theme); } g_message("icon name: '%s'", icon_name); thunar_vfs_path_unref(vfs_path); thunar_vfs_info_unref(vfs_info); action = gtk_action_new("xdiff-ext::compare_to", caption->str, hint->str, "gaim.png"); g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(compare_to), window); g_object_set_data_full(G_OBJECT(action), "xdiff-ext::compare_to", thunarx_file_info_list_copy(files),(GDestroyNotify)thunarx_file_info_list_free); g_object_set_data(G_OBJECT(action), "xdiff-ext::saved", head); actions = g_list_append(actions, action); if(_saved->length > 1) { add_compare_to_menu(actions, window, files, _("Compare to"), make_hint, G_CALLBACK(compare_to), path); } g_string_free(caption, TRUE); g_string_free(hint, TRUE); } } else if(n == 2) { GtkAction* action = gtk_action_new("xdiff-ext::compare", _("Compare"), _("Compare selected files"), "diff"); g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(compare), window); g_object_set_data_full(G_OBJECT(action), "xdiff-ext::compare", thunarx_file_info_list_copy(files),(GDestroyNotify)thunarx_file_info_list_free); actions = g_list_append(actions, action); if(strcmp("", three_way_compare_command) != 0) { if(!g_queue_is_empty(_saved)) { GString* caption = g_string_new(""); GString* hint = g_string_new(""); GList* head = g_queue_peek_head_link(_saved); gchar* head_file = (gchar*)head->data; gchar* uri; gchar* path1; gchar* path2; uri = thunarx_file_info_get_uri((ThunarxFileInfo*)files->data); path1 = g_filename_from_uri(uri, NULL, NULL); g_free(uri); files = g_list_next(files); uri = thunarx_file_info_get_uri((ThunarxFileInfo*)files->data); path2 = g_filename_from_uri(uri, NULL, NULL); g_free(uri); g_string_printf(caption, _("3-way compare to '%s'"), head_file); g_string_printf(hint, _("3-way compare '%s', '%s' and '%s'"), path1, path2, head_file); action = gtk_action_new("xdiff-ext::compare_to", caption->str, hint->str, "diff3_with"); g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(compare3_to), window); g_object_set_data_full(G_OBJECT(action), "xdiff-ext::compare_to", thunarx_file_info_list_copy(files),(GDestroyNotify)thunarx_file_info_list_free); g_object_set_data(G_OBJECT(action), "xdiff-ext::saved", head); actions = g_list_append(actions, action); if(_saved->length > 1) { add_compare_to_menu(actions, window, files, _("3-way compare to"), make_hint3, G_CALLBACK(compare3_to), path1, path2); } g_string_free(caption, TRUE); g_string_free(hint, TRUE); } } } else if(n == 3) { if(strcmp("", three_way_compare_command) != 0) { GtkAction* action = gtk_action_new("xdiff-ext::compare3", _("3-way Compare"), _("Compare selected files"), "diff3"); g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(compare3), window); g_object_set_data_full(G_OBJECT(action), "xdiff-ext::compare3", thunarx_file_info_list_copy(files),(GDestroyNotify)thunarx_file_info_list_free); actions = g_list_append(actions, action); } } } g_free(three_way_compare_command); } return actions; }