[gnome-screenshot] screenshot: use a separate UI file and a GResource for the app menu



commit cdfea89824fe3168b3875c466a29495df1af048b
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Thu May 10 15:33:49 2012 -0400

    screenshot: use a separate UI file and a GResource for the app menu
    
    So to avoid problems with translations; embedding glade-like XML in C
    files makes it impossible for the translatable strings to be picked up
    by gettext, as reported by Piotr DrÄg <piotrdrag gmail com>.

 po/POTFILES.in                     |    1 +
 src/Makefile.am                    |   16 ++++++++++++++++
 src/gnome-screenshot.gresource.xml |    6 ++++++
 src/screenshot-app-menu.ui         |   18 ++++++++++++++++++
 src/screenshot-application.c       |   22 +---------------------
 5 files changed, 42 insertions(+), 21 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index ba320e3..f4dd9a8 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -3,6 +3,7 @@
 src/gnome-screenshot.c
 src/gnome-screenshot.desktop.in
 [type: gettext/glade]src/gnome-screenshot.ui
+[type: gettext/glade]src/screenshot-app-menu.ui
 src/org.gnome.gnome-screenshot.gschema.xml.in
 src/screenshot-application.c
 src/screenshot-config.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 8f2b4ad..6e04709 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -11,7 +11,23 @@ bin_PROGRAMS = \
 	gnome-screenshot		\
 	$(NULL)
 
+UI_FILES = \
+	screenshot-app-menu.ui		\
+	$(NULL)
+
+screenshot-resources.c: gnome-screenshot.gresource.xml $(UI_FILES)
+	$(AM_V_GEN)glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-source --c-name screenshot $(srcdir)/gnome-screenshot.gresource.xml
+
+screenshot-resources.h: gnome-screenshot.gresource.xml $(UI_FILES)
+	$(AM_V_GEN)glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-header --c-name screenshot $(srcdir)/gnome-screenshot.gresource.xml
+
+BUILT_SOURCES = \
+	screenshot-resources.c		\
+	screenshot-resources.h		\
+	$(NULL)
+
 gnome_screenshot_SOURCES = \
+	$(BUILT_SOURCES)		\
 	gnome-screenshot.c		\
 	cheese-flash.c			\
 	cheese-flash.h			\
diff --git a/src/gnome-screenshot.gresource.xml b/src/gnome-screenshot.gresource.xml
new file mode 100644
index 0000000..e228b73
--- /dev/null
+++ b/src/gnome-screenshot.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/screenshot">
+    <file preprocess="xml-stripblanks">screenshot-app-menu.ui</file>
+  </gresource>
+</gresources>
diff --git a/src/screenshot-app-menu.ui b/src/screenshot-app-menu.ui
new file mode 100644
index 0000000..81f0541
--- /dev/null
+++ b/src/screenshot-app-menu.ui
@@ -0,0 +1,18 @@
+<interface>
+  <menu id="app-menu">
+    <section>
+      <item>
+        <attribute name="action">app.about</attribute>
+        <attribute name="label" translatable="yes">About Screenshot</attribute>
+      </item>
+      <item>
+        <attribute name="action">app.help</attribute>
+        <attribute name="label" translatable="yes">Help</attribute>
+      </item>
+      <item>
+       <attribute name="action">app.quit</attribute>
+       <attribute name="label" translatable="yes">Quit</attribute>
+      </item>
+    </section>
+  </menu>
+</interface>
diff --git a/src/screenshot-application.c b/src/screenshot-application.c
index da438da..710b1e9 100644
--- a/src/screenshot-application.c
+++ b/src/screenshot-application.c
@@ -45,26 +45,6 @@
 
 G_DEFINE_TYPE (ScreenshotApplication, screenshot_application, GTK_TYPE_APPLICATION);
 
-static const gchar *app_menu =
-    "<interface>"
-    "  <menu id=\"app-menu\">"
-    "    <section>"
-    "      <item>"
-    "        <attribute name=\"action\">app.about</attribute>"
-    "	     <attribute name=\"label\" translatable=\"yes\">About Screenshot</attribute>"
-    "      </item>"
-    "      <item>"
-    "        <attribute name=\"action\">app.help</attribute>"
-    "	     <attribute name=\"label\" translatable=\"yes\">Help</attribute>"
-    "      </item>"
-    "      <item>"
-    "       <attribute name=\"action\">app.quit</attribute>"
-    "	    <attribute name=\"label\" translatable=\"yes\">Quit</attribute>"
-    "      </item>"
-    "    </section>"
-    "  <menu>"
-    "</interface>";
-
 static void screenshot_save_to_file (ScreenshotApplication *self);
 
 struct _ScreenshotApplicationPriv {
@@ -696,7 +676,7 @@ screenshot_application_startup (GApplication *app)
                                        G_N_ELEMENTS (action_entries), self);
 
       builder = gtk_builder_new ();
-      gtk_builder_add_from_string (builder, app_menu, -1, NULL);
+      gtk_builder_add_from_resource (builder, "/org/gnome/screenshot/screenshot-app-menu.ui", NULL);
       menu = G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu"));
       gtk_application_set_app_menu (GTK_APPLICATION (self), menu);
 



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