From 7e66a54b5bcfd932742775d3306c22fad43d1f5b Mon Sep 17 00:00:00 2001 From: Alexander Schwinn Date: Wed, 13 Jun 2018 23:10:05 +0200 Subject: [PATCH] Add property to enable/disable frames on thumbnails (Bug #14433) --- thunar/thunar-icon-factory.c | 56 ++++++++++++++++++++++++++++++++------ thunar/thunar-preferences-dialog.c | 11 ++++++-- thunar/thunar-preferences.c | 15 ++++++++++ 3 files changed, 72 insertions(+), 10 deletions(-) diff --git a/thunar/thunar-icon-factory.c b/thunar/thunar-icon-factory.c index b9243509..3d7b6644 100644 --- a/thunar/thunar-icon-factory.c +++ b/thunar/thunar-icon-factory.c @@ -49,6 +49,7 @@ enum PROP_0, PROP_ICON_THEME, PROP_THUMBNAIL_MODE, + PROP_THUMBNAIL_DRAW_FRAMES, }; @@ -106,6 +107,8 @@ struct _ThunarIconFactory ThunarThumbnailMode thumbnail_mode; + gboolean thumbnail_draw_frames; + guint sweep_timer_id; gulong changed_hook_id; @@ -182,6 +185,21 @@ thunar_icon_factory_class_init (ThunarIconFactoryClass *klass) THUNAR_TYPE_THUMBNAIL_MODE, THUNAR_THUMBNAIL_MODE_ONLY_LOCAL, EXO_PARAM_READWRITE)); + + /** + * ThunarIconFactory:thumbnail-draw-frames: + * + * Whether to draw black frames around thumbnails. + * This looks neat, but will delay the first draw a bit. + * May have an impact on older systems, on folders with many pictures. + **/ + g_object_class_install_property (gobject_class, + PROP_THUMBNAIL_DRAW_FRAMES, + g_param_spec_boolean ("thumbnail-draw-frames", + "thumbnail-draw-frames", + "thumbnail-draw-frames", + FALSE, + EXO_PARAM_READWRITE)); } @@ -266,6 +284,10 @@ thunar_icon_factory_get_property (GObject *object, g_value_set_enum (value, factory->thumbnail_mode); break; + case PROP_THUMBNAIL_DRAW_FRAMES: + g_value_set_boolean (value, factory->thumbnail_draw_frames); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -288,6 +310,19 @@ thunar_icon_factory_set_property (GObject *object, factory->thumbnail_mode = g_value_get_enum (value); break; + case PROP_THUMBNAIL_DRAW_FRAMES: + if (factory->thumbnail_draw_frames != g_value_get_boolean (value)) + { + factory->thumbnail_draw_frames = g_value_get_boolean (value); + + /* drop all items from the icon cache */ + g_hash_table_remove_all (factory->icon_cache); + + /* bump the stamp so all file icons are reloaded */ + factory->theme_stamp++; + } + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -432,6 +467,8 @@ thunar_icon_factory_load_from_file (ThunarIconFactory *factory, gint width; gint height; + _thunar_return_val_if_fail (THUNAR_IS_ICON_FACTORY (factory), NULL); + /* try to load the image from the file */ pixbuf = gdk_pixbuf_new_from_file (path, NULL); if (G_LIKELY (pixbuf != NULL)) @@ -440,14 +477,15 @@ thunar_icon_factory_load_from_file (ThunarIconFactory *factory, width = gdk_pixbuf_get_width (pixbuf); height = gdk_pixbuf_get_height (pixbuf); - /* check if we want to add a frame to the image (we really don't - * want to do this for icons displayed in the details view). - */ needs_frame = FALSE; - /* Disabled for 1.8.0 release, will be made optional later - * needs_frame = (strstr (path, G_DIR_SEPARATOR_S ".cache/thumbnails" G_DIR_SEPARATOR_S) != NULL) - * && (size >= 32) && thumbnail_needs_frame (pixbuf, width, height); - */ + if( factory->thumbnail_draw_frames ) + { + /* check if we want to add a frame to the image (we really don't + * want to do this for icons displayed in the details view). + * */ + needs_frame = (strstr (path, G_DIR_SEPARATOR_S ".cache/thumbnails" G_DIR_SEPARATOR_S) != NULL) + && (size >= 32) && thumbnail_needs_frame (pixbuf, width, height); + } /* be sure to make framed thumbnails fit into the size */ if (G_LIKELY (needs_frame)) @@ -694,10 +732,12 @@ thunar_icon_factory_get_for_icon_theme (GtkIconTheme *icon_theme) factory->icon_theme = GTK_ICON_THEME (g_object_ref (G_OBJECT (icon_theme))); g_object_set_qdata (G_OBJECT (factory->icon_theme), thunar_icon_factory_quark, factory); - /* connect the "show-thumbnails" property to the global preference */ + /* connect two local properties to the global preferences */ factory->preferences = thunar_preferences_get (); exo_binding_new (G_OBJECT (factory->preferences), "misc-thumbnail-mode", G_OBJECT (factory), "thumbnail-mode"); + exo_binding_new (G_OBJECT (factory->preferences), "misc-thumbnail-draw-frames", + G_OBJECT (factory), "thumbnail-draw-frames"); } else { diff --git a/thunar/thunar-preferences-dialog.c b/thunar/thunar-preferences-dialog.c index dd19f6d0..88f4bf9f 100644 --- a/thunar/thunar-preferences-dialog.c +++ b/thunar/thunar-preferences-dialog.c @@ -296,18 +296,25 @@ thunar_preferences_dialog_init (ThunarPreferencesDialog *dialog) gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo); gtk_widget_show (combo); + button = gtk_check_button_new_with_mnemonic (_("Draw frames around thumbnails")); + exo_mutual_binding_new (G_OBJECT (dialog->preferences), "misc-thumbnail-draw-frames", G_OBJECT (button), "active"); + gtk_widget_set_tooltip_text (button, _("Select this option to draw black frames around thumbnails.")); + gtk_widget_set_hexpand (button, TRUE); + gtk_grid_attach (GTK_GRID (grid), button, 0, 2, 2, 1); + gtk_widget_show (button); + button = gtk_check_button_new_with_mnemonic (_("Sort _folders before files")); exo_mutual_binding_new (G_OBJECT (dialog->preferences), "misc-folders-first", G_OBJECT (button), "active"); gtk_widget_set_tooltip_text (button, _("Select this option to list folders before files when you sort a folder.")); gtk_widget_set_hexpand (button, TRUE); - gtk_grid_attach (GTK_GRID (grid), button, 0, 2, 2, 1); + gtk_grid_attach (GTK_GRID (grid), button, 0, 3, 2, 1); gtk_widget_show (button); button = gtk_check_button_new_with_mnemonic (_("Show file size in binary format")); exo_mutual_binding_new (G_OBJECT (dialog->preferences), "misc-file-size-binary", G_OBJECT (button), "active"); gtk_widget_set_tooltip_text (button, _("Select this option to show file size in binary format instead of decimal.")); gtk_widget_set_hexpand (button, TRUE); - gtk_grid_attach (GTK_GRID (grid), button, 0, 3, 2, 1); + gtk_grid_attach (GTK_GRID (grid), button, 0, 4, 2, 1); gtk_widget_show (button); frame = g_object_new (GTK_TYPE_FRAME, "border-width", 0, "shadow-type", GTK_SHADOW_NONE, NULL); diff --git a/thunar/thunar-preferences.c b/thunar/thunar-preferences.c index db92bf2a..4b3efc2b 100644 --- a/thunar/thunar-preferences.c +++ b/thunar/thunar-preferences.c @@ -90,6 +90,7 @@ enum PROP_MISC_TAB_CLOSE_MIDDLE_CLICK, PROP_MISC_TEXT_BESIDE_ICONS, PROP_MISC_THUMBNAIL_MODE, + PROP_MISC_THUMBNAIL_DRAW_FRAMES, PROP_MISC_FILE_SIZE_BINARY, PROP_SHORTCUTS_ICON_EMBLEMS, PROP_SHORTCUTS_ICON_SIZE, @@ -694,6 +695,20 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass) EXO_PARAM_READWRITE); /** + * ThunarPreferences:misc-thumbnail-draw-frames: + * + * Whether to draw black frames around thumbnails. + * This looks neat, but will delay the first draw a bit. + * May have an impact on older systems, on folders with many pictures. + **/ + preferences_props[PROP_MISC_THUMBNAIL_DRAW_FRAMES] = + g_param_spec_boolean ("misc-thumbnail-draw-frames", + NULL, + NULL, + FALSE, + EXO_PARAM_READWRITE); + + /** * ThunarPreferences:misc-file-size-binary: * * Show file size in binary format instead of decimal. -- 2.11.0