static void set_replace_button_label (FileConflictDialogData *data) { gboolean source_is_directory, destination_is_directory; source_is_directory = nautilus_file_is_directory (data->source); destination_is_directory = nautilus_file_is_directory (data->destination); if (source_is_directory && destination_is_directory) { nautilus_file_conflict_dialog_set_replace_button_label (data->dialog, _("Merge")); } }
static gboolean nautilus_drag_can_accept_files (NautilusFile *drop_target_item) { NautilusDirectory *directory; if (nautilus_file_is_directory (drop_target_item)) { gboolean res; /* target is a directory, accept if editable */ directory = nautilus_directory_get_for_file (drop_target_item); res = nautilus_directory_is_editable (directory); nautilus_directory_unref (directory); return res; } if (NAUTILUS_IS_DESKTOP_ICON_FILE (drop_target_item)) { return TRUE; } /* Launchers are an acceptable drop target */ if (nautilus_file_is_launcher (drop_target_item)) { return TRUE; } if (nautilus_is_file_roller_installed () && nautilus_file_is_archive (drop_target_item)) { return TRUE; } return FALSE; }
static void copy_move_conflict_on_file_list_ready (GList *files, gpointer user_data) { FileConflictDialogData *data = user_data; g_autofree gchar *title = NULL; data->handle = NULL; if (nautilus_file_is_directory (data->source)) { title = g_strdup (nautilus_file_is_directory (data->destination) ? _("Merge Folder") : _("File and Folder conflict")); } else { title = g_strdup (nautilus_file_is_directory (data->destination) ? _("File and Folder conflict") : _("File conflict")); } gtk_window_set_title (GTK_WINDOW (data->dialog), title); set_copy_move_dialog_text (data); set_images (data); set_file_labels (data); set_conflict_name (data); set_replace_button_label (data); nautilus_file_monitor_add (data->source, data, NAUTILUS_FILE_ATTRIBUTES_FOR_ICON); nautilus_file_monitor_add (data->destination, data, NAUTILUS_FILE_ATTRIBUTES_FOR_ICON); data->source_handler_id = g_signal_connect (data->source, "changed", G_CALLBACK (file_icons_changed), data); data->destination_handler_id = g_signal_connect (data->destination, "changed", G_CALLBACK (file_icons_changed), data); }
static gboolean nautilus_drag_can_accept_files (NautilusFile *drop_target_item) { NautilusDirectory *directory; if (nautilus_file_is_directory (drop_target_item)) { gboolean res; /* target is a directory, accept if editable */ directory = nautilus_directory_get_for_file (drop_target_item); res = nautilus_directory_is_editable (directory); nautilus_directory_unref (directory); return res; } if (NAUTILUS_IS_DESKTOP_ICON_FILE (drop_target_item)) { return TRUE; } /* All Nautilus links are assumed to be links to directories. * Therefore, they all can accept drags, like all other * directories to. As with other directories, there can be * errors when the actual copy is attempted due to * permissions. */ if (nautilus_file_is_nautilus_link (drop_target_item)) { return TRUE; } if (nautilus_is_file_roller_installed () && nautilus_file_is_archive (drop_target_item)) { return TRUE; } return FALSE; }
static void file_list_ready_cb (GList *files, gpointer user_data) { NautilusFileConflictDialog *fcd = user_data; NautilusFile *src, *dest, *dest_dir; time_t src_mtime, dest_mtime; gboolean source_is_dir, dest_is_dir, should_show_type; NautilusFileConflictDialogDetails *details; char *primary_text, *message, *secondary_text; const gchar *message_extra; char *dest_name, *dest_dir_name, *edit_name; char *label_text; char *size, *date, *type = NULL; GdkPixbuf *pixbuf; GtkWidget *label; GString *str; PangoAttrList *attr_list; 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 = nautilus_file_get_mtime (src); dest_mtime = nautilus_file_get_mtime (dest); dest_name = nautilus_file_get_display_name (dest); dest_dir_name = nautilus_file_get_display_name (dest_dir); source_is_dir = nautilus_file_is_directory (src); dest_is_dir = nautilus_file_is_directory (dest); type = nautilus_file_get_mime_type (dest); should_show_type = !nautilus_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_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); attr_list = pango_attr_list_new (); pango_attr_list_insert (attr_list, pango_attr_weight_new (PANGO_WEIGHT_BOLD)); pango_attr_list_insert (attr_list, pango_attr_scale_new (PANGO_SCALE_LARGE)); g_object_set (label, "attributes", attr_list, NULL); pango_attr_list_unref (attr_list); label = gtk_label_new (secondary_text); gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); 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 = nautilus_file_get_icon_pixbuf (dest, NAUTILUS_ICON_SIZE_LARGE, TRUE, gtk_widget_get_scale_factor (fcd->details->titles_vbox), NAUTILUS_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 = nautilus_file_get_icon_pixbuf (src, NAUTILUS_ICON_SIZE_LARGE, TRUE, gtk_widget_get_scale_factor (fcd->details->titles_vbox), NAUTILUS_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 = nautilus_file_get_string_attribute (dest, "date_modified"); size = nautilus_file_get_string_attribute (dest, "size"); if (should_show_type) { type = nautilus_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, "%s %s\n", _("Size:"), size); if (should_show_type) { g_string_append_printf (str, "%s %s\n", _("Type:"), type); } g_string_append_printf (str, "%s %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 = nautilus_file_get_string_attribute (src, "date_modified"); size = nautilus_file_get_string_attribute (src, "size"); if (should_show_type) { type = nautilus_file_get_string_attribute (src, "type"); } g_string_append_printf (str, "<b>%s</b>\n", _("Replace with")); g_string_append_printf (str, "%s %s\n", _("Size:"), size); if (should_show_type) { g_string_append_printf (str, "%s %s\n", _("Type:"), type); } g_string_append_printf (str, "%s %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 = nautilus_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")); } nautilus_file_monitor_add (src, fcd, NAUTILUS_FILE_ATTRIBUTES_FOR_ICON); nautilus_file_monitor_add (dest, fcd, NAUTILUS_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); }
static void set_file_labels (FileConflictDialogData *data) { GString *destination_label; GString *source_label; gboolean source_is_directory; gboolean destination_is_directory; gboolean should_show_type; g_autofree char *destination_mime_type = NULL; g_autofree char *destination_date = NULL; g_autofree char *destination_size = NULL; g_autofree char *destination_type = NULL; g_autofree char *source_date = NULL; g_autofree char *source_size = NULL; g_autofree char *source_type = NULL; source_is_directory = nautilus_file_is_directory (data->source); destination_is_directory = nautilus_file_is_directory (data->destination); destination_mime_type = nautilus_file_get_mime_type (data->destination); should_show_type = !nautilus_file_is_mime_type (data->source, destination_mime_type); destination_date = nautilus_file_get_string_attribute (data->destination, "date_modified"); destination_size = nautilus_file_get_string_attribute (data->destination, "size"); if (should_show_type) { destination_type = nautilus_file_get_string_attribute (data->destination, "type"); } destination_label = g_string_new (NULL); if (destination_is_directory) { g_string_append_printf (destination_label, "<b>%s</b>\n", _("Original folder")); g_string_append_printf (destination_label, "%s %s\n", _("Items:"), destination_size); } else { g_string_append_printf (destination_label, "<b>%s</b>\n", _("Original file")); g_string_append_printf (destination_label, "%s %s\n", _("Size:"), destination_size); } if (should_show_type) { g_string_append_printf (destination_label, "%s %s\n", _("Type:"), destination_type); } g_string_append_printf (destination_label, "%s %s", _("Last modified:"), destination_date); source_date = nautilus_file_get_string_attribute (data->source, "date_modified"); source_size = nautilus_file_get_string_attribute (data->source, "size"); if (should_show_type) { source_type = nautilus_file_get_string_attribute (data->source, "type"); } source_label = g_string_new (NULL); if (source_is_directory) { g_string_append_printf (source_label, "<b>%s</b>\n", destination_is_directory ? _("Merge with") : _("Replace with")); g_string_append_printf (source_label, "%s %s\n", _("Items:"), source_size); } else { g_string_append_printf (source_label, "<b>%s</b>\n", _("Replace with")); g_string_append_printf (source_label, "%s %s\n", _("Size:"), source_size); } if (should_show_type) { g_string_append_printf (source_label, "%s %s\n", _("Type:"), source_type); } g_string_append_printf (source_label, "%s %s", _("Last modified:"), source_date); nautilus_file_conflict_dialog_set_file_labels (data->dialog, destination_label->str, source_label->str); g_string_free (destination_label, TRUE); g_string_free (source_label, TRUE); }
static void set_copy_move_dialog_text (FileConflictDialogData *data) { g_autofree gchar *primary_text = NULL; g_autofree gchar *secondary_text = NULL; const gchar *message_extra; time_t source_mtime; time_t destination_mtime; g_autofree gchar *message = NULL; g_autofree gchar *destination_name = NULL; g_autofree gchar *destination_directory_name = NULL; gboolean source_is_directory; gboolean destination_is_directory; source_mtime = nautilus_file_get_mtime (data->source); destination_mtime = nautilus_file_get_mtime (data->destination); destination_name = nautilus_file_get_display_name (data->destination); destination_directory_name = nautilus_file_get_display_name (data->destination_directory); source_is_directory = nautilus_file_is_directory (data->source); destination_is_directory = nautilus_file_is_directory (data->destination); if (destination_is_directory) { if (source_is_directory) { primary_text = g_strdup_printf (_("Merge folder “%s”?"), destination_name); message_extra = _("Merging will ask for confirmation before replacing any files in " "the folder that conflict with the files being copied."); if (source_mtime > destination_mtime) { message = g_strdup_printf (_("An older folder with the same name already exists in “%s”."), destination_directory_name); } else if (source_mtime < destination_mtime) { message = g_strdup_printf (_("A newer folder with the same name already exists in “%s”."), destination_directory_name); } else { message = g_strdup_printf (_("Another folder with the same name already exists in “%s”."), destination_directory_name); } } else { primary_text = g_strdup_printf (_("Replace folder “%s”?"), destination_name); message_extra = _("Replacing it will remove all files in the folder."); message = g_strdup_printf (_("A folder with the same name already exists in “%s”."), destination_directory_name); } } else { primary_text = g_strdup_printf (_("Replace file “%s”?"), destination_name); message_extra = _("Replacing it will overwrite its content."); if (source_mtime > destination_mtime) { message = g_strdup_printf (_("An older file with the same name already exists in “%s”."), destination_directory_name); } else if (source_mtime < destination_mtime) { message = g_strdup_printf (_("A newer file with the same name already exists in “%s”."), destination_directory_name); } else { message = g_strdup_printf (_("Another file with the same name already exists in “%s”."), destination_directory_name); } } secondary_text = g_strdup_printf ("%s\n%s", message, message_extra); nautilus_file_conflict_dialog_set_text (data->dialog, primary_text, secondary_text); }
static NautilusRequestStatus vfs_file_get_deep_counts (NautilusFile *file, guint *directory_count, guint *file_count, guint *unreadable_directory_count, goffset *total_size) { GFileType type; if (directory_count != NULL) { *directory_count = 0; } if (file_count != NULL) { *file_count = 0; } if (unreadable_directory_count != NULL) { *unreadable_directory_count = 0; } if (total_size != NULL) { *total_size = 0; } if (!nautilus_file_is_directory (file)) { return NAUTILUS_REQUEST_DONE; } if (file->details->deep_counts_status != NAUTILUS_REQUEST_NOT_STARTED) { if (directory_count != NULL) { *directory_count = file->details->deep_directory_count; } if (file_count != NULL) { *file_count = file->details->deep_file_count; } if (unreadable_directory_count != NULL) { *unreadable_directory_count = file->details->deep_unreadable_count; } if (total_size != NULL) { *total_size = file->details->deep_size; } return file->details->deep_counts_status; } /* For directories, or before we know the type, we haven't started. */ type = nautilus_file_get_file_type (file); if (type == G_FILE_TYPE_UNKNOWN || type == G_FILE_TYPE_DIRECTORY) { return NAUTILUS_REQUEST_NOT_STARTED; } /* For other types, we are done, and the zeros are permanent. */ return NAUTILUS_REQUEST_DONE; }
gboolean nautilus_list_model_add_file (NautilusListModel *model, NautilusFile *file, NautilusDirectory *directory) { GtkTreeIter iter; GtkTreePath *path; FileEntry *file_entry; GSequenceIter *ptr, *parent_ptr; GSequence *files; gboolean replace_dummy; GHashTable *parent_hash; parent_ptr = g_hash_table_lookup (model->details->directory_reverse_map, directory); if (parent_ptr) { file_entry = g_sequence_get (parent_ptr); ptr = g_hash_table_lookup (file_entry->reverse_map, file); } else { file_entry = NULL; ptr = g_hash_table_lookup (model->details->top_reverse_map, file); } if (ptr != NULL) { g_warning ("file already in tree (parent_ptr: %p)!!!\n", parent_ptr); return FALSE; } file_entry = g_new0 (FileEntry, 1); file_entry->file = nautilus_file_ref (file); file_entry->parent = NULL; file_entry->subdirectory = NULL; file_entry->files = NULL; files = model->details->files; parent_hash = model->details->top_reverse_map; replace_dummy = FALSE; if (parent_ptr != NULL) { file_entry->parent = g_sequence_get (parent_ptr); /* At this point we set loaded. Either we saw * "done" and ignored it waiting for this, or we do this * earlier, but then we replace the dummy row anyway, * so it doesn't matter */ file_entry->parent->loaded = 1; parent_hash = file_entry->parent->reverse_map; files = file_entry->parent->files; if (g_sequence_get_length (files) == 1) { GSequenceIter *dummy_ptr = g_sequence_get_iter_at_pos (files, 0); FileEntry *dummy_entry = g_sequence_get (dummy_ptr); if (dummy_entry->file == NULL) { /* replace the dummy loading entry */ model->details->stamp++; g_sequence_remove (dummy_ptr); replace_dummy = TRUE; } } } file_entry->ptr = g_sequence_insert_sorted (files, file_entry, nautilus_list_model_file_entry_compare_func, model); g_hash_table_insert (parent_hash, file, file_entry->ptr); iter.stamp = model->details->stamp; iter.user_data = file_entry->ptr; path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter); if (replace_dummy) { gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter); } else { gtk_tree_model_row_inserted (GTK_TREE_MODEL (model), path, &iter); } if (nautilus_file_is_directory (file)) { file_entry->files = g_sequence_new ((GDestroyNotify)file_entry_free); add_dummy_row (model, file_entry); gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (model), path, &iter); } gtk_tree_path_free (path); return TRUE; }