Commit 9d70c5e6 authored by Victor Ananjevsky's avatar Victor Ananjevsky

Improve thumbnails handling. Add --large-preview option

parent 75af2258
......@@ -966,9 +966,11 @@ is a name of mime type (for example text/plain). This option may be used multipl
Add filter for images supported by gdk-pixbuf library. \fINAME\fP in as optional name for this filter.
.TP
.B \-\-add-preview
Add preview widget. Preview images loads from large or normal thumbnails according to XDG Thumbnails
Add preview widget. Preview images loads from normal (default) or large thumbnails according to XDG Thumbnails
specification v0.8.0 (http://standards.freedesktop.org/thumbnail-spec/latest/) or creates by yad for image files and saves
as large thumbnails.
as normal or large thumbnails.
.TP \--large-preview
Use large previews by default. This option can be permanently turned on througn yad settings.
This options applies to all of yad's file chooser dialogs.
......
......@@ -40,6 +40,10 @@
<default>100</default>
<_summary>Maximum number of tabs in notebook dialog</_summary>
</key>
<key name="large-preview" type="b">
<default>false</default>
<_summary>Use large previews in file selection dialogs</_summary>
</key>
<key name="ignore-unknown-options" type="b">
<default>true</default>
<_summary>Ignore unknown command-line options</_summary>
......
......@@ -209,6 +209,8 @@ static GOptionEntry common_options[] = {
N_("Allow multiple selection"), NULL },
{ "add-preview", 0, 0, G_OPTION_ARG_NONE, &options.common_data.preview,
N_("Enable preview"), NULL },
{ "large-preview", 0, 0, G_OPTION_ARG_NONE, &options.common_data.large_preview,
N_("Use large preview"), NULL },
{ "show-hidden", 0, 0, G_OPTION_ARG_NONE, &options.common_data.show_hidden,
N_("Show hidden files in file selection dialogs"), NULL },
{ "filename", 0, 0, G_OPTION_ARG_FILENAME, &options.common_data.uri,
......@@ -1542,6 +1544,11 @@ yad_options_init (void)
options.common_data.align = 0.0;
options.common_data.listen = FALSE;
options.common_data.preview = FALSE;
#ifndef STANDALONE
options.common_data.large_preview = g_settings_get_boolean (settings, "large-preview");
#else
options.common_data.large_preview = FALSE;
#endif
options.common_data.show_hidden = FALSE;
options.common_data.quoted_output = FALSE;
options.common_data.num_output = FALSE;
......
......@@ -21,6 +21,9 @@
#define _GNU_SOURCE 1
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
......@@ -165,38 +168,60 @@ update_preview (GtkFileChooser * chooser, GtkWidget *p)
{
gchar *file;
GChecksum *chs;
GdkPixbuf *pb;
GdkPixbuf *pb = NULL;
chs = g_checksum_new (G_CHECKSUM_MD5);
g_checksum_update (chs, (const guchar *) uri, -1);
/* first try to get preview from large thumbnail */
file = g_strdup_printf ("%s/%s.png", large_path, g_checksum_get_string (chs));
if (g_file_test (file, G_FILE_TEST_EXISTS))
if (options.common_data.large_preview && g_file_test (file, G_FILE_TEST_EXISTS))
pb = gdk_pixbuf_new_from_file (file, NULL);
else
{
/* try to get preview from normal thumbnail */
g_free (file);
file = g_strdup_printf ("%s/%s.png", normal_path, g_checksum_get_string (chs));
if (g_file_test (file, G_FILE_TEST_EXISTS))
if (!options.common_data.large_preview && g_file_test (file, G_FILE_TEST_EXISTS))
pb = gdk_pixbuf_new_from_file (file, NULL);
else
{
/* try to create it */
g_free (file);
file = g_filename_from_uri (uri, NULL, NULL);
pb = gdk_pixbuf_new_from_file_at_size (file, 256, 256, NULL);
g_free (file);
if (options.common_data.large_preview)
pb = gdk_pixbuf_new_from_file_at_scale (file, 256, 256, TRUE, NULL);
else
pb = gdk_pixbuf_new_from_file_at_scale (file, 128, 128, TRUE, NULL);
if (pb)
{
struct stat st;
gchar *smtime;
stat (file, &st);
smtime = g_strdup_printf ("%d", st.st_mtime);
g_free (file);
/* save thumbnail */
g_mkdir_with_parents (large_path, 0755);
file = g_strdup_printf ("%s/%s.png", large_path, g_checksum_get_string (chs));
gdk_pixbuf_save (pb, file, "png", NULL, NULL);
if (options.common_data.large_preview)
{
g_mkdir_with_parents (large_path, 0755);
file = g_strdup_printf ("%s/%s.png", large_path, g_checksum_get_string (chs));
}
else
{
g_mkdir_with_parents (normal_path, 0755);
file = g_strdup_printf ("%s/%s.png", normal_path, g_checksum_get_string (chs));
}
gdk_pixbuf_save (pb, file, "png", NULL,
"tEXt::Thumb::URI", uri,
"tEXt::Thumb::MTime", smtime,
NULL);
g_free (smtime);
}
}
}
g_checksum_free (chs);
g_free (file);
if (pb)
{
......
......@@ -470,6 +470,7 @@ typedef struct {
gdouble align;
gboolean listen;
gboolean preview;
gboolean large_preview;
gboolean show_hidden;
gboolean quoted_output;
gboolean num_output;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment