[shotwell] publish: Load resources from GResource



commit 8f86cdaaa86f2d42d1d85f84b71995e93abc5dbc
Author: Jens Georg <mail jensge org>
Date:   Wed Jul 20 00:19:45 2016 +0200

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

 .../shotwell-publishing/FacebookPublishing.vala    |    8 ++++----
 plugins/shotwell-publishing/FlickrPublishing.vala  |   11 ++++++-----
 plugins/shotwell-publishing/PicasaPublishing.vala  |    8 ++++----
 plugins/shotwell-publishing/PiwigoPublishing.vala  |   13 ++++---------
 plugins/shotwell-publishing/YouTubePublishing.vala |    7 ++++---
 .../org.gnome.Shotwell.Publishing.gresource.xml    |   17 +++++++++++++++++
 publish.am                                         |    9 ++++++++-
 7 files changed, 47 insertions(+), 26 deletions(-)
---
diff --git a/plugins/shotwell-publishing/FacebookPublishing.vala 
b/plugins/shotwell-publishing/FacebookPublishing.vala
index 729b2da..608e5c5 100644
--- a/plugins/shotwell-publishing/FacebookPublishing.vala
+++ b/plugins/shotwell-publishing/FacebookPublishing.vala
@@ -11,7 +11,8 @@ public class FacebookService : Object, Spit.Pluggable, Spit.Publishing.Service {
     
     public FacebookService(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) {
@@ -364,9 +365,8 @@ public class FacebookPublisher : Spit.Publishing.Publisher, GLib.Object {
         try {
             // the trailing get_path() is required, since add_from_file can't cope
             // with File objects directly and expects a pathname instead.
-            builder.add_from_file(
-                host.get_module_file().get_parent().
-                get_child("facebook_publishing_options_pane.ui").get_path());
+            builder.add_from_resource (Resources.RESOURCE_PATH + "/" +
+                    "facebook_publishing_options_pane.ui");
         } catch (Error e) {
             warning("Could not parse UI file! Error: %s.", e.message);
             host.post_error(
diff --git a/plugins/shotwell-publishing/FlickrPublishing.vala 
b/plugins/shotwell-publishing/FlickrPublishing.vala
index 0eea485..36762d8 100644
--- a/plugins/shotwell-publishing/FlickrPublishing.vala
+++ b/plugins/shotwell-publishing/FlickrPublishing.vala
@@ -13,7 +13,8 @@ public class FlickrService : Object, Spit.Pluggable, Spit.Publishing.Service {
     
     public FlickrService(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) {
@@ -436,7 +437,8 @@ public class FlickrPublisher : Spit.Publishing.Publisher, GLib.Object {
         Gtk.Builder builder = new Gtk.Builder();
         
         try {
-            
builder.add_from_file(host.get_module_file().get_parent().get_child("flickr_pin_entry_pane.ui").get_path());
+            builder.add_from_resource (Resources.RESOURCE_PATH + "/" +
+                    "flickr_pin_entry_pane.ui");
         } catch (Error e) {
             warning("Could not parse UI file! Error: %s.", e.message);
             host.post_error(
@@ -585,9 +587,8 @@ public class FlickrPublisher : Spit.Publishing.Publisher, GLib.Object {
         try {
             // the trailing get_path() is required, since add_from_file can't cope
             // with File objects directly and expects a pathname instead.
-            builder.add_from_file(
-                host.get_module_file().get_parent().
-                get_child("flickr_publishing_options_pane.ui").get_path());
+            builder.add_from_resource(Resources.RESOURCE_PATH + "/" +
+                    "flickr_publishing_options_pane.ui");
         } catch (Error e) {
             warning("Could not parse UI file! Error: %s.", e.message);
             host.post_error(
diff --git a/plugins/shotwell-publishing/PicasaPublishing.vala 
b/plugins/shotwell-publishing/PicasaPublishing.vala
index 03a34c6..a393c08 100644
--- a/plugins/shotwell-publishing/PicasaPublishing.vala
+++ b/plugins/shotwell-publishing/PicasaPublishing.vala
@@ -11,7 +11,8 @@ public class PicasaService : Object, Spit.Pluggable, Spit.Publishing.Service {
     
     public PicasaService(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) {
@@ -351,9 +352,8 @@ public class PicasaPublisher : Publishing.RESTSupport.GooglePublisher {
         try {
             // the trailing get_path() is required, since add_from_file can't cope
             // with File objects directly and expects a pathname instead.
-            builder.add_from_file(
-                get_host().get_module_file().get_parent().
-                get_child("picasa_publishing_options_pane.ui").get_path());
+            builder.add_from_resource(Resources.RESOURCE_PATH + "/" +
+                "picasa_publishing_options_pane.ui");
         } catch (Error e) {
             warning("Could not parse UI file! Error: %s.", e.message);
             get_host().post_error(
diff --git a/plugins/shotwell-publishing/PiwigoPublishing.vala 
b/plugins/shotwell-publishing/PiwigoPublishing.vala
index fdb40e2..bc83fdc 100644
--- a/plugins/shotwell-publishing/PiwigoPublishing.vala
+++ b/plugins/shotwell-publishing/PiwigoPublishing.vala
@@ -11,7 +11,8 @@ public class PiwigoService : Object, Spit.Pluggable, Spit.Publishing.Service {
     
     public PiwigoService(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) {
@@ -1001,12 +1002,9 @@ internal class AuthenticationPane : Spit.Publishing.DialogPane, Object {
     public AuthenticationPane(PiwigoPublisher publisher, Mode mode = Mode.INTRO) {
         this.pane_widget = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
 
-        File ui_file = publisher.get_host().get_module_file().get_parent().
-            get_child("piwigo_authentication_pane.ui");
-        
         try {
             builder = new Gtk.Builder();
-            builder.add_from_file(ui_file.get_path());
+            builder.add_from_resource (Resources.RESOURCE_PATH + "/piwigo_authentication_pane.ui");
             builder.connect_signals(null);
             Gtk.Alignment align = builder.get_object("alignment") as Gtk.Alignment;
             
@@ -1156,12 +1154,9 @@ internal class PublishingOptionsPane : Spit.Publishing.DialogPane, Object {
         this.last_title_as_comment = last_title_as_comment;
         this.last_no_upload_tags = last_no_upload_tags;
 
-        File ui_file = publisher.get_host().get_module_file().get_parent().
-            get_child("piwigo_publishing_options_pane.ui");
-        
         try {
             builder = new Gtk.Builder();
-            builder.add_from_file(ui_file.get_path());
+            builder.add_from_resource (Resources.RESOURCE_PATH + "/piwigo_publishing_options_pane.ui");
             builder.connect_signals(null);
             Gtk.Alignment align = builder.get_object("alignment") as Gtk.Alignment;
             
diff --git a/plugins/shotwell-publishing/YouTubePublishing.vala 
b/plugins/shotwell-publishing/YouTubePublishing.vala
index 78dc52f..7325c32 100644
--- a/plugins/shotwell-publishing/YouTubePublishing.vala
+++ b/plugins/shotwell-publishing/YouTubePublishing.vala
@@ -11,7 +11,8 @@ public class YouTubeService : Object, Spit.Pluggable, Spit.Publishing.Service {
 
     public YouTubeService(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) {
@@ -353,8 +354,8 @@ public class YouTubePublisher : Publishing.RESTSupport.GooglePublisher {
         Gtk.Builder builder = new Gtk.Builder();
 
         try {
-            builder.add_from_file(
-                
get_host().get_module_file().get_parent().get_child("youtube_publishing_options_pane.ui").get_path());
+            builder.add_from_resource (Resources.RESOURCE_PATH +
+                    "/youtube_publishing_options_pane.ui");
         } catch (Error e) {
             warning("Could not parse UI file! Error: %s.", e.message);
             get_host().post_error(
diff --git a/plugins/shotwell-publishing/org.gnome.Shotwell.Publishing.gresource.xml 
b/plugins/shotwell-publishing/org.gnome.Shotwell.Publishing.gresource.xml
new file mode 100644
index 0000000..53bcc43
--- /dev/null
+++ b/plugins/shotwell-publishing/org.gnome.Shotwell.Publishing.gresource.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/Shotwell/Publishing">
+      <file>facebook.png</file>
+      <file>flickr.png</file>
+      <file>picasa.png</file>
+      <file>piwigo.png</file>
+      <file>youtube.png</file>
+      <file>facebook_publishing_options_pane.ui</file>
+      <file>flickr_pin_entry_pane.ui</file>
+      <file>flickr_publishing_options_pane.ui</file>
+      <file>picasa_publishing_options_pane.ui</file>
+      <file>piwigo_authentication_pane.ui</file>
+      <file>piwigo_publishing_options_pane.ui</file>
+      <file>youtube_publishing_options_pane.ui</file>
+  </gresource>
+</gresources>
diff --git a/publish.am b/publish.am
index 93ec0cb..b00e50b 100644
--- a/publish.am
+++ b/publish.am
@@ -1,6 +1,6 @@
 plugin_LTLIBRARIES += plugins/shotwell-publishing/shotwell-publishing.la
 
-dist_plugin_DATA += \
+dist_noinst_DATA += \
        plugins/shotwell-publishing/facebook.png \
        plugins/shotwell-publishing/flickr.png \
        plugins/shotwell-publishing/picasa.png \
@@ -23,6 +23,12 @@ plugins_shotwell_publishing_shotwell_publishing_la_SOURCES = \
        plugins/shotwell-publishing/PiwigoPublishing.vala \
        plugins/shotwell-plugin-common.vapi
 
+nodist_plugins_shotwell_publishing_shotwell_publishing_la_SOURCES = \
+       plugins/shotwell-publishing/resource.c
+
+plugins/shotwell-publishing/resource.c: 
plugins/shotwell-publishing/org.gnome.Shotwell.Publishing.gresource.xml
+       $(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=plugins/shotwell-publishing --generate $<
+
 plugins_shotwell_publishing_shotwell_publishing_la_VALAFLAGS = \
        $(COMMON_VALAFLAGS) \
        --pkg gtk+-3.0 \
@@ -37,6 +43,7 @@ plugins_shotwell_publishing_shotwell_publishing_la_VALAFLAGS = \
        --vapidir $(abs_top_srcdir)/plugins
 
 plugins_shotwell_publishing_shotwell_publishing_la_CFLAGS = \
+       -DPLUGIN_RESOURCE_PATH='"/org/gnome/Shotwell/Publishing"' \
        $(PLUGIN_CFLAGS) \
        $(COMMON_CFLAGS) \
        -I $(top_srcdir)/plugins


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