static void thunar_location_entry_activate (GtkWidget *path_entry, ThunarLocationEntry *location_entry) { ThunarFile *file; GError *error = NULL; _thunar_return_if_fail (THUNAR_IS_LOCATION_ENTRY (location_entry)); _thunar_return_if_fail (location_entry->path_entry == path_entry); /* determine the current file from the path entry */ file = thunar_path_entry_get_current_file (THUNAR_PATH_ENTRY (path_entry)); if (G_LIKELY (file != NULL)) { /* check if we have a new directory or a file to launch */ if (thunar_file_is_directory (file)) { /* open the new directory */ thunar_navigator_change_directory (THUNAR_NAVIGATOR (location_entry), file); } else { /* try to launch the selected file */ if (!thunar_file_launch (file, path_entry, &error)) { thunar_dialogs_show_error (path_entry, error, _("Failed to launch \"%s\""), thunar_file_get_display_name (file)); g_error_free (error); } /* be sure to reset the current file of the path entry */ if (G_LIKELY (location_entry->current_directory != NULL)) thunar_path_entry_set_current_file (THUNAR_PATH_ENTRY (path_entry), location_entry->current_directory); } } }
void thunar_navigator_open_new_tab (ThunarNavigator *navigator, ThunarFile *directory) { _thunar_return_if_fail (THUNAR_IS_NAVIGATOR (navigator)); _thunar_return_if_fail (THUNAR_IS_FILE (directory)); _thunar_return_if_fail (thunar_file_is_directory (directory)); g_signal_emit (G_OBJECT (navigator), navigator_signals[OPEN_NEW_TAB], 0, directory); }
/** * thunar_navigator_change_directory: * @navigator : a #ThunarNavigator instance. * @directory : a #ThunarFile referring to a directory. * * Emits the "change-directory" signal on @navigator with * the specified @directory. * * Derived classes should invoke this method whenever the user * selects a new directory from within @navigator. The derived * class should not perform any directory changing operations * itself, but leave it up to the surrounding module (usually * a #ThunarWindow instance) to change the directory. * * It should never ever be called from outside a #ThunarNavigator * implementation, as that may led to unexpected results! **/ void thunar_navigator_change_directory (ThunarNavigator *navigator, ThunarFile *directory) { _thunar_return_if_fail (THUNAR_IS_NAVIGATOR (navigator)); _thunar_return_if_fail (THUNAR_IS_FILE (directory)); _thunar_return_if_fail (thunar_file_is_directory (directory)); g_signal_emit (G_OBJECT (navigator), navigator_signals[CHANGE_DIRECTORY], 0, directory); }
/** * thunar_folder_get_for_file: * @file : a #ThunarFile. * * Opens the specified @file as #ThunarFolder and * returns a reference to the folder. * * The caller is responsible to free the returned * object using g_object_unref() when no longer * needed. * * Return value: the #ThunarFolder which corresponds * to @file. **/ ThunarFolder* thunar_folder_get_for_file (ThunarFile *file) { ThunarFolder *folder; _thunar_return_val_if_fail (THUNAR_IS_FILE (file), NULL); _thunar_return_val_if_fail (thunar_file_is_directory (file), NULL); /* determine the "thunar-folder" quark on-demand */ if (G_UNLIKELY (thunar_folder_quark == 0)) thunar_folder_quark = g_quark_from_static_string ("thunar-folder"); /* check if we already know that folder */ folder = g_object_get_qdata (G_OBJECT (file), thunar_folder_quark); if (G_UNLIKELY (folder != NULL)) { g_object_ref (G_OBJECT (folder)); } else { /* allocate the new instance */ folder = g_object_new (THUNAR_TYPE_FOLDER, NULL); folder->corresponding_file = file; g_object_ref (G_OBJECT (file)); /* drop the floating reference */ exo_gtk_object_ref_sink (GTK_OBJECT (folder)); /* connect the folder to the file */ g_object_set_qdata (G_OBJECT (file), thunar_folder_quark, folder); /* schedule the loading of the folder */ thunar_folder_reload (folder); } return folder; }
static void thunar_location_entry_item_activated (GtkWidget *item, ThunarLocationEntry *location_entry) { ThunarVfsVolume *volume; ThunarFile *file; GtkWidget *window; GError *error = NULL; _thunar_return_if_fail (GTK_IS_MENU_ITEM (item)); _thunar_return_if_fail (THUNAR_IS_LOCATION_ENTRY (location_entry)); /* determine the toplevel window */ window = gtk_widget_get_toplevel (GTK_WIDGET (location_entry)); /* check if the item corresponds to a volume */ volume = g_object_get_data (G_OBJECT (item), "thunar-vfs-volume"); if (G_UNLIKELY (volume != NULL)) { /* check if the volume isn't already mounted */ if (G_LIKELY (!thunar_vfs_volume_is_mounted (volume))) { /* try to mount the volume */ if (!thunar_vfs_volume_mount (volume, window, &error)) { /* display an error dialog to inform the user */ thunar_dialogs_show_error (window, error, _("Failed to mount \"%s\""), thunar_vfs_volume_get_name (volume)); g_error_free (error); return; } } /* try to determine the mount point of the volume */ file = thunar_file_get_for_path (thunar_vfs_volume_get_mount_point (volume), &error); if (G_UNLIKELY (file == NULL)) { /* display an error dialog to inform the user */ thunar_dialogs_show_error (window, error, _("Failed to determine the mount point for %s"), thunar_vfs_volume_get_name (volume)); g_error_free (error); return; } } else { /* determine the file from the item */ file = g_object_get_data (G_OBJECT (item), "thunar-file"); if (G_LIKELY (file != NULL)) g_object_ref (G_OBJECT (file)); } /* check if we have a file object now */ if (G_LIKELY (file != NULL)) { /* make sure that this is actually a directory */ if (thunar_file_is_directory (file)) { /* open the new directory */ thunar_navigator_change_directory (THUNAR_NAVIGATOR (location_entry), file); } /* cleanup */ g_object_unref (G_OBJECT (file)); } }
/** * thunar_dialogs_show_rename_file: * @parent : a #GtkWidget on which the error dialog should be shown, or a #GdkScreen * if no #GtkWidget is known. May also be %NULL, in which case the default * #GdkScreen will be used. * @file : the #ThunarFile we're going to rename. * * Displays the Thunar rename dialog for a single file rename. * * Return value: The #ThunarJob responsible for renaming the file or * %NULL if there was no renaming required. **/ ThunarJob * thunar_dialogs_show_rename_file (gpointer parent, ThunarFile *file) { ThunarIconFactory *icon_factory; GtkIconTheme *icon_theme; const gchar *filename; const gchar *text; ThunarJob *job = NULL; GtkWidget *dialog; GtkWidget *entry; GtkWidget *label; GtkWidget *image; GtkWidget *table; GtkWindow *window; GdkPixbuf *icon; GdkScreen *screen; glong offset; gchar *title; gint response; PangoLayout *layout; gint layout_width; gint layout_offset; gint parent_width = 500; _thunar_return_val_if_fail (parent == NULL || GDK_IS_SCREEN (parent) || GTK_IS_WINDOW (parent), FALSE); _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE); /* parse the parent window and screen */ screen = thunar_util_parse_parent (parent, &window); /* get the filename of the file */ filename = thunar_file_get_display_name (file); /* create a new dialog window */ title = g_strdup_printf (_("Rename \"%s\""), filename); dialog = gtk_dialog_new_with_buttons (title, window, GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, _("_Rename"), GTK_RESPONSE_OK, NULL); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); g_free (title); /* move the dialog to the appropriate screen */ if (G_UNLIKELY (window == NULL && screen != NULL)) gtk_window_set_screen (GTK_WINDOW (dialog), screen); table = g_object_new (GTK_TYPE_TABLE, "border-width", 6, "column-spacing", 6, "row-spacing", 3, NULL); gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), table, TRUE, TRUE, 0); gtk_widget_show (table); icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (dialog)); icon_factory = thunar_icon_factory_get_for_icon_theme (icon_theme); icon = thunar_icon_factory_load_file_icon (icon_factory, file, THUNAR_FILE_ICON_STATE_DEFAULT, 48); g_object_unref (G_OBJECT (icon_factory)); image = gtk_image_new_from_pixbuf (icon); gtk_misc_set_padding (GTK_MISC (image), 6, 6); gtk_table_attach (GTK_TABLE (table), image, 0, 1, 0, 2, GTK_FILL, GTK_FILL, 0, 0); g_object_unref (G_OBJECT (icon)); gtk_widget_show (image); label = gtk_label_new (_("Enter the new name:")); gtk_misc_set_alignment (GTK_MISC (label), 0.0f, 0.5f); gtk_table_attach (GTK_TABLE (table), label, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0); gtk_widget_show (label); entry = gtk_entry_new (); gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE); gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0); gtk_widget_show (entry); /* setup the old filename */ gtk_entry_set_text (GTK_ENTRY (entry), filename); /* check if we don't have a directory here */ if (!thunar_file_is_directory (file)) { /* check if the filename contains an extension */ text = thunar_util_str_get_extension (filename); if (G_LIKELY (text != NULL)) { /* grab focus to the entry first, else the selection will be altered later */ gtk_widget_grab_focus (entry); /* determine the UTF-8 char offset */ offset = g_utf8_pointer_to_offset (filename, text); /* select the text prior to the dot */ if (G_LIKELY (offset > 0)) gtk_editable_select_region (GTK_EDITABLE (entry), 0, offset); } } /* get the size the entry requires to render the full text */ layout = gtk_entry_get_layout (GTK_ENTRY (entry)); pango_layout_get_pixel_size (layout, &layout_width, NULL); gtk_entry_get_layout_offsets (GTK_ENTRY (entry), &layout_offset, NULL); layout_width += (layout_offset * 2) + (12 * 4) + 48; /* 12px free space in entry */ /* parent window width */ if (G_LIKELY (window != NULL)) { /* keep below 90% of the parent window width */ gtk_window_get_size (GTK_WINDOW (window), &parent_width, NULL); parent_width *= 0.90f; } /* resize the dialog to make long names fit as much as possible */ gtk_window_set_default_size (GTK_WINDOW (dialog), CLAMP (layout_width, 300, parent_width), -1); /* run the dialog */ response = gtk_dialog_run (GTK_DIALOG (dialog)); if (G_LIKELY (response == GTK_RESPONSE_OK)) { /* hide the dialog */ gtk_widget_hide (dialog); /* determine the new filename */ text = gtk_entry_get_text (GTK_ENTRY (entry)); /* check if we have a new name here */ if (G_LIKELY (!exo_str_is_equal (filename, text))) { /* try to rename the file */ job = thunar_io_jobs_rename_file (file, text); } } /* cleanup */ gtk_widget_destroy (dialog); return job; }
/** * thunar_dialogs_show_job_ask_replace: * @parent : the parent #GtkWindow or %NULL. * @src_file : the #ThunarFile of the source file. * @dst_file : the #ThunarFile of the destination file that * may be replaced with the source file. * * Asks the user whether to replace the destination file with the * source file identified by @src_file. * * Return value: the selected #ThunarJobResponse. **/ ThunarJobResponse thunar_dialogs_show_job_ask_replace (GtkWindow *parent, ThunarFile *src_file, ThunarFile *dst_file) { ThunarIconFactory *icon_factory; ThunarPreferences *preferences; ThunarDateStyle date_style; GtkIconTheme *icon_theme; GtkWidget *dialog; GtkWidget *table; GtkWidget *image; GtkWidget *label; GdkPixbuf *icon; gchar *date_string; gchar *size_string; gchar *text; gint response; gboolean file_size_binary; _thunar_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), THUNAR_JOB_RESPONSE_CANCEL); _thunar_return_val_if_fail (THUNAR_IS_FILE (src_file), THUNAR_JOB_RESPONSE_CANCEL); _thunar_return_val_if_fail (THUNAR_IS_FILE (dst_file), THUNAR_JOB_RESPONSE_CANCEL); /* determine the style used to format dates */ preferences = thunar_preferences_get (); g_object_get (G_OBJECT (preferences), "misc-date-style", &date_style, NULL); g_object_get (G_OBJECT (preferences), "misc-file-size-binary", &file_size_binary, NULL); g_object_unref (G_OBJECT (preferences)); /* setup the confirmation dialog */ dialog = gtk_dialog_new_with_buttons (_("Confirm to replace files"), parent, GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, _("S_kip All"), THUNAR_JOB_RESPONSE_NO_ALL, _("_Skip"), THUNAR_JOB_RESPONSE_NO, _("Replace _All"), THUNAR_JOB_RESPONSE_YES_ALL, _("_Replace"), THUNAR_JOB_RESPONSE_YES, NULL); gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog), THUNAR_JOB_RESPONSE_YES, THUNAR_JOB_RESPONSE_YES_ALL, THUNAR_JOB_RESPONSE_NO, THUNAR_JOB_RESPONSE_NO_ALL, GTK_RESPONSE_CANCEL, -1); gtk_dialog_set_default_response (GTK_DIALOG (dialog), THUNAR_JOB_RESPONSE_YES); /* determine the icon factory to use */ icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (dialog)); icon_factory = thunar_icon_factory_get_for_icon_theme (icon_theme); table = g_object_new (GTK_TYPE_TABLE, "border-width", 10, "n-columns", 3, "n-rows", 5, "row-spacing", 6, "column-spacing", 5, NULL); gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), table, TRUE, TRUE, 0); gtk_widget_show (table); image = gtk_image_new_from_icon_name ("stock_folder-copy", GTK_ICON_SIZE_BUTTON); gtk_misc_set_alignment (GTK_MISC (image), 0.5f, 0.0f); gtk_misc_set_padding (GTK_MISC (image), 6, 6); gtk_table_attach (GTK_TABLE (table), image, 0, 1, 0, 1, GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); gtk_widget_show (image); if (thunar_file_is_symlink (dst_file)) { text = g_strdup_printf (_("This folder already contains a symbolic link \"%s\"."), thunar_file_get_display_name (dst_file)); } else if (thunar_file_is_directory (dst_file)) { text = g_strdup_printf (_("This folder already contains a folder \"%s\"."), thunar_file_get_display_name (dst_file)); } else { text = g_strdup_printf (_("This folder already contains a file \"%s\"."), thunar_file_get_display_name (dst_file)); } label = gtk_label_new (text); gtk_misc_set_alignment (GTK_MISC (label), 0.0f, 0.5f); gtk_label_set_attributes (GTK_LABEL (label), thunar_pango_attr_list_big ()); gtk_table_attach (GTK_TABLE (table), label, 1, 3, 0, 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0); gtk_widget_show (label); g_free (text); if (thunar_file_is_symlink (dst_file)) text = g_strdup_printf (Q_("ReplaceDialogPart1|Do you want to replace the link")); else if (thunar_file_is_directory (dst_file)) text = g_strdup_printf (Q_("ReplaceDialogPart1|Do you want to replace the existing folder")); else text = g_strdup_printf (Q_("ReplaceDialogPart1|Do you want to replace the existing file")); label = gtk_label_new (text); gtk_misc_set_alignment (GTK_MISC (label), 0.0f, 0.5f); gtk_table_attach (GTK_TABLE (table), label, 1, 3, 1, 2, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0); gtk_widget_show (label); g_free (text); icon = thunar_icon_factory_load_file_icon (icon_factory, dst_file, THUNAR_FILE_ICON_STATE_DEFAULT, 48); image = gtk_image_new_from_pixbuf (icon); gtk_misc_set_padding (GTK_MISC (image), 6, 6); gtk_table_attach (GTK_TABLE (table), image, 1, 2, 2, 3, GTK_FILL, GTK_FILL, 0, 0); g_object_unref (G_OBJECT (icon)); gtk_widget_show (image); size_string = thunar_file_get_size_string_formatted (dst_file, file_size_binary); date_string = thunar_file_get_date_string (dst_file, THUNAR_FILE_DATE_MODIFIED, date_style); text = g_strdup_printf ("%s %s\n%s %s", _("Size:"), size_string, _("Modified:"), date_string); label = gtk_label_new (text); gtk_misc_set_alignment (GTK_MISC (label), 0.0f, 0.5f); gtk_table_attach (GTK_TABLE (table), label, 2, 3, 2, 3, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0); gtk_widget_show (label); g_free (size_string); g_free (date_string); g_free (text); if (thunar_file_is_symlink (src_file)) text = g_strdup_printf (Q_("ReplaceDialogPart2|with the following link?")); else if (thunar_file_is_directory (src_file)) text = g_strdup_printf (Q_("ReplaceDialogPart2|with the following folder?")); else text = g_strdup_printf (Q_("ReplaceDialogPart2|with the following file?")); label = gtk_label_new (text); gtk_misc_set_alignment (GTK_MISC (label), 0.0f, 0.5f); gtk_table_attach (GTK_TABLE (table), label, 1, 3, 3, 4, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0); gtk_widget_show (label); g_free (text); icon = thunar_icon_factory_load_file_icon (icon_factory, src_file, THUNAR_FILE_ICON_STATE_DEFAULT, 48); image = gtk_image_new_from_pixbuf (icon); gtk_misc_set_padding (GTK_MISC (image), 6, 6); gtk_table_attach (GTK_TABLE (table), image, 1, 2, 4, 5, GTK_FILL, GTK_FILL, 0, 0); g_object_unref (G_OBJECT (icon)); gtk_widget_show (image); size_string = thunar_file_get_size_string_formatted (src_file, file_size_binary); date_string = thunar_file_get_date_string (src_file, THUNAR_FILE_DATE_MODIFIED, date_style); text = g_strdup_printf ("%s %s\n%s %s", _("Size:"), size_string, _("Modified:"), date_string); label = gtk_label_new (text); gtk_misc_set_alignment (GTK_MISC (label), 0.0f, 0.5f); gtk_table_attach (GTK_TABLE (table), label, 2, 3, 4, 5, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0); gtk_widget_show (label); g_free (size_string); g_free (date_string); g_free (text); /* run the dialog */ response = gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); /* cleanup */ g_object_unref (G_OBJECT (icon_factory)); /* translate GTK responses */ if (G_UNLIKELY (response < 0)) response = THUNAR_JOB_RESPONSE_CANCEL; return response; }
/** * thunar_dnd_ask: * @widget : the widget on which the drop was performed. * @folder : the #ThunarFile to which the @path_list is being dropped. * @path_list : the #GFile<!---->s of the files being dropped to @file. * @timestamp : the time of the drop event. * @actions : the list of actions supported for the drop. * * Pops up a menu that asks the user to choose one of the * @actions or to cancel the drop. If the user chooses a * valid #GdkDragAction from @actions, then this action is * returned. Else if the user cancels the drop, 0 will be * returned. * * This method can be used to implement a response to the * #GDK_ACTION_ASK action on drops. * * Return value: the selected #GdkDragAction or 0 to cancel. **/ GdkDragAction thunar_dnd_ask (GtkWidget *widget, ThunarFile *folder, GList *path_list, guint timestamp, GdkDragAction dnd_actions) { static const GdkDragAction dnd_action_items[] = { GDK_ACTION_COPY, GDK_ACTION_MOVE, GDK_ACTION_LINK }; static const gchar *dnd_action_names[] = { N_ ("_Copy here"), N_ ("_Move here"), N_ ("_Link here") }; static const gchar *dnd_action_icons[] = { "stock_folder-copy", "stock_folder-move", NULL }; ThunarxProviderFactory *factory; GdkDragAction dnd_action = 0; ThunarFile *file; GtkWidget *window; GtkWidget *image; GtkWidget *menu; GtkWidget *item; GList *file_list = NULL; GList *providers = NULL; GList *actions = NULL; GList *lp; guint n; _thunar_return_val_if_fail (thunar_file_is_directory (folder), 0); _thunar_return_val_if_fail (GTK_IS_WIDGET (widget), 0); /* connect to the provider factory */ factory = thunarx_provider_factory_get_default (); /* prepare the popup menu */ menu = gtk_menu_new (); /* append the various items */ for (n = 0; n < G_N_ELEMENTS (dnd_action_items); ++n) if (G_LIKELY ((dnd_actions & dnd_action_items[n]) != 0)) { item = gtk_image_menu_item_new_with_mnemonic (_(dnd_action_names[n])); g_object_set_data (G_OBJECT (item), I_("dnd-action"), GUINT_TO_POINTER (dnd_action_items[n])); g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (dnd_action_selected), &dnd_action); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); /* add image to the menu item */ if (G_LIKELY (dnd_action_icons[n] != NULL)) { image = gtk_image_new_from_icon_name (dnd_action_icons[n], GTK_ICON_SIZE_MENU); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); } } /* append the separator */ item = gtk_separator_menu_item_new (); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); /* determine the toplevel window the widget belongs to */ window = gtk_widget_get_toplevel (widget); if (G_LIKELY (window != NULL && gtk_widget_get_toplevel (window))) { /* check if we can resolve all paths */ for (lp = path_list; lp != NULL; lp = lp->next) { /* try to resolve this path */ file = thunar_file_cache_lookup (lp->data); if (G_LIKELY (file != NULL)) file_list = g_list_prepend (file_list, file); else break; } /* check if we resolved all paths (and have atleast one file) */ if (G_LIKELY (file_list != NULL && lp == NULL)) { /* load the menu providers from the provider factory */ providers = thunarx_provider_factory_list_providers (factory, THUNARX_TYPE_MENU_PROVIDER); /* load the dnd actions offered by the menu providers */ for (lp = providers; lp != NULL; lp = lp->next) { /* merge the actions from this provider */ actions = g_list_concat (actions, thunarx_menu_provider_get_dnd_actions (lp->data, window, THUNARX_FILE_INFO (folder), file_list)); g_object_unref (G_OBJECT (lp->data)); } g_list_free (providers); /* check if we have atleast one action */ if (G_UNLIKELY (actions != NULL)) { /* add menu items for all actions */ for (lp = actions; lp != NULL; lp = lp->next) { /* add a menu item for the action */ item = gtk_action_create_menu_item (lp->data); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); g_object_unref (G_OBJECT (lp->data)); gtk_widget_show (item); } g_list_free (actions); /* append another separator */ item = gtk_separator_menu_item_new (); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); } } } /* append the cancel item */ item = gtk_image_menu_item_new_from_stock (GTK_STOCK_CANCEL, NULL); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); /* run the menu on the widget's screen (takes over the floating reference of menu) */ thunar_gtk_menu_run (GTK_MENU (menu), widget, NULL, NULL, 3, timestamp); /* cleanup */ g_object_unref (G_OBJECT (factory)); g_list_free_full (file_list, g_object_unref); return dnd_action; }
/** * thunar_dnd_perform: * @widget : the #GtkWidget on which the drop was done. * @file : the #ThunarFile on which the @file_list was dropped. * @file_list : the list of #GFile<!---->s that was dropped. * @action : the #GdkDragAction that was performed. * @new_files_closure : a #GClosure to connect to the job's "new-files" signal, * which will be emitted when the job finishes with the * list of #GFile<!---->s created by the job, or * %NULL if you're not interested in the signal. * * Performs the drop of @file_list on @file in @widget, as given in * @action and returns %TRUE if the drop was started successfully * (or even completed successfully), else %FALSE. * * Return value: %TRUE if the DnD operation was started * successfully, else %FALSE. **/ gboolean thunar_dnd_perform (GtkWidget *widget, ThunarFile *file, GList *file_list, GdkDragAction action, GClosure *new_files_closure) { ThunarApplication *application; gboolean succeed = TRUE; GError *error = NULL; _thunar_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE); _thunar_return_val_if_fail (gtk_widget_get_realized (widget), FALSE); /* query a reference on the application object */ application = thunar_application_get (); /* check if the file is a directory */ if (thunar_file_is_directory (file)) { /* perform the given directory operation */ switch (action) { case GDK_ACTION_COPY: thunar_application_copy_into (application, widget, file_list, thunar_file_get_file (file), new_files_closure); break; case GDK_ACTION_MOVE: thunar_application_move_into (application, widget, file_list, thunar_file_get_file (file), new_files_closure); break; case GDK_ACTION_LINK: thunar_application_link_into (application, widget, file_list, thunar_file_get_file (file), new_files_closure); break; default: succeed = FALSE; } } else if (thunar_file_is_executable (file)) { /* TODO any chance to determine the working dir here? */ succeed = thunar_file_execute (file, NULL, widget, file_list, &error); if (G_UNLIKELY (!succeed)) { /* display an error to the user */ thunar_dialogs_show_error (widget, error, _("Failed to execute file \"%s\""), thunar_file_get_display_name (file)); /* release the error */ g_error_free (error); } } else { succeed = FALSE; } /* release the application reference */ g_object_unref (G_OBJECT (application)); return succeed; }
/** * thunar_dialogs_show_job_ask_replace: * @parent : the parent #GtkWindow or %NULL. * @src_file : the #ThunarFile of the source file. * @dst_file : the #ThunarFile of the destination file that * may be replaced with the source file. * * Asks the user whether to replace the destination file with the * source file identified by @src_file. * * Return value: the selected #ThunarJobResponse. **/ ThunarJobResponse thunar_dialogs_show_job_ask_replace (GtkWindow *parent, ThunarFile *src_file, ThunarFile *dst_file) { ThunarIconFactory *icon_factory; ThunarPreferences *preferences; ThunarDateStyle date_style; GtkIconTheme *icon_theme; GtkWidget *dialog; GtkWidget *grid; GtkWidget *image; GtkWidget *label; GdkPixbuf *icon; gchar *date_custom_style; gchar *date_string; gchar *size_string; gchar *text; gint response; gboolean file_size_binary; _thunar_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), THUNAR_JOB_RESPONSE_CANCEL); _thunar_return_val_if_fail (THUNAR_IS_FILE (src_file), THUNAR_JOB_RESPONSE_CANCEL); _thunar_return_val_if_fail (THUNAR_IS_FILE (dst_file), THUNAR_JOB_RESPONSE_CANCEL); /* determine the style used to format dates */ preferences = thunar_preferences_get (); g_object_get (G_OBJECT (preferences), "misc-date-style", &date_style, NULL); g_object_get (G_OBJECT (preferences), "misc-date-custom-style", &date_custom_style, NULL); g_object_get (G_OBJECT (preferences), "misc-file-size-binary", &file_size_binary, NULL); g_object_unref (G_OBJECT (preferences)); /* setup the confirmation dialog */ dialog = gtk_dialog_new_with_buttons (_("Confirm to replace files"), parent, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, _("_Cancel"), GTK_RESPONSE_CANCEL, _("S_kip All"), THUNAR_JOB_RESPONSE_NO_ALL, _("_Skip"), THUNAR_JOB_RESPONSE_NO, _("Replace _All"), THUNAR_JOB_RESPONSE_YES_ALL, _("_Replace"), THUNAR_JOB_RESPONSE_YES, NULL); gtk_dialog_set_default_response (GTK_DIALOG (dialog), THUNAR_JOB_RESPONSE_YES); /* determine the icon factory to use */ icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (dialog)); icon_factory = thunar_icon_factory_get_for_icon_theme (icon_theme); grid = gtk_grid_new (); gtk_grid_set_column_spacing (GTK_GRID (grid), 5); gtk_grid_set_row_spacing (GTK_GRID (grid), 6); gtk_container_set_border_width (GTK_CONTAINER (grid), 10); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), grid, TRUE, TRUE, 0); gtk_widget_show (grid); image = gtk_image_new_from_icon_name ("stock_folder-copy", GTK_ICON_SIZE_BUTTON); gtk_widget_set_halign (image, GTK_ALIGN_CENTER); gtk_widget_set_valign (image, GTK_ALIGN_START); gtk_widget_set_margin_start (GTK_WIDGET(image), 6); gtk_widget_set_margin_end (GTK_WIDGET(image), 6); gtk_widget_set_margin_top (GTK_WIDGET(image), 6); gtk_widget_set_margin_bottom (GTK_WIDGET(image), 6); gtk_widget_set_vexpand (image, TRUE); gtk_grid_attach (GTK_GRID (grid), image, 0, 0, 1, 1); gtk_widget_show (image); if (thunar_file_is_symlink (dst_file)) { text = g_strdup_printf (_("This folder already contains a symbolic link \"%s\"."), thunar_file_get_display_name (dst_file)); } else if (thunar_file_is_directory (dst_file)) { text = g_strdup_printf (_("This folder already contains a folder \"%s\"."), thunar_file_get_display_name (dst_file)); } else { text = g_strdup_printf (_("This folder already contains a file \"%s\"."), thunar_file_get_display_name (dst_file)); } label = gtk_label_new (text); gtk_label_set_xalign (GTK_LABEL (label), 0.0f); gtk_label_set_attributes (GTK_LABEL (label), thunar_pango_attr_list_big ()); gtk_widget_set_hexpand (label, TRUE); gtk_grid_attach (GTK_GRID (grid), label, 1, 0, 2, 1); gtk_widget_show (label); g_free (text); if (thunar_file_is_symlink (dst_file)) text = g_strdup_printf (Q_("ReplaceDialogPart1|Do you want to replace the link")); else if (thunar_file_is_directory (dst_file)) text = g_strdup_printf (Q_("ReplaceDialogPart1|Do you want to replace the existing folder")); else text = g_strdup_printf (Q_("ReplaceDialogPart1|Do you want to replace the existing file")); label = gtk_label_new (text); gtk_label_set_xalign (GTK_LABEL (label), 0.0f); gtk_widget_set_hexpand (label, TRUE); gtk_grid_attach (GTK_GRID (grid), label, 1, 1, 2, 1); gtk_widget_show (label); g_free (text); icon = thunar_icon_factory_load_file_icon (icon_factory, dst_file, THUNAR_FILE_ICON_STATE_DEFAULT, 48); image = gtk_image_new_from_pixbuf (icon); gtk_widget_set_margin_start (GTK_WIDGET(image), 6); gtk_widget_set_margin_end (GTK_WIDGET(image), 6); gtk_widget_set_margin_top (GTK_WIDGET(image), 6); gtk_widget_set_margin_bottom (GTK_WIDGET(image), 6); gtk_grid_attach (GTK_GRID (grid), image, 1, 2, 1, 1); g_object_unref (G_OBJECT (icon)); gtk_widget_show (image); size_string = thunar_file_get_size_string_long (dst_file, file_size_binary); date_string = thunar_file_get_date_string (dst_file, THUNAR_FILE_DATE_MODIFIED, date_style, date_custom_style); text = g_strdup_printf ("%s %s\n%s %s", _("Size:"), size_string, _("Modified:"), date_string); label = gtk_label_new (text); gtk_label_set_xalign (GTK_LABEL (label), 0.0f); gtk_widget_set_hexpand (label, TRUE); gtk_grid_attach (GTK_GRID (grid), label, 2, 2, 1, 1); gtk_widget_show (label); g_free (size_string); g_free (date_string); g_free (text); if (thunar_file_is_symlink (src_file)) text = g_strdup_printf (Q_("ReplaceDialogPart2|with the following link?")); else if (thunar_file_is_directory (src_file)) text = g_strdup_printf (Q_("ReplaceDialogPart2|with the following folder?")); else text = g_strdup_printf (Q_("ReplaceDialogPart2|with the following file?")); label = gtk_label_new (text); gtk_label_set_xalign (GTK_LABEL (label), 0.0f); gtk_widget_set_hexpand (label, TRUE); gtk_grid_attach (GTK_GRID (grid), label, 1, 3, 2, 1); gtk_widget_show (label); g_free (text); icon = thunar_icon_factory_load_file_icon (icon_factory, src_file, THUNAR_FILE_ICON_STATE_DEFAULT, 48); image = gtk_image_new_from_pixbuf (icon); gtk_widget_set_margin_start (GTK_WIDGET(image), 6); gtk_widget_set_margin_end (GTK_WIDGET(image), 6); gtk_widget_set_margin_top (GTK_WIDGET(image), 6); gtk_widget_set_margin_bottom (GTK_WIDGET(image), 6); gtk_grid_attach (GTK_GRID (grid), image, 1, 4, 1, 1); g_object_unref (G_OBJECT (icon)); gtk_widget_show (image); size_string = thunar_file_get_size_string_long (src_file, file_size_binary); date_string = thunar_file_get_date_string (src_file, THUNAR_FILE_DATE_MODIFIED, date_style, date_custom_style); text = g_strdup_printf ("%s %s\n%s %s", _("Size:"), size_string, _("Modified:"), date_string); label = gtk_label_new (text); gtk_label_set_xalign (GTK_LABEL (label), 0.0f); gtk_widget_set_hexpand (label, TRUE); gtk_grid_attach (GTK_GRID (grid), label, 2, 4, 1, 1); gtk_widget_show (label); g_free (size_string); g_free (date_string); g_free (text); /* run the dialog */ response = gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); /* cleanup */ g_object_unref (G_OBJECT (icon_factory)); /* translate GTK responses */ if (G_UNLIKELY (response < 0)) response = THUNAR_JOB_RESPONSE_CANCEL; return response; }