/* This callback returns the text, both the editable part, and the * part below that is not editable. */ static void fm_icon_container_get_icon_text (CajaIconContainer *container, CajaIconData *data, char **editable_text, char **additional_text, gboolean include_invisible) { char *actual_uri; gchar *description; GQuark *attributes; char *text_array[4]; int i, j, num_attributes; FMIconView *icon_view; CajaFile *file; gboolean use_additional; file = CAJA_FILE (data); g_assert (CAJA_IS_FILE (file)); g_assert (editable_text != NULL); icon_view = get_icon_view (container); g_return_if_fail (icon_view != NULL); use_additional = (additional_text != NULL); /* In the smallest zoom mode, no text is drawn. */ if (caja_icon_container_get_zoom_level (container) == CAJA_ZOOM_LEVEL_SMALLEST && !include_invisible) { *editable_text = NULL; } else { /* Strip the suffix for caja object xml files. */ *editable_text = caja_file_get_display_name (file); } if (!use_additional) { return; } if (fm_icon_view_is_compact (icon_view)) { *additional_text = NULL; return; } if (CAJA_IS_DESKTOP_ICON_FILE (file)) { /* Don't show the normal extra information for desktop icons, it doesn't * make sense. */ *additional_text = NULL; return; } /* Handle link files specially. */ if (caja_file_is_caja_link (file)) { /* FIXME bugzilla.gnome.org 42531: Does sync. I/O and works only locally. */ *additional_text = NULL; if (caja_file_is_local (file)) { actual_uri = caja_file_get_uri (file); description = caja_link_local_get_additional_text (actual_uri); if (description) *additional_text = g_strdup_printf (" \n%s\n ", description); g_free (description); g_free (actual_uri); } /* Don't show the normal extra information for desktop files, it doesn't * make sense. */ return; } /* Find out what attributes go below each icon. */ attributes = fm_icon_container_get_icon_text_attribute_names (container, &num_attributes); /* Get the attributes. */ j = 0; for (i = 0; i < num_attributes; ++i) { if (attributes[i] == attribute_none_q) { continue; } text_array[j++] = caja_file_get_string_attribute_with_default_q (file, attributes[i]); } text_array[j] = NULL; /* Return them. */ if (j == 0) { *additional_text = NULL; } else if (j == 1) { /* Only one item, avoid the strdup + free */ *additional_text = text_array[0]; } else { *additional_text = g_strjoinv ("\n", text_array); for (i = 0; i < j; i++) { g_free (text_array[i]); } } }
static void file_list_ready_cb (GList *files, gpointer user_data) { CajaFileConflictDialog *fcd = user_data; CajaFile *src, *dest, *dest_dir; time_t src_mtime, dest_mtime; GtkDialog *dialog; gboolean source_is_dir, dest_is_dir, should_show_type; CajaFileConflictDialogDetails *details; char *primary_text, *message, *secondary_text; const gchar *message_extra; char *src_name, *dest_name, *dest_dir_name, *edit_name; char *label_text; char *size, *date, *type = NULL; GdkPixbuf *pixbuf; GtkWidget *label; GString *str; PangoFontDescription *desc; dialog = GTK_DIALOG (fcd); details = fcd->details; details->handle = NULL; dest_dir = g_list_nth_data (files, 0); dest = g_list_nth_data (files, 1); src = g_list_nth_data (files, 2); src_mtime = caja_file_get_mtime (src); dest_mtime = caja_file_get_mtime (dest); src_name = caja_file_get_display_name (src); dest_name = caja_file_get_display_name (dest); dest_dir_name = caja_file_get_display_name (dest_dir); source_is_dir = caja_file_is_directory (src); dest_is_dir = caja_file_is_directory (dest); type = caja_file_get_mime_type (dest); should_show_type = !caja_file_is_mime_type (src, type); g_free (type); type = NULL; /* Set up the right labels */ if (dest_is_dir) { if (source_is_dir) { primary_text = g_strdup_printf (_("Merge folder \"%s\"?"), dest_name); message_extra = _("Merging will ask for confirmation before replacing any files in " "the folder that conflict with the files being copied."); if (src_mtime > dest_mtime) { message = g_strdup_printf ( _("An older folder with the same name already exists in \"%s\"."), dest_dir_name); } else if (src_mtime < dest_mtime) { message = g_strdup_printf ( _("A newer folder with the same name already exists in \"%s\"."), dest_dir_name); } else { message = g_strdup_printf ( _("Another folder with the same name already exists in \"%s\"."), dest_dir_name); } } else { message_extra = _("Replacing it will remove all files in the folder."); primary_text = g_strdup_printf (_("Replace folder \"%s\"?"), dest_name); message = g_strdup_printf (_("A folder with the same name already exists in \"%s\"."), dest_dir_name); } } else { primary_text = g_strdup_printf (_("Replace file \"%s\"?"), dest_name); message_extra = _("Replacing it will overwrite its content."); if (src_mtime > dest_mtime) { message = g_strdup_printf ( _("An older file with the same name already exists in \"%s\"."), dest_dir_name); } else if (src_mtime < dest_mtime) { message = g_strdup_printf ( _("A newer file with the same name already exists in \"%s\"."), dest_dir_name); } else { message = g_strdup_printf ( _("Another file with the same name already exists in \"%s\"."), dest_dir_name); } } secondary_text = g_strdup_printf ("%s\n%s", message, message_extra); g_free (message); label = gtk_label_new (primary_text); gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); gtk_label_set_line_wrap_mode (GTK_LABEL (label), PANGO_WRAP_WORD_CHAR); gtk_widget_set_size_request (label, 350, -1); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_box_pack_start (GTK_BOX (details->titles_vbox), label, FALSE, FALSE, 0); gtk_widget_modify_font (label, NULL); desc = pango_font_description_new (); pango_font_description_set_weight (desc, PANGO_WEIGHT_BOLD); pango_font_description_set_size (desc, pango_font_description_get_size (gtk_widget_get_style (label)->font_desc) * PANGO_SCALE_LARGE); gtk_widget_modify_font (label, desc); pango_font_description_free (desc); gtk_widget_show (label); label = gtk_label_new (secondary_text); gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); gtk_widget_set_size_request (label, 350, -1); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_box_pack_start (GTK_BOX (details->titles_vbox), label, FALSE, FALSE, 0); gtk_widget_show (label); g_free (primary_text); g_free (secondary_text); /* Set up file icons */ pixbuf = caja_file_get_icon_pixbuf (dest, CAJA_ICON_SIZE_LARGE, TRUE, CAJA_FILE_ICON_FLAGS_USE_THUMBNAILS); details->dest_image = gtk_image_new_from_pixbuf (pixbuf); gtk_box_pack_start (GTK_BOX (details->first_hbox), details->dest_image, FALSE, FALSE, 0); gtk_widget_show (details->dest_image); g_object_unref (pixbuf); pixbuf = caja_file_get_icon_pixbuf (src, CAJA_ICON_SIZE_LARGE, TRUE, CAJA_FILE_ICON_FLAGS_USE_THUMBNAILS); details->src_image = gtk_image_new_from_pixbuf (pixbuf); gtk_box_pack_start (GTK_BOX (details->second_hbox), details->src_image, FALSE, FALSE, 0); gtk_widget_show (details->src_image); g_object_unref (pixbuf); /* Set up labels */ label = gtk_label_new (NULL); date = caja_file_get_string_attribute (dest, "date_modified"); size = caja_file_get_string_attribute (dest, "size"); if (should_show_type) { type = caja_file_get_string_attribute (dest, "type"); } str = g_string_new (NULL); g_string_append_printf (str, "<b>%s</b>\n", _("Original file")); g_string_append_printf (str, "<i>%s</i> %s\n", _("Size:"), size); if (should_show_type) { g_string_append_printf (str, "<i>%s</i> %s\n", _("Type:"), type); } g_string_append_printf (str, "<i>%s</i> %s", _("Last modified:"), date); label_text = str->str; gtk_label_set_markup (GTK_LABEL (label), label_text); gtk_box_pack_start (GTK_BOX (details->first_hbox), label, FALSE, FALSE, 0); gtk_widget_show (label); g_free (size); g_free (type); g_free (date); g_string_erase (str, 0, -1); /* Second label */ label = gtk_label_new (NULL); date = caja_file_get_string_attribute (src, "date_modified"); size = caja_file_get_string_attribute (src, "size"); if (should_show_type) { type = caja_file_get_string_attribute (src, "type"); } g_string_append_printf (str, "<b>%s</b>\n", _("Replace with")); g_string_append_printf (str, "<i>%s</i> %s\n", _("Size:"), size); if (should_show_type) { g_string_append_printf (str, "<i>%s</i> %s\n", _("Type:"), type); } g_string_append_printf (str, "<i>%s</i> %s", _("Last modified:"), date); label_text = g_string_free (str, FALSE); gtk_label_set_markup (GTK_LABEL (label), label_text); gtk_box_pack_start (GTK_BOX (details->second_hbox), label, FALSE, FALSE, 0); gtk_widget_show (label); g_free (size); g_free (date); g_free (type); g_free (label_text); /* Populate the entry */ edit_name = caja_file_get_edit_name (dest); details->conflict_name = edit_name; gtk_entry_set_text (GTK_ENTRY (details->entry), edit_name); if (source_is_dir && dest_is_dir) { gtk_button_set_label (GTK_BUTTON (details->replace_button), _("Merge")); } /* If meld is installed, and source and destination arent binary * files, show the diff button */ gtk_widget_hide (details->diff_button); if (!source_is_dir && !dest_is_dir) { if (g_find_program_in_path ("meld")) { gboolean src_is_binary; gboolean dest_is_binary; src_is_binary = caja_file_is_binary (details->source); dest_is_binary = caja_file_is_binary (details->destination); if (!src_is_binary && !dest_is_binary) gtk_widget_show (details->diff_button); } } caja_file_monitor_add (src, fcd, CAJA_FILE_ATTRIBUTES_FOR_ICON); caja_file_monitor_add (dest, fcd, CAJA_FILE_ATTRIBUTES_FOR_ICON); details->src_handler_id = g_signal_connect (src, "changed", G_CALLBACK (file_icons_changed), fcd); details->dest_handler_id = g_signal_connect (dest, "changed", G_CALLBACK (file_icons_changed), fcd); }
void fm_report_error_renaming_file (CajaFile *file, const char *new_name, GError *error, GtkWindow *parent_window) { char *original_name, *original_name_truncated; char *new_name_truncated; char *message; /* Truncate names for display since very long file names with no spaces * in them won't get wrapped, and can create insanely wide dialog boxes. */ original_name = caja_file_get_display_name (file); original_name_truncated = eel_str_middle_truncate (original_name, MAXIMUM_DISPLAYED_FILE_NAME_LENGTH); g_free (original_name); new_name_truncated = eel_str_middle_truncate (new_name, MAXIMUM_DISPLAYED_FILE_NAME_LENGTH); message = NULL; if (error->domain == G_IO_ERROR) { switch (error->code) { case G_IO_ERROR_EXISTS: message = g_strdup_printf (_("The name \"%s\" is already used in this folder. " "Please use a different name."), new_name_truncated); break; case G_IO_ERROR_NOT_FOUND: message = g_strdup_printf (_("There is no \"%s\" in this folder. " "Perhaps it was just moved or deleted?"), original_name_truncated); break; case G_IO_ERROR_PERMISSION_DENIED: message = g_strdup_printf (_("You do not have the permissions necessary to rename \"%s\"."), original_name_truncated); break; case G_IO_ERROR_INVALID_FILENAME: if (strchr (new_name, '/') != NULL) { message = g_strdup_printf (_("The name \"%s\" is not valid because it contains the character \"/\". " "Please use a different name."), new_name_truncated); } else { message = g_strdup_printf (_("The name \"%s\" is not valid. " "Please use a different name."), new_name_truncated); } break; default: break; } } if (message == NULL) { /* We should invent decent error messages for every case we actually experience. */ g_warning ("Hit unhandled case %s:%d in fm_report_error_renaming_file", g_quark_to_string (error->domain), error->code); /* fall through */ message = g_strdup_printf (_("Sorry, could not rename \"%s\" to \"%s\": %s"), original_name_truncated, new_name_truncated, error->message); } g_free (original_name_truncated); g_free (new_name_truncated); eel_show_error_dialog (_("The item could not be renamed."), message, parent_window); g_free (message); }
/** * 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 }