[gnome-panel] panel: Convert to GResource



commit 9fca67f7bf2db30838ba6dcf86d49ca965ed31e5
Author: Vincent Untz <vuntz gnome org>
Date:   Thu Feb 2 14:54:58 2012 +0100

    panel: Convert to GResource

 gnome-panel/Makefile.am                      |   54 +++++++++++++++++--------
 gnome-panel/nothing.cP                       |   41 ++++++++++++++++----
 gnome-panel/panel-properties-dialog.c        |   28 +------------
 gnome-panel/panel-run-dialog.c               |   26 +-----------
 gnome-panel/panel-schemas.h                  |    2 +
 gnome-panel/panel-test-applets.c             |   13 +------
 gnome-panel/panel-test-applets.gresource.xml |    6 +++
 gnome-panel/panel.gresource.xml              |    8 ++++
 8 files changed, 93 insertions(+), 85 deletions(-)
---
diff --git a/gnome-panel/Makefile.am b/gnome-panel/Makefile.am
index 59f7e36..85ed498 100644
--- a/gnome-panel/Makefile.am
+++ b/gnome-panel/Makefile.am
@@ -14,17 +14,12 @@ AM_CPPFLAGS =							\
 	-I$(top_builddir)/gnome-panel/libpanel-util		\
 	-DPANELDATADIR=\""$(datadir)/gnome-panel"\"		\
 	-DGNOMELOCALEDIR=\""$(prefix)/$(DATADIRNAME)/locale"\"	\
-	-DBUILDERDIR=\""$(uidir)"\"				\
-	-DICONDIR=\""$(datadir)/gnome-panel/pixmaps"\"		\
 	$(DISABLE_DEPRECATED_CFLAGS)
 
 AM_CFLAGS = $(WARN_CFLAGS)
 
 panel_sources =			\
-	panel-typebuiltins.c	\
-	panel-typebuiltins.h	\
-	panel-marshal.c		\
-	panel-marshal.h		\
+	$(gnome_panel_BUILT_SOURCES) \
 	main.c			\
 	panel-widget.c		\
 	button-widget.c		\
@@ -158,11 +153,11 @@ gnome_desktop_item_edit_LDADD = 	\
 	$(PANEL_LIBS)							\
 	$(X_LIBS)
 
-panel_test_applets_SOURCES =		\
-	panel-modules.c			\
-	panel-applet-info.c		\
-	panel-applets-manager.c		\
-	panel-marshal.c			\
+panel_test_applets_SOURCES =			\
+	$(panel_test_applets_BUILT_SOURCES)	\
+	panel-modules.c				\
+	panel-applet-info.c			\
+	panel-applets-manager.c			\
 	panel-test-applets.c
 
 panel_test_applets_CPPFLAGS =			\
@@ -224,17 +219,41 @@ panel-typebuiltins.h: $(panel_enum_headers)
 			--eprod "GType @enum_name _get_type (void);\n" \
 		$(panel_enum_headers) > $@
 
-BUILT_SOURCES = \
+gnome_panel_BUILT_SOURCES = \
 	panel-typebuiltins.c		\
 	panel-typebuiltins.h		\
+	panel-resources.c		\
+	panel-resources.h		\
 	panel-marshal.c			\
 	panel-marshal.h
 
-uidir = $(datadir)/gnome-panel/ui
-ui_DATA =					\
+panel_test_applets_BUILT_SOURCES = 	\
+	panel-test-applets-resources.c	\
+	panel-test-applets-resources.h	\
+	panel-marshal.c			\
+	panel-marshal.h
+
+BUILT_SOURCES = 				\
+	$(gnome_panel_BUILT_SOURCES)		\
+	$(panel_test_applets_BUILT_SOURCES)
+
+ui_FILES =					\
 	panel-properties-dialog.ui		\
-	panel-run-dialog.ui			\
-	panel-test-applets.ui
+	panel-run-dialog.ui
+
+panel-resources.c: panel.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies panel.gresource.xml)
+	$(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate --c-name panel $(srcdir)/$<
+
+panel-resources.h: panel.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies panel.gresource.xml)
+	$(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate --c-name panel $(srcdir)/$<
+
+uitest_FILES = panel-test-applets.ui
+
+panel-test-applets-resources.c: panel-test-applets.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies panel-test-applets.gresource.xml)
+	$(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate --c-name panel $(srcdir)/$<
+
+panel-test-applets-resources.h: panel-test-applets.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies panel-test-applets.gresource.xml)
+	$(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate --c-name panel $(srcdir)/$<
 
 desktopdir = $(datadir)/applications
 desktop_in_files = gnome-panel.desktop.in
@@ -243,7 +262,8 @@ desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
 @INTLTOOL_DESKTOP_RULE@
 
 EXTRA_DIST =					\
-	$(ui_DATA)				\
+	$(ui_FILES)				\
+	$(uitest_FILES)				\
 	nothing.cP				\
 	nothing.h				\
 	panel-marshal.list			\
diff --git a/gnome-panel/nothing.cP b/gnome-panel/nothing.cP
index 14f1dc3..e016698 100644
--- a/gnome-panel/nothing.cP
+++ b/gnome-panel/nothing.cP
@@ -166,10 +166,24 @@ out:
         gtk_main_do_event (event);
 }
 
