[gnumeric] UI: use embedded ui files.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] UI: use embedded ui files.
- Date: Tue, 18 Oct 2011 17:33:31 +0000 (UTC)
commit 79c05d8d3838828b9d4b677876eab1a580a9b86e
Author: Morten Welinder <terra gnome org>
Date: Mon Oct 17 16:58:26 2011 -0400
UI: use embedded ui files.
src/Makefile.am | 2 +
src/dialogs/.gitignore | 1 +
src/dialogs/Makefile.am | 18 ++++++-
src/dialogs/embedded-ui.h | 12 +++++
src/gnm-rsm.c | 36 ++++++++++++++
src/gnm-rsm.h | 12 +++++
src/gui-util.c | 10 +++-
src/libgnumeric.c | 2 +
tools/embedder | 112 +++++++++++++++++++++++++++++++++++++++++++++
9 files changed, 199 insertions(+), 6 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index c5e1ca3..11d5c25 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -79,6 +79,8 @@ libspreadsheet_la_SOURCES = \
\
gnm-data-cache-source.h \
gnm-data-cache-source.c \
+ gnm-rsm.h \
+ gnm-rsm.c \
gnm-sheet-slicer.h \
gnm-sheet-slicer.c \
gnm-sheet-slicer-combo.h \
diff --git a/src/dialogs/.gitignore b/src/dialogs/.gitignore
index a18cc7c..aed4038 100644
--- a/src/dialogs/.gitignore
+++ b/src/dialogs/.gitignore
@@ -3,3 +3,4 @@ Makefile
.deps
*.gladep
*.bak
+embedded-ui.c
diff --git a/src/dialogs/Makefile.am b/src/dialogs/Makefile.am
index 0058331..be31804 100644
--- a/src/dialogs/Makefile.am
+++ b/src/dialogs/Makefile.am
@@ -90,11 +90,15 @@ base_files = \
dialog-workbook-attr.c \
dialog-zoom.c \
dialogs.h \
+ embedded-ui.c \
+ embedded-ui.h \
tool-dialogs.h \
dialog-printer-setup.c
uidir = $(gnumeric_datadir)/ui
-ui_DATA = \
+ui_DATA =
+
+embedded_uis = \
advanced-filter.ui \
anova-one.ui \
anova-two.ui \
@@ -103,8 +107,8 @@ ui_DATA = \
autoformat.ui \
autosave.ui \
cell-comment.ui \
- cell-format.ui \
cell-format-cond.ui \
+ cell-format.ui \
cell-sort.ui \
chi-squared.ui \
col-width.ui \
@@ -176,4 +180,12 @@ ui_DATA = \
wilcoxon-mann-whitney.ui \
workbook-attr.ui
-EXTRA_DIST = $(ui_DATA)
+BUILT_SOURCES = embedded-ui.c
+
+embedded-ui.c: $(top_srcdir)/tools/embedder $(embedded_uis)
+ @PERL@ $(top_srcdir)/tools/embedder \
+ --register-function=gnm_register_ui_files \
+ --include embedded-ui.h \
+ $(embedded_uis) >$(abs_builddir)/$@
+
+EXTRA_DIST = $(ui_DATA) $(embedded_uis)
diff --git a/src/dialogs/embedded-ui.h b/src/dialogs/embedded-ui.h
new file mode 100644
index 0000000..a791959
--- /dev/null
+++ b/src/dialogs/embedded-ui.h
@@ -0,0 +1,12 @@
+#ifndef GNUMERIC_DIALOG_REGISTER_UI_FILES_H
+#define GNUMERIC_DIALOG_REGISTER_UI_FILES_H
+
+#include "gnumeric.h"
+
+G_BEGIN_DECLS
+
+void gnm_register_ui_files (void);
+
+G_END_DECLS
+
+#endif
diff --git a/src/gnm-rsm.c b/src/gnm-rsm.c
new file mode 100644
index 0000000..a4f3a1f
--- /dev/null
+++ b/src/gnm-rsm.c
@@ -0,0 +1,36 @@
+/*
+ * gnm-rsm.c: Resource manager for Gnumeric.
+ *
+ * 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 <gnumeric-config.h>
+#include <goffice/goffice.h>
+#include "gnm-rsm.h"
+
+void
+gnm_rsm_register_file (const char *id, gconstpointer data, size_t len)
+{
+ char *id2;
+
+ g_return_if_fail (id != NULL);
+
+ id2 = g_strconcat ("gnm:", id, NULL);
+ go_rsm_register_file (id2, data, len);
+ g_free (id2);
+}
diff --git a/src/gnm-rsm.h b/src/gnm-rsm.h
new file mode 100644
index 0000000..4944ffa
--- /dev/null
+++ b/src/gnm-rsm.h
@@ -0,0 +1,12 @@
+#ifndef GNM_RSM_H
+#define GNM_RSM_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+void gnm_rsm_register_file (const char *id, gconstpointer data, size_t len);
+
+G_END_DECLS
+
+#endif /* GNM_RSM_H */
diff --git a/src/gui-util.c b/src/gui-util.c
index 8c69138..6eeb95d 100644
--- a/src/gui-util.c
+++ b/src/gui-util.c
@@ -25,6 +25,7 @@
#include "wbc-gtk.h"
#include "dead-kittens.h"
#include "widgets/gnumeric-expr-entry.h"
+#include "gnm-rsm.h"
#include <goffice/goffice.h>
#include <gtk/gtk.h>
@@ -549,10 +550,13 @@ GtkBuilder *
gnm_gtk_builder_new (char const *uifile, char const *domain, GOCmdContext *cc)
{
GtkBuilder *gui;
+ char *f;
- char *f = g_path_is_absolute (uifile)
- ? g_strdup (uifile)
- : g_build_filename (gnm_sys_data_dir (), "ui", uifile, NULL);
+ if (g_path_is_absolute (uifile)) {
+ f = g_strdup (uifile);
+ } else {
+ f = g_strconcat ("res:gnm:", uifile, NULL);
+ }
gui = go_gtk_builder_new (f, domain, cc);
g_free (f);
diff --git a/src/libgnumeric.c b/src/libgnumeric.c
index 3793c0d..02ce1fb 100644
--- a/src/libgnumeric.c
+++ b/src/libgnumeric.c
@@ -55,6 +55,7 @@
#include "mathfunc.h"
#include "hlink.h"
#include "wbc-gtk-impl.h"
+#include "dialogs/embedded-ui.h"
#include <goffice/goffice.h>
#ifdef HAVE_SYS_RESOURCE_H
@@ -270,6 +271,7 @@ gnm_init (void)
go_plugin_loader_module_register_version ("gnumeric", GNM_VERSION_FULL);
g_object_new (GNM_APP_TYPE, NULL);
+ gnm_register_ui_files ();
mathfunc_init ();
gnm_style_init ();
diff --git a/tools/embedder b/tools/embedder
new file mode 100644
index 0000000..21a7571
--- /dev/null
+++ b/tools/embedder
@@ -0,0 +1,112 @@
+#!/usr/bin/perl
+
+use strict;
+use Getopt::Long;
+
+my $myself = $0;
+$myself =~ s|^.*/||;
+
+my $WIDTH = 70;
+my $regfunc = undef;
+my @includes;
+
+&GetOptions("register-function=s" => \$regfunc,
+ "include=s" => \ includes,
+ );
+
+# -----------------------------------------------------------------------------
+
+print "/* Generated by $myself -- do not edit! */\n\n";
+print "#include <gnumeric-config.h>\n";
+print "#include <gnm-rsm.h>\n\n";
+foreach (@includes) {
+ print "#include \"$_\"\n";
+}
+
+my $fileno = 0;
+my $reg = "";
+foreach my $file (@ARGV) {
+ &embed ($file);
+}
+print "void\n";
+print "$regfunc (void)\n";
+print "{\n";
+print $reg;
+print "}\n";
+
+sub embed {
+ my ($file) = @_;
+
+ print "/* Embedded file $file */\n";
+
+ my $data;
+ {
+ local (*FIL);
+ local ($/);
+ $/ = undef;
+ open (*FIL, "<$file") or die "$myself: cannot read $file: $!\n";
+ $data = <FIL>;
+ }
+
+ my $id = "data$fileno";
+ $fileno++;
+
+ &embed_data ($data, $id);
+
+ my $len = length ($data);
+ $reg .= " gnm_rsm_register_file (\"$file\", $id, $len);\n";
+}
+
+sub embed_data {
+ my ($data,$id) = @_;
+
+ my $len = length ($data);
+ if ($len == 0) {
+ print "static const char ${id}[] = \"\";\n";
+ return;
+ }
+
+ print "static const char ${id}[] =\n";
+ my $linelen = 0;
+ my $nohex = 0;
+ foreach my $c (split (//, $data)) {
+ if ($linelen > $WIDTH) {
+ print "\"\n";
+ $linelen = 0;
+ }
+ if ($linelen == 0) {
+ print " \"";
+ $linelen += 3;
+ }
+
+ my $thisnohex = $nohex;
+ $nohex = 0;
+
+ my $ci = ord ($c);
+ if ($c eq "\n") {
+ print "\\n";
+ $linelen += 2;
+ } elsif ($c eq "\t") {
+ print "\\t";
+ $linelen += 2;
+ } elsif ($c eq '"') {
+ print "\\\"";
+ $linelen += 2;
+ } elsif ($c eq "\\") {
+ print "\\\\";
+ $linelen += 2;
+ } elsif ($ci >= 32 && $ci < 128) {
+ if ($thisnohex && $c =~ /[a-fA-f0-9]/) {
+ print "\"\"";
+ $linelen += 2;
+ }
+ print $c;
+ $linelen += 1;
+ } else {
+ printf ("\\x%02x", $ci);
+ $linelen += 4;
+ $nohex = 1;
+ }
+ }
+ print "\";\n\n";
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]