[shotwell] transitions: Load icon from resource



commit 92e38a39ddfcb193af3932db71027cd4e3360b08
Author: Jens Georg <mail jensge org>
Date:   Tue Jul 19 23:35:43 2016 +0200

    transitions: Load icon from resource
    
    Signed-off-by: Jens Georg <mail jensge org>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=747368

 Makefile.am                                        |    3 +-
 configure.ac                                       |    5 ++++
 plugins/common/Resources.vala                      |   22 +++++++++++++++++++-
 .../org.gnome.Shotwell.Transitions.gresource.xml   |    6 +++++
 .../shotwell-transitions/shotwell-transitions.vala |    3 +-
 transition.am                                      |    9 +++++++-
 6 files changed, 44 insertions(+), 4 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index e42c95b..e6ad4f4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -119,6 +119,7 @@ dist_plugin_DATA =
 pkglibexec_PROGRAMS =
 
 dist_pkglibexec_SCRIPTS = $(top_srcdir)/settings-migrator/shotwell-settings-migrator
+dist_noinst_DATA = $(NULL)
 
 include $(top_srcdir)/common.am
 include $(top_srcdir)/shotwell.am
@@ -133,7 +134,7 @@ include $(top_srcdir)/import.am
 dist_noinst_SCRIPTS = \
        autogen.sh
 
-dist_noinst_DATA = \
+dist_noinst_DATA += \
        plugins/shotwell-plugin-dev-1.0.h \
        plugins/shotwell-plugin-common.h \
        vapi/gphoto.h \
diff --git a/configure.ac b/configure.ac
index ffdacb1..a65abd9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -146,6 +146,11 @@ dnl ***********************************************************************
 AX_REQUIRE_DEFINED([APPDATA_XML])
 APPDATA_XML
 
+dnl
+dnl
+dnl
+AC_SUBST([GLIB_COMPILE_RESOURCES], [`$PKG_CONFIG --variable glib_compile_resources gio-2.0`])
+
 dnl ***********************************************************************
 dnl Process .in Files
 dnl ***********************************************************************
diff --git a/plugins/common/Resources.vala b/plugins/common/Resources.vala
index 2bb1cb3..29c7294 100644
--- a/plugins/common/Resources.vala
+++ b/plugins/common/Resources.vala
@@ -6,6 +6,9 @@
 
 namespace Resources {
 
+[CCode (cname = "PLUGIN_RESOURCE_PATH")]
+public extern const string RESOURCE_PATH;
+
 public const string WEBSITE_NAME = _("Visit the Shotwell home page");
 public const string WEBSITE_URL = "https://wiki.gnome.org/Apps/Shotwell";;
 
@@ -42,7 +45,7 @@ public Gdk.Pixbuf[]? load_icon_set(GLib.File? icon_file) {
         warning("couldn't load icon set from %s.", icon_file.get_path());
     }
     
-    if (icon_file != null) {
+    if (icon != null) {
         Gdk.Pixbuf[] icon_pixbuf_set = new Gdk.Pixbuf[0];
         icon_pixbuf_set += icon;
         return icon_pixbuf_set;
@@ -51,4 +54,21 @@ public Gdk.Pixbuf[]? load_icon_set(GLib.File? icon_file) {
     return null;
 }
 
+public Gdk.Pixbuf[]? load_from_resource (string resource_path) {
+    Gdk.Pixbuf? icon = null;
+    try {
+        icon = new Gdk.Pixbuf.from_resource (resource_path);
+    } catch (Error error) {
+        warning ("Couldn't load icon set from %s", resource_path);
+    }
+
+    if (icon != null) {
+        Gdk.Pixbuf[] icon_pixbuf_set = new Gdk.Pixbuf[0];
+        icon_pixbuf_set += icon;
+        return icon_pixbuf_set;
+    }
+
+    return null;
+}
+
 }
diff --git a/plugins/shotwell-transitions/org.gnome.Shotwell.Transitions.gresource.xml 
b/plugins/shotwell-transitions/org.gnome.Shotwell.Transitions.gresource.xml
new file mode 100644
index 0000000..7545683
--- /dev/null
+++ b/plugins/shotwell-transitions/org.gnome.Shotwell.Transitions.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/Shotwell/Transitions">
+    <file>slideshow-plugin.png</file>
+  </gresource>
+</gresources>
diff --git a/plugins/shotwell-transitions/shotwell-transitions.vala 
b/plugins/shotwell-transitions/shotwell-transitions.vala
index 2b1fe40..7673414 100644
--- a/plugins/shotwell-transitions/shotwell-transitions.vala
+++ b/plugins/shotwell-transitions/shotwell-transitions.vala
@@ -58,7 +58,8 @@ public abstract class ShotwellTransitionDescriptor : Object, Spit.Pluggable, Spi
     
     public ShotwellTransitionDescriptor(GLib.File resource_directory) {
         if (icon_pixbuf_set == null)
-            icon_pixbuf_set = Resources.load_icon_set(resource_directory.get_child(ICON_FILENAME));
+            icon_pixbuf_set =
+                Resources.load_from_resource(Resources.RESOURCE_PATH + "/" + ICON_FILENAME);
     }
 
     public int get_pluggable_interface(int min_host_interface, int max_host_interface) {
diff --git a/transition.am b/transition.am
index f055536..aa911ff 100644
--- a/transition.am
+++ b/transition.am
@@ -1,5 +1,5 @@
 plugin_LTLIBRARIES += plugins/shotwell-transitions/shotwell-transitions.la
-dist_plugin_DATA += plugins/shotwell-transitions/slideshow-plugin.png
+dist_noinst_DATA += plugins/shotwell-transitions/slideshow-plugin.png
 
 plugins_shotwell_transitions_shotwell_transitions_la_SOURCES = \
        plugins/shotwell-transitions/BlindsEffect.vala \
@@ -15,6 +15,12 @@ plugins_shotwell_transitions_shotwell_transitions_la_SOURCES = \
        plugins/shotwell-transitions/StripesEffect.vala \
        plugins/shotwell-plugin-common.vapi
 
+nodist_plugins_shotwell_transitions_shotwell_transitions_la_SOURCES = \
+       plugins/shotwell-transitions/resource.c
+
+plugins/shotwell-transitions/resource.c: 
plugins/shotwell-transitions/org.gnome.Shotwell.Transitions.gresource.xml
+       $(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=plugins/shotwell-transitions --generate 
$<
+
 plugins_shotwell_transitions_shotwell_transitions_la_VALAFLAGS = \
        $(COMMON_VALAFLAGS) \
        --pkg gtk+-3.0 \
@@ -29,6 +35,7 @@ plugins_shotwell_transitions_shotwell_transitions_la_VALAFLAGS = \
        --vapidir $(abs_top_srcdir)/plugins
 
 plugins_shotwell_transitions_shotwell_transitions_la_CFLAGS = \
+       -DPLUGIN_RESOURCE_PATH='"/org/gnome/Shotwell/Transitions"' \
        $(PLUGIN_CFLAGS) \
        $(COMMON_CFLAGS) \
        -I $(abs_top_srcdir)/plugins


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]