From 54abef2bc0bbe4a578a2533239ef88e256e0a8b1 Mon Sep 17 00:00:00 2001 Message-Id: <54abef2bc0bbe4a578a2533239ef88e256e0a8b1.1714819019.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sun, 21 Oct 2007 23:26:20 +0100 Subject: [PATCH] disobedience now embeds image files Organization: Straylight/Edgeware From: Richard Kettlewell --- .bzrignore | 1 + debian/rules.m4 | 1 - disobedience/Makefile.am | 17 +++++++++++++++++ disobedience/misc.c | 26 ++++++++++++++++++++++---- 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/.bzrignore b/.bzrignore index 2625610..b419939 100644 --- a/.bzrignore +++ b/.bzrignore @@ -111,3 +111,4 @@ doc/disorder-decode.8 doc/plumbing.png disobedience/manual.h disobedience/manual.html +disobedience/images.h diff --git a/debian/rules.m4 b/debian/rules.m4 index 1fc08d3..2be1ffd 100644 --- a/debian/rules.m4 +++ b/debian/rules.m4 @@ -83,7 +83,6 @@ archpkg([disorder-playrtp], [ m4_dnl ]) archpkg([disobedience], [ m4_dnl - $(MAKE) DESTDIR=`pwd`/debian/disobedience -C images installdirs install mkdir -p debian/disobedience/usr/bin mkdir -p debian/disobedience/usr/share/man/man1 $(INSTALL) -m 755 disobedience/disobedience \ diff --git a/disobedience/Makefile.am b/disobedience/Makefile.am index 9b18ca9..99abd7f 100644 --- a/disobedience/Makefile.am +++ b/disobedience/Makefile.am @@ -22,6 +22,7 @@ bin_PROGRAMS=disobedience AM_CPPFLAGS=-I${top_srcdir}/lib -I../lib AM_CFLAGS=$(GLIB_CFLAGS) $(GTK_CFLAGS) +PNGS:=$(wildcard ${top_srcdir}/images/*.png) disobedience_SOURCES=disobedience.h disobedience.c client.c queue.c \ choose.c misc.c style.h control.c properties.c menu.c \ @@ -53,6 +54,22 @@ manual.h: manual.html ${top_srcdir}/scripts/text2c ${top_srcdir}/scripts/text2c manual manual.html > $@.tmp mv $@.tmp $@ +misc.o: images.h + +images.h: $(PNGS) + exec > @$.new; \ + for png in $(PNGS); do \ + name=`echo $$png | sed 's,.*/,,;s,\.png,,;'`; \ + gdk-pixbuf-csource --raw --name=image_$$name $$png; \ + done; \ + echo "static const struct image images[] = {"; \ + for png in $(PNGS); do \ + name=`echo $$png | sed 's,.*/,,;s,\.png,,;'`; \ + echo " { \"$$name.png\", image_$$name },"; \ + done; \ + echo "};" + mv @$.new $@ + EXTRA_DIST=disobedience.rc # check everything has working --help diff --git a/disobedience/misc.c b/disobedience/misc.c index c268654..2db0173 100644 --- a/disobedience/misc.c +++ b/disobedience/misc.c @@ -22,6 +22,14 @@ */ #include "disobedience.h" +#include "table.h" + +struct image { + const char *name; + const guint8 *data; +}; + +#include "images.h" /* Miscellaneous GTK+ stuff ------------------------------------------------ */ @@ -80,12 +88,22 @@ GdkPixbuf *find_image(const char *name) { GdkPixbuf *pb; char *path; GError *err = 0; + int n; if(!(pb = (GdkPixbuf *)cache_get(&image_cache_type, name))) { - byte_xasprintf(&path, "%s/static/%s", pkgdatadir, name); - if(!(pb = gdk_pixbuf_new_from_file(path, &err))) { - error(0, "%s", err->message); - return 0; + if((n = TABLE_FIND(images, struct image, name, name)) >= 0) { + /* Use the built-in copy */ + if(!(pb = gdk_pixbuf_new_from_inline(-1, images[n].data, FALSE, &err))) { + error(0, "%s", err->message); + return 0; + } + } else { + /* See if there's a copy on disk */ + byte_xasprintf(&path, "%s/static/%s", pkgdatadir, name); + if(!(pb = gdk_pixbuf_new_from_file(path, &err))) { + error(0, "%s", err->message); + return 0; + } } NW(cached_image); cache_put(&image_cache_type, name, pb); -- [mdw]