[hitori] Use GResource for the UI and CSS files.
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [hitori] Use GResource for the UI and CSS files.
- Date: Thu, 5 Mar 2015 10:31:07 +0000 (UTC)
commit 6860892f6a152d795389c7f98835ee4b89db2ce9
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Tue Feb 24 16:39:16 2015 +0100
Use GResource for the UI and CSS files.
https://bugzilla.gnome.org/show_bug.cgi?id=744981
Makefile.am | 15 ++++-----------
src/hitori.gresource.xml | 4 ++++
src/interface.c | 33 ++++-----------------------------
3 files changed, 12 insertions(+), 40 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index aff8d10..a8be381 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -72,10 +72,6 @@ EXTRA_DIST = \
$(icon48_DATA) \
$(NULL)
-# CSS
-cssdir = $(datadir)/hitori
-css_DATA = data/hitori.css
-
# GResources
src/hitori-resources.c: $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies --sourcedir=$(top_srcdir)
$(top_srcdir)/src/hitori.gresource.xml)
$(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(top_srcdir) --generate-source
$(top_srcdir)/src/hitori.gresource.xml
@@ -83,12 +79,11 @@ src/hitori-resources.c: $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencie
CLEANFILES = src/hitori-resources.c
EXTRA_DIST += src/hitori.gresource.xml
-# UI file
+# UI & CSS files
dist_noinst_DATA = \
- data/hitori-menus.ui
-
-uidir = $(datadir)/hitori
-ui_DATA = data/hitori.ui
+ data/hitori-menus.ui \
+ data/hitori.ui \
+ data/hitori.css
# GSettings
gsettings_SCHEMAS = data/org.gnome.hitori.gschema.xml
@@ -104,9 +99,7 @@ desktopdir = $(datadir)/applications
desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
EXTRA_DIST += \
- $(css_DATA) \
$(gsettings_SCHEMAS) \
- $(ui_DATA) \
$(desktop_in_files) \
$(NULL)
CLEANFILES += $(desktop_DATA)
diff --git a/src/hitori.gresource.xml b/src/hitori.gresource.xml
index c22aacd..22cdfa0 100644
--- a/src/hitori.gresource.xml
+++ b/src/hitori.gresource.xml
@@ -1,5 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
+ <gresource prefix="/org/gnome/Hitori/ui">
+ <file preprocess="xml-stripblanks" alias="hitori.ui">./data/hitori.ui</file>
+ <file alias="hitori.css">./data/hitori.css</file>
+ </gresource>
<gresource prefix="/org/gnome/Hitori/gtk">
<file preprocess="xml-stripblanks" alias="menus.ui">./data/hitori-menus.ui</file>
</gresource>
diff --git a/src/interface.c b/src/interface.c
index 582176b..e08261b 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -67,33 +67,13 @@ static GActionEntry win_entries[] = {
GtkWidget *
hitori_create_interface (Hitori *hitori)
{
- GError *error = NULL;
GtkBuilder *builder;
GtkStyleContext *style_context;
GtkCssProvider *css_provider;
const PangoFontDescription *font;
GAction *action;
- builder = gtk_builder_new ();
-
- if (gtk_builder_add_from_file (builder, PACKAGE_DATA_DIR"/hitori/hitori.ui", &error) == FALSE &&
- gtk_builder_add_from_file (builder, "./data/hitori.ui", NULL) == FALSE) {
- /* Show an error */
- GtkWidget *dialog = gtk_message_dialog_new (NULL,
- GTK_DIALOG_MODAL,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- _("UI file ā%sā could not be loaded"), PACKAGE_DATA_DIR"/hitori/hitori.ui");
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
- gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
-
- g_error_free (error);
- g_object_unref (builder);
- hitori_quit (hitori);
-
- return NULL;
- }
+ builder = gtk_builder_new_from_resource ("/org/gnome/Hitori/ui/hitori.ui");
gtk_builder_set_translation_domain (builder, GETTEXT_PACKAGE);
gtk_builder_connect_signals (builder, hitori);
@@ -126,14 +106,9 @@ hitori_create_interface (Hitori *hitori)
/* Load CSS for the drawing area */
css_provider = gtk_css_provider_new ();
- gtk_css_provider_load_from_path (css_provider, PACKAGE_DATA_DIR"/hitori/hitori.css", &error);
- if (error) {
- g_warning ("Unable to load CSS: %s", error->message);
- g_error_free (error);
- } else {
- gtk_style_context_add_provider (style_context, GTK_STYLE_PROVIDER (css_provider),
- GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
- }
+ gtk_css_provider_load_from_resource (css_provider, "/org/gnome/Hitori/ui/hitori.css");
+ gtk_style_context_add_provider (style_context, GTK_STYLE_PROVIDER (css_provider),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_object_unref (css_provider);
/* Reset the timer */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]