chiark / gitweb /
disobedience now embeds image files
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 21 Oct 2007 22:26:20 +0000 (23:26 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 21 Oct 2007 22:26:20 +0000 (23:26 +0100)
.bzrignore
debian/rules.m4
disobedience/Makefile.am
disobedience/misc.c

index 2625610..b419939 100644 (file)
@@ -111,3 +111,4 @@ doc/disorder-decode.8
 doc/plumbing.png
 disobedience/manual.h
 disobedience/manual.html
+disobedience/images.h
index 1fc08d3..2be1ffd 100644 (file)
@@ -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 \
index 9b18ca9..99abd7f 100644 (file)
@@ -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
index c268654..2db0173 100644 (file)
  */
 
 #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);