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 2625610af7f1ab78c97534df4bf782f436418dad..b419939fb0990e4eb5ef4ab5cd67211bbd5fb69f 100644 (file)
@@ -111,3 +111,4 @@ doc/disorder-decode.8
 doc/plumbing.png
 disobedience/manual.h
 disobedience/manual.html
+disobedience/images.h
index 1fc08d3eb325c86ad94fd54e0edd985a56429b8a..2be1ffd9f02bde4e589e857a62f1d5feea54c446 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 9b18ca99e7b68e6a7e534e255fb20d07ecde1ce7..99abd7fad7671a7d2919d5a8a2bf8f6a73d26717 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 c2686543eff851c969ec713179f8e58b1d1e1325..2db01732b6c1f7f5589c129df8c8be4308ed1ab5 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);