[goffice] rsm: new resource manager.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] rsm: new resource manager.
- Date: Mon, 17 Oct 2011 20:52:22 +0000 (UTC)
commit 493f65fccb37147183969a33b5bbcc0f843f47e5
Author: Morten Welinder <terra gnome org>
Date: Mon Oct 17 16:51:51 2011 -0400
rsm: new resource manager.
ChangeLog | 8 ++++
goffice/goffice.c | 2 +
goffice/gtk/goffice-gtk.c | 15 +++++++-
goffice/utils/Makefile.am | 2 +
goffice/utils/go-rsm.c | 73 +++++++++++++++++++++++++++++++++++++++++
goffice/utils/go-rsm.h | 17 +++++++++
goffice/utils/goffice-utils.h | 1 +
7 files changed, 116 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a484fa6..5a45305 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,16 @@
2011-10-17 Morten Welinder <terra gnome org>
+ * goffice/utils/go-rsm.c: New file.
+
+ * goffice/gtk/goffice-gtk.c (go_gtk_builder_new)
+ (go_gtk_builder_new_internal): Handle resources.
+
+2011-10-17 Morten Welinder <terra gnome org>
+
* goffice/gtk/goffice-gtk.c (go_gtk_builder_new): Move
default-directory code from here...
(go_gtk_builder_new_internal): ...to here.
+
* */*.c: change to use go_gtk_builder_new_internal as appropriate.
2011-10-13 Jean Brefort <jean brefort normalesup org>
diff --git a/goffice/goffice.c b/goffice/goffice.c
index 3de9bf6..df9f3a8 100644
--- a/goffice/goffice.c
+++ b/goffice/goffice.c
@@ -205,6 +205,7 @@ libgoffice_init (void)
_go_conf_init ();
_go_fonts_init ();
_go_math_init ();
+ _go_rsm_init ();
/* keep trigger happy linkers from leaving things out */
_go_plugin_services_init ();
@@ -263,6 +264,7 @@ libgoffice_shutdown (void)
_go_number_format_shutdown ();
_go_string_shutdown ();
_go_locale_shutdown ();
+ _go_rsm_shutdown ();
#ifdef G_OS_WIN32
/* const_cast, we created these above */
g_free ((char *)libgoffice_data_dir);
diff --git a/goffice/gtk/goffice-gtk.c b/goffice/gtk/goffice-gtk.c
index 14c5194..f131108 100644
--- a/goffice/gtk/goffice-gtk.c
+++ b/goffice/gtk/goffice-gtk.c
@@ -125,7 +125,18 @@ go_gtk_builder_new (char const *uifile,
gui = gtk_builder_new ();
if (domain)
gtk_builder_set_translation_domain (gui, domain);
- if (!gtk_builder_add_from_file (gui, uifile, &error)) {
+
+ if (strncmp (uifile, "res:", 4) == 0) {
+ size_t len;
+ gconstpointer data = go_rsm_lookup (uifile + 4, &len);
+ if (!data) {
+ g_object_unref (gui);
+ gui = NULL;
+ } else if (!gtk_builder_add_from_string (gui, data, len, &error)) {
+ g_object_unref (gui);
+ gui = NULL;
+ }
+ } else if (!gtk_builder_add_from_file (gui, uifile, &error)) {
g_object_unref (gui);
gui = NULL;
}
@@ -155,7 +166,7 @@ go_gtk_builder_new_internal (char const *uifile,
char *f;
GtkBuilder *res;
- if (g_path_is_absolute (uifile))
+ if (g_path_is_absolute (uifile) || strncmp (uifile, "res:", 4) == 0)
return go_gtk_builder_new (uifile, domain, gcc);
f = g_build_filename (go_sys_data_dir (), "ui", uifile, NULL);
diff --git a/goffice/utils/Makefile.am b/goffice/utils/Makefile.am
index 4a1f324..1876d02 100644
--- a/goffice/utils/Makefile.am
+++ b/goffice/utils/Makefile.am
@@ -18,6 +18,7 @@ libgoffice_utils_la_SOURCES = \
go-path.c \
go-pattern.c \
go-geometry.c \
+ go-rsm.c \
go-string.c \
go-undo.c \
datetime.c \
@@ -61,6 +62,7 @@ libgoffice_utils_la_HEADERS = \
go-persist.h \
go-bezier.h \
go-editor.h \
+ go-rsm.h \
go-style.h \
go-styled-object.h
diff --git a/goffice/utils/go-rsm.c b/goffice/utils/go-rsm.c
new file mode 100644
index 0000000..9e551fd
--- /dev/null
+++ b/goffice/utils/go-rsm.c
@@ -0,0 +1,73 @@
+/*
+ * go-rsm.c: Resource manager for Goffice.
+ *
+ * Copyright (C) 2011 Morten Welinder (terra gnome org)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+
+#include <goffice/goffice.h>
+#include "go-rsm.h"
+
+typedef struct {
+ gconstpointer data;
+ size_t len;
+} GORSMResource;
+
+static GHashTable *rsm;
+
+void
+_go_rsm_init (void)
+{
+ rsm = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+}
+
+void
+_go_rsm_shutdown (void)
+{
+ g_hash_table_destroy (rsm);
+ rsm = NULL;
+}
+
+void
+go_rsm_register_file (const char *id, gconstpointer data, size_t len)
+{
+ GORSMResource *r;
+
+ g_return_if_fail (id != NULL);
+ g_return_if_fail (g_hash_table_lookup (rsm, id) == NULL);
+
+ r = g_new (GORSMResource, 1);
+ r->data = data;
+ r->len = len;
+ g_hash_table_insert (rsm, g_strdup (id), r);
+}
+
+gconstpointer
+go_rsm_lookup (const char *id, size_t *len)
+{
+ GORSMResource *r;
+
+ g_return_val_if_fail (id != NULL, NULL);
+
+ r = g_hash_table_lookup (rsm, id);
+ if (!r)
+ return NULL;
+
+ if (len)
+ *len = r->len;
+ return r->data;
+}
diff --git a/goffice/utils/go-rsm.h b/goffice/utils/go-rsm.h
new file mode 100644
index 0000000..228463d
--- /dev/null
+++ b/goffice/utils/go-rsm.h
@@ -0,0 +1,17 @@
+#ifndef GO_RSM_H
+#define GO_RSM_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+void _go_rsm_init (void);
+void _go_rsm_shutdown (void);
+
+void go_rsm_register_file (const char *id, gconstpointer data, size_t len);
+
+gconstpointer go_rsm_lookup (const char *id, size_t *len);
+
+G_END_DECLS
+
+#endif /* GO_RSM_H */
diff --git a/goffice/utils/goffice-utils.h b/goffice/utils/goffice-utils.h
index 7869bc9..9d21ad2 100644
--- a/goffice/utils/goffice-utils.h
+++ b/goffice/utils/goffice-utils.h
@@ -121,6 +121,7 @@ G_END_DECLS
#include <goffice/utils/go-path.h>
#include <goffice/utils/go-pattern.h>
#include <goffice/utils/go-persist.h>
+#include <goffice/utils/go-rsm.h>
#include <goffice/utils/go-string.h>
#include <goffice/utils/go-styled-object.h>
#include <goffice/utils/go-style.h>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]