static void thunar_image_update (ThunarImage *image) { ThunarIconFactory *icon_factory; GtkIconTheme *icon_theme; GdkPixbuf *icon; GdkScreen *screen; _thunar_return_if_fail (THUNAR_IS_IMAGE (image)); if (THUNAR_IS_FILE (image->priv->file)) { screen = gtk_widget_get_screen (GTK_WIDGET (image)); icon_theme = gtk_icon_theme_get_for_screen (screen); icon_factory = thunar_icon_factory_get_for_icon_theme (icon_theme); icon = thunar_icon_factory_load_file_icon (icon_factory, image->priv->file, THUNAR_FILE_ICON_STATE_DEFAULT, 48); gtk_image_set_from_pixbuf (GTK_IMAGE (image), icon); g_object_unref (icon_factory); } }
static void thunar_history_show_menu (GtkAction *action, GtkWidget *menu, ThunarHistory *history) { ThunarIconFactory *icon_factory; GtkIconTheme *icon_theme; GCallback handler; GtkWidget *image; GtkWidget *item; GdkPixbuf *icon; GList *lp; guint n; _thunar_return_if_fail (GTK_IS_ACTION (action)); _thunar_return_if_fail (GTK_IS_MENU_SHELL (menu)); _thunar_return_if_fail (THUNAR_IS_HISTORY (history)); /* determine the icon factory to use to load the icons */ icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (menu)); icon_factory = thunar_icon_factory_get_for_icon_theme (icon_theme); /* check if we have "Back" or "Forward" here */ if (action == history->action_back) { /* display the "back" list */ lp = history->back_list; handler = G_CALLBACK (thunar_history_action_back_nth); } else { /* display the "forward" list */ lp = history->forward_list; handler = G_CALLBACK (thunar_history_action_forward_nth); } /* add menu items for all list items */ for (n = 1; lp != NULL; lp = lp->next, ++n) { /* load the icon for the file */ icon = thunar_icon_factory_load_file_icon (icon_factory, lp->data, THUNAR_FILE_ICON_STATE_DEFAULT, 16); /* add an item for this file */ item = gtk_image_menu_item_new_with_label (thunar_file_get_display_name (lp->data)); g_object_set_data (G_OBJECT (item), I_("thunar-history-index"), GUINT_TO_POINTER (n)); g_signal_connect_object (G_OBJECT (item), "activate", handler, history, 0); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); /* setup the image for the file */ image = gtk_image_new_from_pixbuf (icon); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); gtk_widget_show (image); /* release the icon */ g_object_unref (G_OBJECT (icon)); } /* release the icon factory */ g_object_unref (G_OBJECT (icon_factory)); }
static void thunar_location_entry_button_clicked (GtkWidget *button, ThunarLocationEntry *location_entry) { ThunarShortcutsModel *model; ThunarIconFactory *icon_factory; ThunarVfsVolume *volume; GtkIconTheme *icon_theme; const gchar *icon_name; GtkTreeIter iter; ThunarFile *file; GtkWidget *image; GtkWidget *item; GtkWidget *menu; GdkPixbuf *icon; gint icon_size; gint width; _thunar_return_if_fail (THUNAR_IS_LOCATION_ENTRY (location_entry)); _thunar_return_if_fail (GTK_IS_TOGGLE_BUTTON (button)); /* allocate a new menu */ menu = gtk_menu_new (); /* determine the icon theme and factory */ icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (button)); icon_factory = thunar_icon_factory_get_for_icon_theme (icon_theme); /* determine the icon size for menus */ gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &icon_size, &icon_size); /* load the menu items from the shortcuts model */ model = thunar_shortcuts_model_get_default (); if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter)) { do { /* determine the file and volume for the item */ gtk_tree_model_get (GTK_TREE_MODEL (model), &iter, THUNAR_SHORTCUTS_MODEL_COLUMN_FILE, &file, THUNAR_SHORTCUTS_MODEL_COLUMN_VOLUME, &volume, -1); /* check if we have a separator here */ if (G_UNLIKELY (file == NULL && volume == NULL)) { /* generate a separator the menu */ item = gtk_separator_menu_item_new (); } else if (G_UNLIKELY (volume != NULL)) { /* generate an image menu item for the volume */ item = gtk_image_menu_item_new_with_label (thunar_vfs_volume_get_name (volume)); /* load the icon for the volume */ icon_name = thunar_vfs_volume_lookup_icon_name (volume, icon_theme); icon = thunar_icon_factory_load_icon (icon_factory, icon_name, icon_size, NULL, FALSE); if (G_LIKELY (icon != NULL)) { /* generate an image for the menu item */ image = gtk_image_new_from_pixbuf (icon); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); g_object_unref (G_OBJECT (icon)); gtk_widget_show (image); } } else { /* generate an image menu item for the file */ item = gtk_image_menu_item_new_with_label (thunar_file_get_display_name (file)); /* load the icon for the file and generate the image for the menu item */ icon = thunar_icon_factory_load_file_icon (icon_factory, file, THUNAR_FILE_ICON_STATE_DEFAULT, icon_size); image = gtk_image_new_from_pixbuf (icon); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); g_object_unref (G_OBJECT (icon)); gtk_widget_show (image); } /* connect the file and volume to the item */ g_object_set_data_full (G_OBJECT (item), I_("thunar-vfs-volume"), volume, g_object_unref); g_object_set_data_full (G_OBJECT (item), I_("thunar-file"), file, g_object_unref); /* append the new item to the menu */ g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (thunar_location_entry_item_activated), location_entry); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter)); } /* make sure the menu has atleast the same width as the location entry */ width = GTK_WIDGET (location_entry)->allocation.width - 2 * gtk_container_get_border_width (GTK_CONTAINER (location_entry)); if (G_LIKELY (menu->allocation.width < width)) gtk_widget_set_size_request (menu, width, -1); /* select the first visible or selectable item in the menu */ gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), TRUE); /* enable the button, making sure that we do not recurse on the "clicked" signal by temporarily blocking the handler */ g_signal_handlers_block_by_func (G_OBJECT (button), G_CALLBACK (thunar_location_entry_button_clicked), location_entry); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); g_signal_handlers_unblock_by_func (G_OBJECT (button), G_CALLBACK (thunar_location_entry_button_clicked), location_entry); /* run the menu, taking ownership over the menu object */ thunar_gtk_menu_run (GTK_MENU (menu), button, menu_position, location_entry, 1, gtk_get_current_event_time ()); /* disable the button, making sure that we do not recurse on the "clicked" signal by temporarily blocking the handler */ g_signal_handlers_block_by_func (G_OBJECT (button), G_CALLBACK (thunar_location_entry_button_clicked), location_entry); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE); g_signal_handlers_unblock_by_func (G_OBJECT (button), G_CALLBACK (thunar_location_entry_button_clicked), location_entry); /* clean up */ g_object_unref (G_OBJECT (icon_factory)); g_object_unref (G_OBJECT (model)); }
/** * 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; }
static void thunar_icon_renderer_render (GtkCellRenderer *renderer, GdkWindow *window, GtkWidget *widget, GdkRectangle *background_area, GdkRectangle *cell_area, GdkRectangle *expose_area, GtkCellRendererState flags) { ThunarClipboardManager *clipboard; ThunarFileIconState icon_state; ThunarIconRenderer *icon_renderer = THUNAR_ICON_RENDERER (renderer); ThunarIconFactory *icon_factory; GtkIconSource *icon_source; GtkIconTheme *icon_theme; GdkRectangle emblem_area; GdkRectangle icon_area; GdkRectangle draw_area; GtkStateType state; GdkPixbuf *emblem; GdkPixbuf *icon; GdkPixbuf *temp; GList *emblems; GList *lp; gint max_emblems; gint position; if (G_UNLIKELY (icon_renderer->file == NULL)) return; /* determine the icon state */ icon_state = (icon_renderer->drop_file != icon_renderer->file) ? renderer->is_expanded ? THUNAR_FILE_ICON_STATE_OPEN : THUNAR_FILE_ICON_STATE_DEFAULT : THUNAR_FILE_ICON_STATE_DROP; /* load the main icon */ icon_theme = gtk_icon_theme_get_for_screen (gdk_drawable_get_screen (window)); icon_factory = thunar_icon_factory_get_for_icon_theme (icon_theme); icon = thunar_icon_factory_load_file_icon (icon_factory, icon_renderer->file, icon_state, icon_renderer->size); if (G_UNLIKELY (icon == NULL)) { g_object_unref (G_OBJECT (icon_factory)); return; } /* pre-light the item if we're dragging about it */ if (G_UNLIKELY (icon_state == THUNAR_FILE_ICON_STATE_DROP)) flags |= GTK_CELL_RENDERER_PRELIT; /* determine the real icon size */ icon_area.width = gdk_pixbuf_get_width (icon); icon_area.height = gdk_pixbuf_get_height (icon); /* scale down the icon on-demand */ if (G_UNLIKELY (icon_area.width > cell_area->width || icon_area.height > cell_area->height)) { /* scale down to fit */ temp = exo_gdk_pixbuf_scale_down (icon, TRUE, cell_area->width, cell_area->height); g_object_unref (G_OBJECT (icon)); icon = temp; /* determine the icon dimensions again */ icon_area.width = gdk_pixbuf_get_width (icon); icon_area.height = gdk_pixbuf_get_height (icon); } icon_area.x = cell_area->x + (cell_area->width - icon_area.width) / 2; icon_area.y = cell_area->y + (cell_area->height - icon_area.height) / 2; /* check whether the icon is affected by the expose event */ if (gdk_rectangle_intersect (expose_area, &icon_area, &draw_area)) { /* use a translucent icon to represent cutted and hidden files to the user */ clipboard = thunar_clipboard_manager_get_for_display (gtk_widget_get_display (widget)); if (thunar_clipboard_manager_has_cutted_file (clipboard, icon_renderer->file)) { /* 50% translucent for cutted files */ temp = exo_gdk_pixbuf_lucent (icon, 50); g_object_unref (G_OBJECT (icon)); icon = temp; } else if (thunar_file_is_hidden (icon_renderer->file)) { /* 75% translucent for hidden files */ temp = exo_gdk_pixbuf_lucent (icon, 75); g_object_unref (G_OBJECT (icon)); icon = temp; } g_object_unref (G_OBJECT (clipboard)); /* colorize the icon if we should follow the selection state */ if ((flags & (GTK_CELL_RENDERER_SELECTED | GTK_CELL_RENDERER_PRELIT)) != 0 && icon_renderer->follow_state) { if ((flags & GTK_CELL_RENDERER_SELECTED) != 0) { state = GTK_WIDGET_HAS_FOCUS (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE; temp = exo_gdk_pixbuf_colorize (icon, &widget->style->base[state]); g_object_unref (G_OBJECT (icon)); icon = temp; } if ((flags & GTK_CELL_RENDERER_PRELIT) != 0) { temp = exo_gdk_pixbuf_spotlight (icon); g_object_unref (G_OBJECT (icon)); icon = temp; } } /* check if we should render an insensitive icon */ if (G_UNLIKELY (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE || !renderer->sensitive)) { /* allocate an icon source */ icon_source = gtk_icon_source_new (); gtk_icon_source_set_pixbuf (icon_source, icon); gtk_icon_source_set_size_wildcarded (icon_source, FALSE); gtk_icon_source_set_size (icon_source, GTK_ICON_SIZE_SMALL_TOOLBAR); /* render the insensitive icon */ temp = gtk_style_render_icon (widget->style, icon_source, gtk_widget_get_direction (widget), GTK_STATE_INSENSITIVE, -1, widget, "gtkcellrendererpixbuf"); g_object_unref (G_OBJECT (icon)); icon = temp; /* release the icon source */ gtk_icon_source_free (icon_source); } /* render the invalid parts of the icon */ gdk_draw_pixbuf (window, widget->style->black_gc, icon, draw_area.x - icon_area.x, draw_area.y - icon_area.y, draw_area.x, draw_area.y, draw_area.width, draw_area.height, GDK_RGB_DITHER_NORMAL, 0, 0); } /* release the file's icon */ g_object_unref (G_OBJECT (icon)); /* check if we should render emblems as well */ if (G_LIKELY (icon_renderer->emblems)) { /* display the primary emblem as well (if any) */ emblems = thunar_file_get_emblem_names (icon_renderer->file); if (G_UNLIKELY (emblems != NULL)) { /* render up to four emblems for sizes from 48 onwards, else up to 2 emblems */ max_emblems = (icon_renderer->size < 48) ? 2 : 4; /* render the emblems */ for (lp = emblems, position = 0; lp != NULL && position < max_emblems; lp = lp->next) { /* check if we have the emblem in the icon theme */ emblem = thunar_icon_factory_load_icon (icon_factory, lp->data, icon_renderer->size, NULL, FALSE); if (G_UNLIKELY (emblem == NULL)) continue; /* determine the dimensions of the emblem */ emblem_area.width = gdk_pixbuf_get_width (emblem); emblem_area.height = gdk_pixbuf_get_height (emblem); /* shrink insane emblems */ if (G_UNLIKELY (MAX (emblem_area.width, emblem_area.height) > (gint) MIN ((2 * icon_renderer->size) / 3, 36))) { /* scale down the emblem */ temp = exo_gdk_pixbuf_scale_ratio (emblem, MIN ((2 * icon_renderer->size) / 3, 36)); g_object_unref (G_OBJECT (emblem)); emblem = temp; /* determine the size again */ emblem_area.width = gdk_pixbuf_get_width (emblem); emblem_area.height = gdk_pixbuf_get_height (emblem); } /* determine a good position for the emblem, depending on the position index */ switch (position) { case 0: /* right/bottom */ emblem_area.x = MIN (icon_area.x + icon_area.width - emblem_area.width / 2, cell_area->x + cell_area->width - emblem_area.width); emblem_area.y = MIN (icon_area.y + icon_area.height - emblem_area.height / 2, cell_area->y + cell_area->height -emblem_area.height); break; case 1: /* left/bottom */ emblem_area.x = MAX (icon_area.x - emblem_area.width / 2, cell_area->x); emblem_area.y = MIN (icon_area.y + icon_area.height - emblem_area.height / 2, cell_area->y + cell_area->height -emblem_area.height); break; case 2: /* left/top */ emblem_area.x = MAX (icon_area.x - emblem_area.width / 2, cell_area->x); emblem_area.y = MAX (icon_area.y - emblem_area.height / 2, cell_area->y); break; case 3: /* right/top */ emblem_area.x = MIN (icon_area.x + icon_area.width - emblem_area.width / 2, cell_area->x + cell_area->width - emblem_area.width); emblem_area.y = MAX (icon_area.y - emblem_area.height / 2, cell_area->y); break; default: _thunar_assert_not_reached (); } /* render the emblem */ if (gdk_rectangle_intersect (expose_area, &emblem_area, &draw_area)) { gdk_draw_pixbuf (window, widget->style->black_gc, emblem, draw_area.x - emblem_area.x, draw_area.y - emblem_area.y, draw_area.x, draw_area.y, draw_area.width, draw_area.height, GDK_RGB_DITHER_NORMAL, 0, 0); } /* release the emblem */ g_object_unref (G_OBJECT (emblem)); /* advance the position index */ ++position; } /* release the emblem name list */ g_list_free (emblems); } } /* release our reference on the icon factory */ g_object_unref (G_OBJECT (icon_factory)); }
/** * 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; }