[gthumb] thumbnailer: added support for larger sizes
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] thumbnailer: added support for larger sizes
- Date: Sun, 3 Apr 2022 08:27:34 +0000 (UTC)
commit a691507086965a8217f3612e8c3e45871217b11c
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sun Apr 3 10:23:36 2022 +0200
thumbnailer: added support for larger sizes
Fixes #41
data/ui/browser-preferences.ui | 101 ++++++++++++++++++++-------------------
gthumb/dlg-preferences-browser.c | 2 +-
gthumb/gnome-desktop-thumbnail.c | 65 ++++++++++++++++++++-----
gthumb/gnome-desktop-thumbnail.h | 6 ++-
gthumb/gth-thumb-loader.c | 12 +----
5 files changed, 114 insertions(+), 72 deletions(-)
---
diff --git a/data/ui/browser-preferences.ui b/data/ui/browser-preferences.ui
index 348d2491..648452ac 100644
--- a/data/ui/browser-preferences.ui
+++ b/data/ui/browser-preferences.ui
@@ -1,24 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.22.1 -->
+<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkBox" id="browser_page">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">20</property>
<child>
<object class="GtkBox" id="box2">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="label" translatable="yes">Caption</property>
- <property name="use_markup">True</property>
+ <property name="use-markup">True</property>
<property name="xalign">0</property>
<attributes>
<attribute name="weight" value="bold"/>
@@ -33,9 +33,9 @@
<child>
<object class="GtkScrolledWindow" id="caption_scrolledwindow">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="margin_left">12</property>
- <property name="shadow_type">in</property>
+ <property name="can-focus">True</property>
+ <property name="margin-left">12</property>
+ <property name="shadow-type">in</property>
<child>
<placeholder/>
</child>
@@ -56,15 +56,15 @@
<child>
<object class="GtkBox" id="box4">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="label" translatable="yes">Behavior</property>
- <property name="use_markup">True</property>
+ <property name="use-markup">True</property>
<property name="xalign">0</property>
<attributes>
<attribute name="weight" value="bold"/>
@@ -79,19 +79,19 @@
<child>
<object class="GtkBox" id="box5">
<property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="margin_left">12</property>
+ <property name="can-focus">False</property>
+ <property name="margin-left">12</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkRadioButton" id="single_click_radiobutton">
<property name="label" translatable="yes">_Single click to open files</property>
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="use_underline">True</property>
+ <property name="can-focus">True</property>
+ <property name="receives-default">False</property>
+ <property name="use-underline">True</property>
<property name="active">True</property>
- <property name="draw_indicator">True</property>
+ <property name="draw-indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
@@ -103,11 +103,11 @@
<object class="GtkRadioButton" id="double_click_radiobutton">
<property name="label" translatable="yes">_Double click to open files</property>
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="use_underline">True</property>
+ <property name="can-focus">True</property>
+ <property name="receives-default">False</property>
+ <property name="use-underline">True</property>
<property name="active">True</property>
- <property name="draw_indicator">True</property>
+ <property name="draw-indicator">True</property>
<property name="group">single_click_radiobutton</property>
</object>
<packing>
@@ -120,10 +120,10 @@
<object class="GtkCheckButton" id="open_in_fullscreen_checkbutton">
<property name="label" translatable="yes">_Open files in fullscreen mode</property>
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="use_underline">True</property>
- <property name="draw_indicator">True</property>
+ <property name="can-focus">True</property>
+ <property name="receives-default">False</property>
+ <property name="use-underline">True</property>
+ <property name="draw-indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
@@ -148,15 +148,15 @@
<child>
<object class="GtkBox" id="box3">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="label8">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="label" translatable="yes">Other</property>
- <property name="use_markup">True</property>
+ <property name="use-markup">True</property>
<property name="xalign">0</property>
<attributes>
<attribute name="weight" value="bold"/>
@@ -171,22 +171,22 @@
<child>
<object class="GtkBox" id="box1">
<property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="margin_left">12</property>
+ <property name="can-focus">False</property>
+ <property name="margin-left">12</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkBox" id="box7">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="label9">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="label" translatable="yes">Thumbnail _size:</property>
- <property name="use_underline">True</property>
- <property name="mnemonic_widget">thumbnail_size_combobox</property>
+ <property name="use-underline">True</property>
+ <property name="mnemonic-widget">thumbnail_size_combobox</property>
</object>
<packing>
<property name="expand">False</property>
@@ -197,21 +197,24 @@
<child>
<object class="GtkBox" id="thumbnail_size_box">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<child>
<object class="GtkComboBoxText" id="thumbnail_size_combobox">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<items>
- <item translatable="yes">48</item>
- <item translatable="yes">64</item>
- <item translatable="yes">85</item>
- <item translatable="yes">95</item>
- <item translatable="yes">112</item>
- <item translatable="yes">128</item>
- <item translatable="yes">164</item>
- <item translatable="yes">200</item>
- <item translatable="yes">256</item>
+ <item>48</item>
+ <item>64</item>
+ <item>85</item>
+ <item>95</item>
+ <item>112</item>
+ <item>128</item>
+ <item>164</item>
+ <item>200</item>
+ <item>256</item>
+ <item>512</item>
+ <item>768</item>
+ <item>1024</item>
</items>
</object>
<packing>
@@ -238,10 +241,10 @@
<object class="GtkCheckButton" id="slow_mime_type_checkbutton">
<property name="label" translatable="yes">D_etermine image type from content
(slower)</property>
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="use_underline">True</property>
- <property name="draw_indicator">True</property>
+ <property name="can-focus">True</property>
+ <property name="receives-default">False</property>
+ <property name="use-underline">True</property>
+ <property name="draw-indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
diff --git a/gthumb/dlg-preferences-browser.c b/gthumb/dlg-preferences-browser.c
index 55e9cca4..7f404b38 100644
--- a/gthumb/dlg-preferences-browser.c
+++ b/gthumb/dlg-preferences-browser.c
@@ -44,7 +44,7 @@ typedef struct {
} BrowserData;
-static int thumb_size[] = { 48, 64, 85, 95, 112, 128, 164, 200, 256 };
+static int thumb_size[] = { 48, 64, 85, 95, 112, 128, 164, 200, 256, 512, 768, 1024 };
static int thumb_sizes = sizeof (thumb_size) / sizeof (int);
diff --git a/gthumb/gnome-desktop-thumbnail.c b/gthumb/gnome-desktop-thumbnail.c
index 01e21cf3..ec491d57 100644
--- a/gthumb/gnome-desktop-thumbnail.c
+++ b/gthumb/gnome-desktop-thumbnail.c
@@ -424,6 +424,40 @@ get_thumbnailers_dirs (void)
return g_once (&once_init, init_thumbnailers_dirs, NULL);
}
+static const char *
+gnome_desktop_thumbnail_size_to_dirname (GnomeDesktopThumbnailSize size)
+{
+ switch (size) {
+ case GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL:
+ return "normal";
+ case GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE:
+ return "large";
+ case GNOME_DESKTOP_THUMBNAIL_SIZE_XLARGE:
+ return "x-large";
+ case GNOME_DESKTOP_THUMBNAIL_SIZE_XXLARGE:
+ return "xx-large";
+ default:
+ g_assert_not_reached ();
+ }
+}
+
+guint
+gnome_desktop_thumbnail_size_to_size (GnomeDesktopThumbnailSize size)
+{
+ switch (size) {
+ case GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL:
+ return 128;
+ case GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE:
+ return 256;
+ case GNOME_DESKTOP_THUMBNAIL_SIZE_XLARGE:
+ return 512;
+ case GNOME_DESKTOP_THUMBNAIL_SIZE_XXLARGE:
+ return 1024;
+ default:
+ g_assert_not_reached ();
+ }
+}
+
/* These should be called with the lock held */
static void
@@ -909,9 +943,9 @@ gnome_desktop_thumbnail_factory_lookup (GnomeDesktopThumbnailFactory *factory,
file = g_strconcat (g_checksum_get_string (checksum), ".png", NULL);
path = thumbnail_factory_build_filename (factory,
- (factory->priv->size ==
GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL)?"normal":"large",
- file,
- NULL);
+ gnome_desktop_thumbnail_size_to_dirname
(factory->priv->size),
+ file,
+ NULL);
if (! gnome_desktop_thumbnail_is_valid (path, uri, mtime)) {
g_free (path);
@@ -1061,9 +1095,7 @@ gnome_desktop_thumbnail_factory_generate_no_script (GnomeDesktopThumbnailFactory
/* Doesn't access any volatile fields in factory, so it's threadsafe */
- size = 128;
- if (factory->priv->size == GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE)
- size = 256;
+ size = gnome_desktop_thumbnail_size_to_size (factory->priv->size);
/* Check for preview::icon first */
pixbuf = _gdk_pixbuf_new_from_uri_at_scale (uri, size, size, TRUE, TRUE, cancellable);
@@ -1166,9 +1198,7 @@ gnome_desktop_thumbnail_factory_generate_from_script (GnomeDesktopThumbnailFacto
g_return_val_if_fail (uri != NULL, FALSE);
g_return_val_if_fail (mime_type != NULL, FALSE);
- size = 128;
- if (factory->priv->size == GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE)
- size = 256;
+ size = gnome_desktop_thumbnail_size_to_size (factory->priv->size);
script = NULL;
g_mutex_lock (&factory->priv->lock);
@@ -1246,7 +1276,7 @@ make_thumbnail_dirs (GnomeDesktopThumbnailFactory *factory)
}
image_dir = g_build_filename (thumbnail_dir,
- (factory->priv->size == GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL)?"normal":"large",
+ gnome_desktop_thumbnail_size_to_dirname (factory->priv->size),
NULL);
if (!g_file_test (image_dir, G_FILE_TEST_IS_DIR))
{
@@ -1342,7 +1372,7 @@ gnome_desktop_thumbnail_factory_save_thumbnail (GnomeDesktopThumbnailFactory *fa
file = g_strconcat (g_checksum_get_string (checksum), ".png", NULL);
path = thumbnail_factory_build_filename (factory,
- (priv->size == GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL ? "normal" :
"large"),
+ gnome_desktop_thumbnail_size_to_dirname (priv->size),
file,
NULL);
@@ -1644,3 +1674,16 @@ gnome_desktop_thumbnail_is_valid (const char *thumbnail_filename,
return is_valid;
}
+
+
+GnomeDesktopThumbnailSize
+gnome_desktop_thumbnail_size_for_size (int size)
+{
+ if (size <= 128)
+ return GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL;
+ if (size <= 256)
+ return GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE;
+ if (size <= 512)
+ return GNOME_DESKTOP_THUMBNAIL_SIZE_XLARGE;
+ return GNOME_DESKTOP_THUMBNAIL_SIZE_XXLARGE;
+}
diff --git a/gthumb/gnome-desktop-thumbnail.h b/gthumb/gnome-desktop-thumbnail.h
index e02f1e91..0f779e51 100644
--- a/gthumb/gnome-desktop-thumbnail.h
+++ b/gthumb/gnome-desktop-thumbnail.h
@@ -55,7 +55,9 @@ G_BEGIN_DECLS
typedef enum {
GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL,
- GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE
+ GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE,
+ GNOME_DESKTOP_THUMBNAIL_SIZE_XLARGE,
+ GNOME_DESKTOP_THUMBNAIL_SIZE_XXLARGE,
} GnomeDesktopThumbnailSize;
#define GNOME_DESKTOP_TYPE_THUMBNAIL_FACTORY (gnome_desktop_thumbnail_factory_get_type ())
@@ -114,6 +116,8 @@ char * gnome_desktop_thumbnail_md5 (const char *uri);
gboolean gnome_desktop_thumbnail_is_valid (const char *thumbnail_filename,
const char *uri,
time_t mtime);
+GnomeDesktopThumbnailSize gnome_desktop_thumbnail_size_for_size (int size);
+guint gnome_desktop_thumbnail_size_to_size (GnomeDesktopThumbnailSize size);
/* Pixbuf utils */
diff --git a/gthumb/gth-thumb-loader.c b/gthumb/gth-thumb-loader.c
index 47885772..074c4174 100644
--- a/gthumb/gth-thumb-loader.c
+++ b/gthumb/gth-thumb-loader.c
@@ -44,8 +44,6 @@
#include "pixbuf-utils.h"
#include "typedefs.h"
-#define THUMBNAIL_LARGE_SIZE 256
-#define THUMBNAIL_NORMAL_SIZE 128
#define THUMBNAIL_DIR_PERMISSIONS 0700
#define MAX_THUMBNAILER_LIFETIME 4000 /* kill the thumbnailer after this amount of time*/
#define CHECK_CANCELLABLE_DELAY 200
@@ -296,14 +294,8 @@ gth_thumb_loader_set_requested_size (GthThumbLoader *self,
GnomeDesktopThumbnailSize thumb_size;
self->priv->requested_size = size;
- if (self->priv->requested_size <= THUMBNAIL_NORMAL_SIZE) {
- self->priv->cache_max_size = THUMBNAIL_NORMAL_SIZE;
- thumb_size = GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL;
- }
- else {
- self->priv->cache_max_size = THUMBNAIL_LARGE_SIZE;
- thumb_size = GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE;
- }
+ thumb_size = gnome_desktop_thumbnail_size_for_size (size);
+ self->priv->cache_max_size = gnome_desktop_thumbnail_size_to_size (thumb_size);
if ((self->priv->thumb_size != thumb_size) || (self->priv->thumb_factory == NULL)) {
self->priv->thumb_size = thumb_size;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]