diff --git a/Makefile b/Makefile index 07f91bf..649038f 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ PACKAGE = Camera VERSION = 0.0.0 -SUBDIRS = data src +SUBDIRS = data src tools RM = rm -f LN = ln -f TAR = tar -czvf @@ -29,6 +29,9 @@ dist: $(PACKAGE)-$(VERSION)/src/Makefile \ $(PACKAGE)-$(VERSION)/src/camera.h \ $(PACKAGE)-$(VERSION)/src/project.conf \ + $(PACKAGE)-$(VERSION)/tools/gallery.c \ + $(PACKAGE)-$(VERSION)/tools/Makefile \ + $(PACKAGE)-$(VERSION)/tools/project.conf \ $(PACKAGE)-$(VERSION)/Makefile \ $(PACKAGE)-$(VERSION)/config.h \ $(PACKAGE)-$(VERSION)/project.conf diff --git a/project.conf b/project.conf index 5262b94..be995e6 100644 --- a/project.conf +++ b/project.conf @@ -1,6 +1,6 @@ package=Camera version=0.0.0 -subdirs=data,src +subdirs=data,src,tools config=h dist=Makefile,config.h diff --git a/tools/Makefile b/tools/Makefile new file mode 100644 index 0000000..df4e198 --- /dev/null +++ b/tools/Makefile @@ -0,0 +1,40 @@ +TARGETS = gallery +PREFIX = /usr/local +DESTDIR = +BINDIR = $(PREFIX)/bin +SBINDIR = $(PREFIX)/sbin +CC = cc +CPPFLAGSF= +CPPFLAGS= +CFLAGSF = -W `pkg-config --cflags glib-2.0` +CFLAGS = -Wall -g -O2 +LDFLAGS = `pkg-config --libs glib-2.0` +RM = rm -f +LN = ln -f +MKDIR = mkdir -p +INSTALL = install + + +all: $(TARGETS) + +gallery_OBJS = gallery.o +gallery_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) +gallery_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) + +gallery: $(gallery_OBJS) + $(CC) -o gallery $(gallery_OBJS) $(gallery_LDFLAGS) + +gallery.o: gallery.c + $(CC) $(gallery_CFLAGS) -c gallery.c + +clean: + $(RM) -- $(gallery_OBJS) + +distclean: clean + $(RM) -- $(TARGETS) + +install: $(TARGETS) + +uninstall: + +.PHONY: all clean distclean install uninstall diff --git a/tools/gallery.c b/tools/gallery.c new file mode 100644 index 0000000..7906251 --- /dev/null +++ b/tools/gallery.c @@ -0,0 +1,82 @@ +/* $Id$ */ +/* Copyright (c) 2013 Pierre Pronchery */ +/* This file is part of DeforaOS desktop camera */ +/* 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, version 3 of the License. + * + * 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, see . */ + + + +#include +#include +#include +#include +#include +#include + + +/* Gallery */ +/* private */ +/* prototypes */ +static int _gallery(void); + + +/* functions */ +/* gallery */ +static int _gallery(void) +{ + char const gallery[] = "gallery"; + char const * homedir; + char const dcim[] = "DCIM"; + char * path; + char * argv[] = { "browser", "--", NULL, NULL }; + + if((homedir = getenv("HOME")) == NULL) + homedir = g_get_home_dir(); + if((path = g_build_filename(homedir, dcim, NULL)) == NULL) + { + /* XXX errno may not be set */ + fprintf(stderr, "%s: %s\n", gallery, strerror(errno)); + return -1; + } + argv[2] = path; + execvp(argv[0], argv); + fprintf(stderr, "%s: %s: %s\n", gallery, argv[0], strerror(errno)); + g_free(path); + return -1; +} + + +/* usage */ +static int _usage(void) +{ + fputs("Usage: gallery\n", stderr); + return 1; +} + + +/* public */ +/* functions */ +/* main */ +int main(int argc, char * argv[]) +{ + int o; + + while((o = getopt(argc, argv, "")) != -1) + switch(o) + { + default: + return _usage(); + } + if(optind != argc) + return _usage(); + return (_gallery() == 0) ? 0 : 2; +} diff --git a/tools/project.conf b/tools/project.conf new file mode 100644 index 0000000..029e9b8 --- /dev/null +++ b/tools/project.conf @@ -0,0 +1,9 @@ +targets=gallery +cflags_force=-W `pkg-config --cflags glib-2.0` +cflags=-Wall -g -O2 +ldflags=`pkg-config --libs glib-2.0` +dist=Makefile + +[gallery] +type=binary +sources=gallery.c