-static char *
-get_phsh_file (void)
+static GdkPixbuf *
+get_phsh_pixbuf (void)
 {
-        return g_strdup_printf ("%s/%cand%c.png", ICONDIR, 'w', 'a');
+        char *resource;
+        GdkPixbuf *pixbuf;
+        GInputStream *stream;
+
+        resource = g_strdup_printf ("%s%cand%c.png", "/org/gnome/panel/anim/", 'w', 'a');
+        stream = g_resources_open_stream (resource, 0, NULL);
+        g_free (resource);
+
+        if (!stream)
+                return NULL;
+
+        pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, NULL);
+        g_object_unref (stream);
+
+        return pixbuf;
 }
 
 static void
@@ -284,21 +298,32 @@ static void
 check_screen (void)
 {
         GdkWindowAttr attributes;
-        char *phsh_file;
+        GdkPixbuf *phsh_pixbuf;
+        int width, height;
         cairo_surface_t *surface;
+        cairo_t *cr;
         int orient;
         int i;
 
         if (phsh.win != NULL)
                 return;
 
-        phsh_file = get_phsh_file ();
+        phsh_pixbuf = get_phsh_pixbuf ();
 
-        if (phsh_file == NULL)
+        if (phsh_pixbuf == NULL)
                 return;
 
-        surface = cairo_image_surface_create_from_png (phsh_file);
-        g_free (phsh_file);
+        width = gdk_pixbuf_get_width (phsh_pixbuf);
+        height = gdk_pixbuf_get_height (phsh_pixbuf);
+
+        surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
+        cr = cairo_create (surface);
+        gdk_cairo_set_source_pixbuf (cr, phsh_pixbuf, 0, 0);
+        cairo_rectangle (cr, 0, 0, width, height);
+        cairo_fill (cr);
+        cairo_destroy (cr);
+
+        g_object_unref (phsh_pixbuf);
 
         if (cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) {
                 cairo_surface_destroy (surface);
diff --git a/gnome-panel/panel-properties-dialog.c b/gnome-panel/panel-properties-dialog.c
index 3193ba1..4320679 100644
--- a/gnome-panel/panel-properties-dialog.c
+++ b/gnome-panel/panel-properties-dialog.c
@@ -27,7 +27,6 @@
 #include <string.h>
 #include <glib/gi18n.h>
 
-#include <libpanel-util/panel-error.h>
 #include <libpanel-util/panel-glib.h>
 #include <libpanel-util/panel-gtk.h>
 #include <libpanel-util/panel-icon-chooser.h>
@@ -793,7 +792,6 @@ panel_properties_dialog_present (PanelToplevel *toplevel)
 {
 	PanelPropertiesDialog *dialog;
 	GtkBuilder            *gui;
-	GError                *error;
 
 	if (!panel_properties_dialog_quark)
 		panel_properties_dialog_quark =
@@ -809,29 +807,9 @@ panel_properties_dialog_present (PanelToplevel *toplevel)
 
 	gui = gtk_builder_new ();
 	gtk_builder_set_translation_domain (gui, GETTEXT_PACKAGE);
-
-	error = NULL;
-	gtk_builder_add_from_file (gui,
-				   BUILDERDIR "/panel-properties-dialog.ui",
-				   &error);
-
-        if (error) {
-		char *secondary;
-
-		secondary = g_strdup_printf (_("Unable to load file '%s': %s."),
-					     BUILDERDIR"/panel-properties-dialog.ui",
-					     error->message);
-		panel_error_dialog (GTK_WINDOW (toplevel),
-				    gtk_window_get_screen (GTK_WINDOW (toplevel)),
-				    "cannot_display_properties_dialog", TRUE,
-				    _("Could not display properties dialog"),
-				    secondary);
-		g_free (secondary);
-		g_error_free (error);
-		g_object_unref (gui);
-
-		return;
-	}
+	gtk_builder_add_from_resource (gui,
+				       PANEL_RESOURCE_PATH "panel-properties-dialog.ui",
+				       NULL);
 
 	dialog = panel_properties_dialog_new (toplevel, gui);
 
diff --git a/gnome-panel/panel-run-dialog.c b/gnome-panel/panel-run-dialog.c
index 5601efb..7b5a8dc 100644
--- a/gnome-panel/panel-run-dialog.c
+++ b/gnome-panel/panel-run-dialog.c
@@ -1869,7 +1869,6 @@ panel_run_dialog_present (GdkScreen *screen,
 			  guint32    activate_time)
 {
 	GtkBuilder *gui;
-	GError     *error;
 
 	if (panel_lockdown_get_disable_command_line_s ())
 		return;
@@ -1884,28 +1883,9 @@ panel_run_dialog_present (GdkScreen *screen,
 
 	gui = gtk_builder_new ();
 	gtk_builder_set_translation_domain (gui, GETTEXT_PACKAGE);
-
-	error = NULL;
-	gtk_builder_add_from_file (gui,
-				   BUILDERDIR "/panel-run-dialog.ui",
-				   &error);
-
-        if (error) {
-		char *secondary;
-
-		secondary = g_strdup_printf (_("Unable to load file '%s': %s."),
-					     BUILDERDIR"/panel-run-dialog.ui",
-					     error->message);
-		panel_error_dialog (NULL, screen, "cannot_display_run_dialog",
-				    TRUE,
-				    _("Could not display run dialog"),
-				      secondary);
-		g_free (secondary);
-		g_error_free (error);
-		g_object_unref (gui);
-
-		return;
-	}
+	gtk_builder_add_from_resource (gui,
+				       PANEL_RESOURCE_PATH "panel-run-dialog.ui",
+				       NULL);
 
 	static_dialog = panel_run_dialog_new (screen, gui, activate_time);
 
diff --git a/gnome-panel/panel-schemas.h b/gnome-panel/panel-schemas.h
index 59b01b8..a2543ac 100644
--- a/gnome-panel/panel-schemas.h
+++ b/gnome-panel/panel-schemas.h
@@ -1,6 +1,8 @@
 #ifndef __PANEL_SCHEMAS_H__
 #define __PANEL_SCHEMAS_H__
 
+#define PANEL_RESOURCE_PATH "/org/gnome/panel/"
+
 #define PANEL_GENERAL_SCHEMA                    "org.gnome.gnome-panel.general"
 #define PANEL_GENERAL_CONFIRM_PANEL_REMOVAL_KEY "confirm-panel-removal"
 #define PANEL_GENERAL_ENABLE_TOOLTIPS_KEY       "enable-tooltips"
diff --git a/gnome-panel/panel-test-applets.c b/gnome-panel/panel-test-applets.c
index b302bc2..b6616ae 100644
--- a/gnome-panel/panel-test-applets.c
+++ b/gnome-panel/panel-test-applets.c
@@ -312,7 +312,6 @@ int
 main (int argc, char **argv)
 {
 	GtkBuilder *builder;
-	char       *uifile;
 	char       *applets_dir;
 	GError     *error;
 
@@ -351,17 +350,7 @@ main (int argc, char **argv)
 
 	builder = gtk_builder_new ();
 	gtk_builder_set_translation_domain (builder, GETTEXT_PACKAGE);
-
-	uifile = BUILDERDIR "/panel-test-applets.ui";
-	gtk_builder_add_from_file (builder, uifile, &error);
-
-	if (error) {
-		g_warning ("Error loading \"%s\": %s", uifile, error->message);
-		g_error_free (error);
-		panel_cleanup_do ();
-
-		return 1;
-	}
+	gtk_builder_add_from_resource (builder, "/org/gnome/panel/test/panel-test-applets.ui", NULL);
 
 	gtk_builder_connect_signals (builder, NULL);
 
diff --git a/gnome-panel/panel-test-applets.gresource.xml b/gnome-panel/panel-test-applets.gresource.xml
new file mode 100644
index 0000000..8e31698
--- /dev/null
+++ b/gnome-panel/panel-test-applets.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/panel/test">
+    <file compressed="true">panel-test-applets.ui</file>
+  </gresource>
+</gresources>
diff --git a/gnome-panel/panel.gresource.xml b/gnome-panel/panel.gresource.xml
new file mode 100644
index 0000000..40b9380
--- /dev/null
+++ b/gnome-panel/panel.gresource.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/panel">
+    <file compressed="true">panel-properties-dialog.ui</file>
+    <file compressed="true">panel-run-dialog.ui</file>
+    <file alias="anim/wanda.png">../applets/fish/wanda.png</file>
+  </gresource>
+</gresources>



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