diff options
author | Xan Lopez <xan@igalia.com> | 2012-03-27 19:31:56 +0800 |
---|---|---|
committer | Xan Lopez <xan@igalia.com> | 2012-03-28 03:42:41 +0800 |
commit | 98e31b7886bad0eae162ec7c6513a1d20f306727 (patch) | |
tree | 714c4d1d1341f9947ce9d12168a55f6609ce1a42 | |
parent | d892edb5d13028c4d150acba9edf3792eb000194 (diff) | |
download | gsoc2013-epiphany-98e31b7886bad0eae162ec7c6513a1d20f306727.tar gsoc2013-epiphany-98e31b7886bad0eae162ec7c6513a1d20f306727.tar.gz gsoc2013-epiphany-98e31b7886bad0eae162ec7c6513a1d20f306727.tar.bz2 gsoc2013-epiphany-98e31b7886bad0eae162ec7c6513a1d20f306727.tar.lz gsoc2013-epiphany-98e31b7886bad0eae162ec7c6513a1d20f306727.tar.xz gsoc2013-epiphany-98e31b7886bad0eae162ec7c6513a1d20f306727.tar.zst gsoc2013-epiphany-98e31b7886bad0eae162ec7c6513a1d20f306727.zip |
Use glib resources to bundle our UI files
https://bugzilla.gnome.org/show_bug.cgi?id=672907
-rw-r--r-- | data/ui/Makefile.am | 20 | ||||
-rw-r--r-- | lib/ephy-dialog.c | 12 | ||||
-rw-r--r-- | lib/ephy-dialog.h | 4 | ||||
-rw-r--r-- | src/Makefile.am | 25 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks-editor.c | 6 | ||||
-rw-r--r-- | src/ephy-encoding-dialog.c | 2 | ||||
-rw-r--r-- | src/ephy-history-window.c | 6 | ||||
-rw-r--r-- | src/ephy-shell.c | 6 | ||||
-rw-r--r-- | src/ephy-window.c | 43 | ||||
-rw-r--r-- | src/epiphany.gresource.xml | 12 | ||||
-rw-r--r-- | src/pdm-dialog.c | 4 | ||||
-rw-r--r-- | src/prefs-dialog.c | 4 |
12 files changed, 95 insertions, 49 deletions
diff --git a/data/ui/Makefile.am b/data/ui/Makefile.am index f9efeaa77..20dfcfdb8 100644 --- a/data/ui/Makefile.am +++ b/data/ui/Makefile.am @@ -1,19 +1,13 @@ -xmldir = $(pkgdatadir) -xml_DATA = \ +UI_FILES = \ epiphany-bookmark-editor-ui.xml \ epiphany-ui.xml \ - epiphany-history-window-ui.xml - -cssdir = $(pkgdatadir) -css_DATA = epiphany.css - -gladedir = $(pkgdatadir)/glade -glade_DATA = \ + epiphany-history-window-ui.xml \ epiphany.ui \ epiphany-application-menu.ui \ - prefs-dialog.ui + prefs-dialog.ui \ + epiphany.css \ + $(NULL) EXTRA_DIST = \ - $(xml_DATA) \ - $(css_DATA) \ - $(glade_DATA) + $(UI_FILES) \ + $(NULL) diff --git a/lib/ephy-dialog.c b/lib/ephy-dialog.c index 1ca4d0daa..3948fb527 100644 --- a/lib/ephy-dialog.c +++ b/lib/ephy-dialog.c @@ -140,7 +140,7 @@ dialog_destroy_cb (GtkWidget *widget, EphyDialog *dialog) static void impl_construct (EphyDialog *dialog, - const char *file, + const char *resource, const char *name, const char *domain) { @@ -150,10 +150,10 @@ impl_construct (EphyDialog *dialog, builder = gtk_builder_new (); gtk_builder_set_translation_domain (builder, domain); - gtk_builder_add_from_file (builder, file, &error); + gtk_builder_add_from_resource (builder, resource, &error); if (error) { - g_warning ("Unable to load UI file %s: %s", file, error->message); + g_warning ("Unable to load UI resource %s: %s", resource, error->message); g_error_free (error); return; } @@ -234,7 +234,7 @@ ephy_dialog_set_size_group (EphyDialog *dialog, /** * ephy_dialog_construct: * @dialog: an #EphyDialog - * @file: the path to a #GtkBuilder file + * @resource: the path to the UI resource * @name: name of the widget to use for @dialog, found in @file * @domain: translation domain to set for @dialog * @@ -243,12 +243,12 @@ ephy_dialog_set_size_group (EphyDialog *dialog, **/ void ephy_dialog_construct (EphyDialog *dialog, - const char *file, + const char *resource, const char *name, const char *domain) { EphyDialogClass *klass = EPHY_DIALOG_GET_CLASS (dialog); - klass->construct (dialog, file, name, domain); + klass->construct (dialog, resource, name, domain); } /** diff --git a/lib/ephy-dialog.h b/lib/ephy-dialog.h index 0373ea834..797690a3e 100644 --- a/lib/ephy-dialog.h +++ b/lib/ephy-dialog.h @@ -54,7 +54,7 @@ struct _EphyDialogClass /* Methods */ void (* construct) (EphyDialog *dialog, - const char *file, + const char *resource, const char *name, const char *domain); void (* show) (EphyDialog *dialog); @@ -75,7 +75,7 @@ EphyDialog *ephy_dialog_new (void); EphyDialog *ephy_dialog_new_with_parent (GtkWidget *parent_window); void ephy_dialog_construct (EphyDialog *dialog, - const char *file, + const char *resource, const char *name, const char *domain); diff --git a/src/Makefile.am b/src/Makefile.am index 0d75a298c..d9cb01db3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -6,7 +6,9 @@ noinst_LTLIBRARIES = libephymain.la bin_PROGRAMS = epiphany -EXTRA_DIST = +EXTRA_DIST = \ + epiphany.gresource.xml \ + $(NULL) headerdir = $(prefix)/include/epiphany/$(EPIPHANY_MAJOR)/epiphany header_DATA = \ @@ -106,8 +108,21 @@ libephymain_la_CFLAGS = \ $(WEBKIT_CFLAGS) \ $(AM_CFLAGS) -BUILT_SOURCES = \ - $(TYPES_SOURCE) +epiphany-resources.c: epiphany.gresource.xml + glib-compile-resources --target=$@ --sourcedir=$(top_srcdir)/data/ui --generate-source --c-name epiphany $(srcdir)/epiphany.gresource.xml + +epiphany-resources.h: epiphany.gresource.xml + glib-compile-resources --target=$@ --sourcedir=$(top_srcdir)/data/ui --generate-header --c-name epiphany $(srcdir)/epiphany.gresource.xml + +EPIPHANY_RESOURCES = \ + epiphany-resources.c \ + epiphany-resources.h \ + $(NULL) + +BUILT_SOURCES = \ + $(EPIPHANY_RESOURCES) \ + $(TYPES_SOURCE) \ + $(NULL) if ENABLE_SEED NOINST_H_FILES += \ @@ -123,7 +138,9 @@ libephymain_la_SOURCES += \ libephymain_la_CFLAGS += $(SEED_CFLAGS) endif # ENABLE_SEED -epiphany_SOURCES = ephy-main.c +epiphany_SOURCES = ephy-main.c \ + $(EPIPHANY_RESOURCES) \ + $(NULL) epiphany_CPPFLAGS = \ -I$(top_builddir)/lib \ diff --git a/src/bookmarks/ephy-bookmarks-editor.c b/src/bookmarks/ephy-bookmarks-editor.c index b30b542b6..f0f46929c 100644 --- a/src/bookmarks/ephy-bookmarks-editor.c +++ b/src/bookmarks/ephy-bookmarks-editor.c @@ -1553,9 +1553,9 @@ ephy_bookmarks_editor_construct (EphyBookmarksEditor *editor) gtk_ui_manager_insert_action_group (ui_merge, action_group, 0); - gtk_ui_manager_add_ui_from_file (ui_merge, - ephy_file ("epiphany-bookmark-editor-ui.xml"), - NULL); + gtk_ui_manager_add_ui_from_resource (ui_merge, + "/org/gnome/epiphany/epiphany-bookmark-editor-ui.xml", + NULL); gtk_window_add_accel_group (GTK_WINDOW (editor), gtk_ui_manager_get_accel_group (ui_merge)); gtk_ui_manager_ensure_update (ui_merge); diff --git a/src/ephy-encoding-dialog.c b/src/ephy-encoding-dialog.c index d3756df77..824ae5d0f 100644 --- a/src/ephy-encoding-dialog.c +++ b/src/ephy-encoding-dialog.c @@ -285,7 +285,7 @@ ephy_encoding_dialog_init (EphyEncodingDialog *dialog) (EPHY_EMBED_SHELL (ephy_shell))); ephy_dialog_construct (EPHY_DIALOG (dialog), - ephy_file ("epiphany.ui"), + "/org/gnome/epiphany/epiphany.ui", "encoding_dialog", NULL); diff --git a/src/ephy-history-window.c b/src/ephy-history-window.c index 88dd18d59..7581f3d2f 100644 --- a/src/ephy-history-window.c +++ b/src/ephy-history-window.c @@ -1145,9 +1145,9 @@ ephy_history_window_constructed (GObject *object) gtk_ui_manager_insert_action_group (ui_merge, action_group, 0); - gtk_ui_manager_add_ui_from_file (ui_merge, - ephy_file ("epiphany-history-window-ui.xml"), - NULL); + gtk_ui_manager_add_ui_from_resource (ui_merge, + "/org/gnome/epiphany/epiphany-history-window-ui.xml", + NULL); gtk_ui_manager_ensure_update (ui_merge); editor->priv->ui_merge = ui_merge; editor->priv->action_group = action_group; diff --git a/src/ephy-shell.c b/src/ephy-shell.c index 510017a7f..3e8450c9a 100644 --- a/src/ephy-shell.c +++ b/src/ephy-shell.c @@ -297,9 +297,9 @@ ephy_shell_startup (GApplication* application) application); builder = gtk_builder_new (); - gtk_builder_add_from_file (builder, - ephy_file ("epiphany-application-menu.ui"), - NULL); + gtk_builder_add_from_resource (builder, + "/org/gnome/epiphany/epiphany-application-menu.ui", + NULL); gtk_application_set_app_menu (GTK_APPLICATION (application), G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu"))); g_object_unref (builder); diff --git a/src/ephy-window.c b/src/ephy-window.c index 0636d5504..ee1c0c293 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -3183,6 +3183,30 @@ static const char* disabled_actions_for_app_mode[] = { "FileOpen", "ViewEncoding", "FileBookmarkPage" }; +static gboolean +_gtk_css_provider_load_from_resource (GtkCssProvider* provider, + const char *resource_path, + GError **error) +{ + GBytes *data; + gboolean res; + + g_return_val_if_fail (GTK_IS_CSS_PROVIDER (provider), FALSE); + g_return_val_if_fail (resource_path != NULL, FALSE); + + data = g_resources_lookup_data (resource_path, 0, error); + if (data == NULL) + return FALSE; + + res = gtk_css_provider_load_from_data (provider, + g_bytes_get_data (data, NULL), + g_bytes_get_size (data), + error); + g_bytes_unref (data); + + return res; +} + static GObject * ephy_window_constructor (GType type, guint n_construct_properties, @@ -3199,7 +3223,6 @@ ephy_window_constructor (GType type, GError *error = NULL; guint settings_connection; GtkCssProvider *css_provider; - GFile *css_file; int i; EphyEmbedShellMode mode; @@ -3275,21 +3298,22 @@ ephy_window_constructor (GType type, priv->downloads_box, "visible", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL); - /* now load the UI definition */ - gtk_ui_manager_add_ui_from_file - (priv->manager, ephy_file ("epiphany-ui.xml"), &error); + /* Now load the UI definition. */ + gtk_ui_manager_add_ui_from_resource (priv->manager, + "/org/gnome/epiphany/epiphany-ui.xml", + &error); if (error != NULL) { g_warning ("Could not merge epiphany-ui.xml: %s", error->message); g_error_free (error); + error = NULL; } - /* Attach the CSS provider to the window */ - css_file = g_file_new_for_path (ephy_file ("epiphany.css")); + /* Attach the CSS provider to the window. */ css_provider = gtk_css_provider_new (); - gtk_css_provider_load_from_file (css_provider, - css_file, - &error); + _gtk_css_provider_load_from_resource (css_provider, + "/org/gnome/epiphany/epiphany.css", + &error); if (error == NULL) { gtk_style_context_add_provider_for_screen (gtk_widget_get_screen (GTK_WIDGET (window)), @@ -3303,7 +3327,6 @@ ephy_window_constructor (GType type, } g_object_unref (css_provider); - g_object_unref (css_file); /* Initialize the menus */ priv->enc_menu = ephy_encoding_menu_new (window); diff --git a/src/epiphany.gresource.xml b/src/epiphany.gresource.xml new file mode 100644 index 000000000..1b881c0df --- /dev/null +++ b/src/epiphany.gresource.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<gresources> + <gresource prefix="/org/gnome/epiphany"> + <file compressed="true">epiphany.ui</file> + <file compressed="true">prefs-dialog.ui</file> + <file>epiphany-application-menu.ui</file> + <file>epiphany-ui.xml</file> + <file>epiphany-bookmark-editor-ui.xml</file> + <file>epiphany-history-window-ui.xml</file> + <file>epiphany.css</file> + </gresource> +</gresources> diff --git a/src/pdm-dialog.c b/src/pdm-dialog.c index 24d075869..b8cb4802a 100644 --- a/src/pdm-dialog.c +++ b/src/pdm-dialog.c @@ -625,7 +625,7 @@ show_cookies_properties (PdmDialog *dialog, cookie_dialog = ephy_dialog_new_with_parent (parent); ephy_dialog_construct (cookie_dialog, - ephy_file ("epiphany.ui"), + "/org/gnome/epiphany/epiphany.ui", "cookie_properties_dialog", NULL); @@ -1466,7 +1466,7 @@ pdm_dialog_init (PdmDialog *dialog) priv = dialog->priv = EPHY_PDM_DIALOG_GET_PRIVATE (dialog); ephy_dialog_construct (EPHY_DIALOG (dialog), - ephy_file ("epiphany.ui"), + "/org/gnome/epiphany/epiphany.ui", "pdm_dialog", NULL); diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c index d3c0c09ac..3ee1f617f 100644 --- a/src/prefs-dialog.c +++ b/src/prefs-dialog.c @@ -538,7 +538,7 @@ setup_add_language_dialog (PrefsDialog *pd) NULL)); ephy_dialog_construct (dialog, - ephy_file ("prefs-dialog.ui"), + "/org/gnome/epiphany/prefs-dialog.ui", "add_language_dialog", NULL); @@ -1031,7 +1031,7 @@ prefs_dialog_init (PrefsDialog *pd) pd->priv = EPHY_PREFS_DIALOG_GET_PRIVATE (pd); ephy_dialog_construct (dialog, - ephy_file ("prefs-dialog.ui"), + "/org/gnome/epiphany/prefs-dialog.ui", "prefs_dialog", NULL); |