[tracker/max-media-art-width] tracker-extract: Added 'max-media-art-width' config option
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/max-media-art-width] tracker-extract: Added 'max-media-art-width' config option
- Date: Mon, 30 Apr 2012 14:23:50 +0000 (UTC)
commit bfabdb424d68dbffa7cc05a4de456a2a62437fa3
Author: Martyn Russell <martyn lanedo com>
Date: Mon Apr 30 15:21:44 2012 +0100
tracker-extract: Added 'max-media-art-width' config option
Allows all media/album art to be disabled with a setting of -1 or resized to a
width of choosing.
Based on the patch from Kiran Bhide <kiran bhide in bosch com>
.../org.freedesktop.Tracker.Extract.gschema.xml.in | 7 ++
src/tracker-extract/tracker-config.c | 45 ++++++++++++++-
src/tracker-extract/tracker-config.h | 25 +++++----
src/tracker-extract/tracker-media-art-pixbuf.c | 60 +++++++++++++++++---
src/tracker-extract/tracker-media-art-qt.cpp | 27 ++++++++-
5 files changed, 140 insertions(+), 24 deletions(-)
---
diff --git a/data/gschemas/org.freedesktop.Tracker.Extract.gschema.xml.in b/data/gschemas/org.freedesktop.Tracker.Extract.gschema.xml.in
index ea20021..17c2456 100644
--- a/data/gschemas/org.freedesktop.Tracker.Extract.gschema.xml.in
+++ b/data/gschemas/org.freedesktop.Tracker.Extract.gschema.xml.in
@@ -41,5 +41,12 @@ Boston, MA 02110-1301, USA.
<range min="0" max="10485760"/>
<default>1048576</default>
</key>
+
+ <key name="max-media-art-width" type="i">
+ <_summary>Max media art width</_summary>
+ <_description>Maximum width in pixels for any media art extracted. Anything bigger is resized. Set to -1 to disable saving media art from files. Setting to 0 sets no limit on the media art width.</_description>
+ <range min="-1" max="2048"/>
+ <default>0</default>
+ </key>
</schema>
</schemalist>
diff --git a/src/tracker-extract/tracker-config.c b/src/tracker-extract/tracker-config.c
index c16059a..e3e2a4d 100644
--- a/src/tracker-extract/tracker-config.c
+++ b/src/tracker-extract/tracker-config.c
@@ -40,13 +40,15 @@ enum {
PROP_0,
PROP_VERBOSITY,
PROP_SCHED_IDLE,
- PROP_MAX_BYTES
+ PROP_MAX_BYTES,
+ PROP_MAX_MEDIA_ART_WIDTH
};
static TrackerConfigMigrationEntry migration[] = {
{ G_TYPE_ENUM, "General", "Verbosity", "verbosity" },
{ G_TYPE_ENUM, "General", "SchedIdle", "sched-idle" },
{ G_TYPE_INT, "General", "MaxBytes", "max-bytes" },
+ { G_TYPE_INT, "General", "MaxMediaArtWidth", "max-media-art-width" },
{ 0 }
};
@@ -88,6 +90,16 @@ tracker_config_class_init (TrackerConfigClass *klass)
0, 1024 * 1024 * 10,
1024 * 1024,
G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class,
+ PROP_MAX_MEDIA_ART_WIDTH,
+ g_param_spec_int ("max-media-art-width",
+ "Max Media Art Width",
+ " Maximum width of the Media Art to be generated (-1=disable, 0=original width, 1->2048=max pixel width)",
+ -1,
+ 2048,
+ 0,
+ G_PARAM_READWRITE));
}
static void
@@ -117,6 +129,11 @@ config_set_property (GObject *object,
g_value_get_int (value));
break;
+ case PROP_MAX_MEDIA_ART_WIDTH:
+ g_settings_set_int (G_SETTINGS (object), "max-media-art-width",
+ g_value_get_int (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -145,6 +162,11 @@ config_get_property (GObject *object,
g_settings_get_int (G_SETTINGS (object), "max-bytes"));
break;
+ case PROP_MAX_MEDIA_ART_WIDTH:
+ g_value_set_int (value,
+ g_settings_get_int (G_SETTINGS (object), "max-media-art-width"));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -248,3 +270,24 @@ tracker_config_set_max_bytes (TrackerConfig *config,
g_object_set (G_OBJECT (config), "max-bytes", value, NULL);
}
+
+gint
+tracker_config_get_max_media_art_width (TrackerConfig *config)
+{
+ gint max_media_art_width;
+
+ g_return_val_if_fail (TRACKER_IS_CONFIG (config), 0);
+
+ g_object_get (config, "max-media-art-width", &max_media_art_width, NULL);
+
+ return max_media_art_width;
+}
+
+void
+tracker_config_set_max_media_art_width (TrackerConfig *config,
+ gint value)
+{
+ g_return_if_fail (TRACKER_IS_CONFIG (config));
+
+ g_object_set (G_OBJECT (config), "max-media-art-width", value, NULL);
+}
diff --git a/src/tracker-extract/tracker-config.h b/src/tracker-extract/tracker-config.h
index 5ccc717..725bef2 100644
--- a/src/tracker-extract/tracker-config.h
+++ b/src/tracker-extract/tracker-config.h
@@ -45,18 +45,21 @@ struct TrackerConfigClass {
GSettingsClass parent_class;
};
-GType tracker_config_get_type (void) G_GNUC_CONST;
+GType tracker_config_get_type (void) G_GNUC_CONST;
-TrackerConfig *tracker_config_new (void);
-gint tracker_config_get_verbosity (TrackerConfig *config);
-gint tracker_config_get_sched_idle (TrackerConfig *config);
-gint tracker_config_get_max_bytes (TrackerConfig *config);
-void tracker_config_set_verbosity (TrackerConfig *config,
- gint value);
-void tracker_config_set_sched_idle (TrackerConfig *config,
- gint value);
-void tracker_config_set_max_bytes (TrackerConfig *config,
- gint value);
+TrackerConfig *tracker_config_new (void);
+gint tracker_config_get_verbosity (TrackerConfig *config);
+gint tracker_config_get_sched_idle (TrackerConfig *config);
+gint tracker_config_get_max_bytes (TrackerConfig *config);
+gint tracker_config_get_max_media_art_width (TrackerConfig *config);
+void tracker_config_set_verbosity (TrackerConfig *config,
+ gint value);
+void tracker_config_set_sched_idle (TrackerConfig *config,
+ gint value);
+void tracker_config_set_max_bytes (TrackerConfig *config,
+ gint value);
+void tracker_config_set_max_media_art_width (TrackerConfig *config,
+ gint value);
G_END_DECLS
diff --git a/src/tracker-extract/tracker-media-art-pixbuf.c b/src/tracker-extract/tracker-media-art-pixbuf.c
index 46b40f9..3ed7684 100644
--- a/src/tracker-extract/tracker-media-art-pixbuf.c
+++ b/src/tracker-extract/tracker-media-art-pixbuf.c
@@ -24,6 +24,8 @@
#include "tracker-media-art-generic.h"
+#include "tracker-main.h"
+
void
tracker_media_art_plugin_init (void)
{
@@ -40,6 +42,15 @@ tracker_media_art_file_to_jpeg (const gchar *filename,
{
GdkPixbuf *pixbuf;
GError *error = NULL;
+ TrackerConfig *config = tracker_main_get_config ();
+ gint max_media_art_width = tracker_config_get_max_media_art_width (config);
+
+ if (max_media_art_width < 0) {
+ g_debug ("Not saving album art from file, disabled in config");
+ return TRUE;
+ }
+
+ /* TODO: Add resizing support */
pixbuf = gdk_pixbuf_new_from_file (filename, &error);
@@ -60,6 +71,26 @@ tracker_media_art_file_to_jpeg (const gchar *filename,
return TRUE;
}
+static void
+size_prepared_cb (GdkPixbufLoader *loader,
+ gint width,
+ gint height,
+ gpointer user_data)
+{
+ TrackerConfig *config = tracker_main_get_config ();
+ gint max_media_art_width = tracker_config_get_max_media_art_width (config);
+ gfloat scale;
+
+ if (max_media_art_width < 1 || width <= max_media_art_width) {
+ return;
+ }
+
+ g_debug ("Resizing media art to %d width", max_media_art_width);
+
+ scale = width / (gfloat) max_media_art_width;
+
+ gdk_pixbuf_loader_set_size (loader, (gint) (width / scale), (gint) (height / scale));
+}
gboolean
tracker_media_art_buffer_to_jpeg (const unsigned char *buffer,
@@ -67,24 +98,37 @@ tracker_media_art_buffer_to_jpeg (const unsigned char *buffer,
const gchar *buffer_mime,
const gchar *target)
{
- /* FF D8 FF are the three first bytes of JPeg images */
- if ((g_strcmp0 (buffer_mime, "image/jpeg") == 0 ||
- g_strcmp0 (buffer_mime, "JPG") == 0) &&
- (buffer && len > 2 && buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff)) {
+ TrackerConfig *config = tracker_main_get_config ();
+ gint max_media_art_width = tracker_config_get_max_media_art_width (config);
- g_debug ("Saving album art using raw data as uri:'%s'",
- target);
+ if (max_media_art_width < 0) {
+ g_debug ("Not saving album art from buffer, disabled in config");
+ return TRUE;
+ }
+ /* FF D8 FF are the three first bytes of JPeg images */
+ if (max_media_art_width == 0 &&
+ (g_strcmp0 (buffer_mime, "image/jpeg") == 0 ||
+ g_strcmp0 (buffer_mime, "JPG") == 0) &&
+ (buffer && len > 2 && buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff)) {
+ g_debug ("Saving album art using raw data as uri:'%s'", target);
g_file_set_contents (target, buffer, (gssize) len, NULL);
} else {
GdkPixbuf *pixbuf;
GdkPixbufLoader *loader;
GError *error = NULL;
- g_debug ("Saving album art using GdkPixbufLoader for uri:'%s'",
- target);
+ g_debug ("Saving album art using GdkPixbufLoader for uri:'%s' (max width:%d)",
+ target,
+ max_media_art_width);
loader = gdk_pixbuf_loader_new ();
+ if (max_media_art_width > 0) {
+ g_signal_connect (loader,
+ "size-prepared",
+ G_CALLBACK (size_prepared_cb),
+ NULL);
+ }
if (!gdk_pixbuf_loader_write (loader, buffer, len, &error)) {
g_warning ("Could not write with GdkPixbufLoader when setting album art, %s",
diff --git a/src/tracker-extract/tracker-media-art-qt.cpp b/src/tracker-extract/tracker-media-art-qt.cpp
index 13c8ff8..89aad2a 100644
--- a/src/tracker-extract/tracker-media-art-qt.cpp
+++ b/src/tracker-extract/tracker-media-art-qt.cpp
@@ -59,6 +59,16 @@ gboolean
tracker_media_art_file_to_jpeg (const gchar *filename,
const gchar *target)
{
+ TrackerConfig *config = tracker_main_get_config ();
+ gint max_media_art_width = tracker_config_get_max_media_art_width (config);
+
+ if (max_media_art_width < 0) {
+ g_debug ("Not saving album art from file, disabled in config");
+ return TRUE;
+ }
+
+ /* TODO: Add resizing support */
+
QFile file (filename);
if (!file.open (QIODevice::ReadOnly)) {
@@ -101,19 +111,28 @@ tracker_media_art_buffer_to_jpeg (const unsigned char *buffer,
const gchar *buffer_mime,
const gchar *target)
{
+ TrackerConfig *config = tracker_main_get_config ();
+ gint max_media_art_width = tracker_config_get_max_media_art_width (config);
+
+ if (max_media_art_width < 0) {
+ g_debug ("Not saving album art from buffer, disabled in config");
+ return TRUE;
+ }
+
/* FF D8 FF are the three first bytes of JPeg images */
- if ((g_strcmp0 (buffer_mime, "image/jpeg") == 0 ||
- g_strcmp0 (buffer_mime, "JPG") == 0) &&
+ if (max_media_art_width == 0 &&
+ (g_strcmp0 (buffer_mime, "image/jpeg") == 0 ||
+ g_strcmp0 (buffer_mime, "JPG") == 0) &&
(buffer && len > 2 && buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff)) {
-
g_debug ("Saving album art using raw data as uri:'%s'",
target);
-
g_file_set_contents (target, (const gchar*) buffer, (gssize) len, NULL);
} else {
QImageReader *reader = NULL;
QByteArray array;
+ /* TODO: Add resizing support */
+
array = QByteArray ((const char *) buffer, (int) len);
QBuffer qbuffer (&array);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]