[almanah] Added the App menu as with GResources
- From: Álvaro Peña <alvaropg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [almanah] Added the App menu as with GResources
- Date: Thu, 22 Jan 2015 18:34:03 +0000 (UTC)
commit e4834729a6f3c5cc9fa0cac62cb7396d66f31e6b
Author: Álvaro Peña <alvaropg gmail com>
Date: Thu Jan 22 19:31:11 2015 +0100
Added the App menu as with GResources
The GtkApplication App menu now is auto-loaded through a GResource.
See https://bugzilla.gnome.org/show_bug.cgi?id=743086
configure.ac | 4 ++
data/Makefile.am | 15 +++++++-
data/almanah.gresource.xml | 6 +++
data/{almanah-app-menu.ui => gtk/menus.ui} | 2 +-
src/application.c | 56 +++++++++-------------------
src/interface.c | 9 ++++
src/interface.h | 1 +
7 files changed, 53 insertions(+), 40 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index b901d3f..26aba67 100644
--- a/configure.ac
+++ b/configure.ac
@@ -145,6 +145,10 @@ AC_FUNC_MKTIME
AC_TYPE_SIZE_T
AC_SYS_LARGEFILE
+dnl GResource
+GLIB_COMPILE_RESOURCES=`$PKG_CONFIG --variable glib_compile_resources gio-2.0`
+AC_SUBST(GLIB_COMPILE_RESOURCES)
+
AC_CONFIG_FILES([
Makefile
src/Makefile
diff --git a/data/Makefile.am b/data/Makefile.am
index 82cee89..d3086c2 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -4,6 +4,20 @@ EXTRA_DIST =
CLEANFILES =
###############################################################################
+# GResource
+###############################################################################
+
+resource_files = $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies
$(srcdir)/almanah.gresource.xml)
+almanah.gresource: almanah.gresource.xml $(resource_files)
+ $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) $<
+
+resourcedir = $(pkgdatadir)
+resource_DATA = almanah.gresource
+
+EXTRA_DIST += $(resource_files)
+CLEANFILES += almanah.gresource
+
+###############################################################################
# Icons
###############################################################################
@@ -27,7 +41,6 @@ update-icon-cache:
uidir = $(datadir)/almanah
ui_DATA = \
almanah.ui \
- almanah-app-menu.ui \
almanah.css
EXTRA_DIST += $(ui_DATA)
diff --git a/data/almanah.gresource.xml b/data/almanah.gresource.xml
new file mode 100644
index 0000000..a422afa
--- /dev/null
+++ b/data/almanah.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/org/gnome/Almanah">
+ <file preprocess="xml-stripblanks">gtk/menus.ui</file>
+ </gresource>
+</gresources>
diff --git a/data/almanah-app-menu.ui b/data/gtk/menus.ui
similarity index 97%
rename from data/almanah-app-menu.ui
rename to data/gtk/menus.ui
index 2714aef..1689f93 100644
--- a/data/almanah-app-menu.ui
+++ b/data/gtk/menus.ui
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<interface>
- <menu id="almanah_app_menu">
+ <menu id="app-menu">
<section>
<item>
<attribute name="label" translatable="yes">_Search</attribute>
diff --git a/src/application.c b/src/application.c
index 8ae28f4..15fe0d8 100644
--- a/src/application.c
+++ b/src/application.c
@@ -43,9 +43,7 @@ static void activate (GApplication *application);
static gint handle_command_line (GApplication *application, GApplicationCommandLine *command_line);
static void window_removed (GtkApplication *application, GtkWindow *window);
-static void almanah_application_init_actions (AlmanahApplication *self);
-
-/* GMenu application actions */
+/* Application actions */
static void action_search_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
static void action_preferences_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
static void action_import_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
@@ -57,6 +55,7 @@ static void action_quit_cb (GSimpleAction *action, GVariant *parameter, gpointer
struct _AlmanahApplicationPrivate {
gboolean debug;
+ GResource *resource;
GSettings *settings;
AlmanahStorageManager *storage_manager;
AlmanahEventManager *event_manager;
@@ -113,8 +112,16 @@ almanah_application_class_init (AlmanahApplicationClass *klass)
static void
almanah_application_init (AlmanahApplication *self)
{
+ GError *error = NULL;
+
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, ALMANAH_TYPE_APPLICATION, AlmanahApplicationPrivate);
self->priv->debug = FALSE;
+ self->priv->resource = g_resource_load (almanah_get_resource_filename (), &error);
+ if (error == NULL) {
+ g_resources_register (self->priv->resource);
+ } else {
+ g_error (_("Error loading resources file: %s"), error->message);
+ }
}
static void
@@ -165,6 +172,12 @@ dispose (GObject *object)
g_object_unref (priv->print_settings);
priv->print_settings = NULL;
+ if (priv->resource) {
+ g_resources_unregister (priv->resource);
+ g_resource_unref (priv->resource);
+ }
+ priv->resource = NULL;
+
/* Chain up to the parent class */
G_OBJECT_CLASS (almanah_application_parent_class)->dispose (object);
}
@@ -262,8 +275,8 @@ startup (GApplication *application)
priv->page_setup = gtk_page_setup_new ();
- /* Load GMenu application actions */
- almanah_application_init_actions (ALMANAH_APPLICATION (application));
+ /* Application actions */
+ g_action_map_add_action_entries (G_ACTION_MAP (application), app_entries, G_N_ELEMENTS (app_entries),
application);
css_path = g_build_filename (almanah_get_css_path (), "almanah.css", NULL);
style_provider = gtk_css_provider_new ();
@@ -406,39 +419,6 @@ window_removed (GtkApplication *application, GtkWindow *window)
}
static void
-almanah_application_init_actions (AlmanahApplication *self)
-{
- GtkBuilder *builder;
- GError *error = NULL;
- const gchar *interface_filename = almanah_get_interface_app_menu_filename ();
-
- g_action_map_add_action_entries (G_ACTION_MAP (self), app_entries, G_N_ELEMENTS (app_entries), self);
-
- builder = gtk_builder_new ();
- if (gtk_builder_add_from_file (builder, interface_filename, &error) == 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"),
interface_filename);
- 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);
-
- exit (1);
- }
-
- gtk_builder_set_translation_domain (builder, GETTEXT_PACKAGE);
- gtk_application_set_app_menu (GTK_APPLICATION (self), G_MENU_MODEL (gtk_builder_get_object (builder,
"almanah_app_menu")));
-
- g_object_unref (builder);
-}
-
-static void
action_search_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data)
{
AlmanahApplication *application;
diff --git a/src/interface.c b/src/interface.c
index ea93784..f86b31e 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -52,6 +52,15 @@ almanah_get_css_path (void)
return PACKAGE_DATA_DIR"/almanah";
}
+const gchar *
+almanah_get_resource_filename(void)
+{
+ if (g_file_test ("./data/almanah.gresource", G_FILE_TEST_EXISTS) == TRUE)
+ return "./data/almanah.gresource";
+ else
+ return PACKAGE_DATA_DIR"/almanah/almanah.gresource";
+}
+
void
almanah_interface_create_text_tags (GtkTextBuffer *text_buffer, gboolean connect_events)
{
diff --git a/src/interface.h b/src/interface.h
index e4e4f6f..603290f 100644
--- a/src/interface.h
+++ b/src/interface.h
@@ -27,6 +27,7 @@ G_BEGIN_DECLS
const gchar *almanah_get_interface_filename (void);
const gchar *almanah_get_interface_app_menu_filename (void);
const gchar *almanah_get_css_path (void);
+const gchar *almanah_get_resource_filename(void);
void almanah_interface_create_text_tags (GtkTextBuffer *text_buffer, gboolean connect_events);
void almanah_calendar_month_changed_cb (GtkCalendar *calendar, gpointer user_data);
gboolean almanah_run_on_screen (GdkScreen *screen, const gchar *command_line, GError **error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]