From: Andre Noll Date: Tue, 23 Oct 2007 16:13:21 +0000 (+0200) Subject: Remove para_sdl_gui, para_slider, para_krell. X-Git-Tag: v0.3.0~246 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=d11d02dc33b31084650ea181896181d02b3a50d3;p=paraslash.git Remove para_sdl_gui, para_slider, para_krell. These were all really crappy, probably not used by anybody, and they broke due to the rename of the status item text or the switch to the new afs. So let's get rid of them. para_gui is here to stay though. --- diff --git a/FEATURES b/FEATURES index 38cda9fc..d436518f 100644 --- a/FEATURES +++ b/FEATURES @@ -19,11 +19,5 @@ Features * well documented * complete API-Reference * easily extendible due to its modular design - * various user interfaces and utilities: - * para_gui. Curses based interface - * para_sdl_gui. Shows images on a per song basis and can be used - as a screen saver. - * para_krell. A gkrellm2 plugin - * para_slider. User-friendly stream creator - * para_dbadm. Simple curses interface for changing attributes. - * para_fade. volume fader and alarm clock. + * curses-based interface + * volume fader and alarm clock. diff --git a/Makefile.in b/Makefile.in index 16fa9505..06fe7d9d 100644 --- a/Makefile.in +++ b/Makefile.in @@ -4,7 +4,6 @@ exec_prefix = @exec_prefix@ BINDIR = @bindir@ VARDIR = /var/paraslash PKGDATADIR = @datarootdir@/@PACKAGE_NAME@ -FONTDIR = $(PKGDATADIR)/fonts PICDIR = $(PKGDATADIR)/pics MANDIR = @datarootdir@/man/man1 @@ -37,7 +36,6 @@ CPPFLAGS += -Wstrict-prototypes CPPFLAGS += -Wchar-subscripts CPPFLAGS += -Wformat-security CPPFLAGS += -DBINDIR='"$(BINDIR)"' -CPPFLAGS += -DFONTDIR='"$(PKGDATADIR)/fonts"' CPPFLAGS += -DPICDIR='"$(PKGDATADIR)/pics"' CPPFLAGS += -DBUILD_DATE='"$(build_date)"' CPPFLAGS += -DSYSTEM='"$(system)"' @@ -55,10 +53,9 @@ CPPFLAGS += @ncurses_cppflags@ BINARIES = para_server para_client para_audioc para_recv \ para_filter para_write para_fsck @extra_binaries@ -man_binaries := $(filter-out para_slider para_krell.so, $(BINARIES)) +man_binaries := $(BINARIES) man_pages := $(patsubst %, man/man1/%.1, $(man_binaries)) man_pages_html := $(patsubst %, man/html/%.html, $(man_binaries)) -FONTS := $(wildcard fonts/*.png) PICS := $(wildcard pics/paraslash/*.jpg) gengetopts := $(wildcard *.ggo) gengetopts_c := $(gengetopts:.ggo=.cmdline.c) @@ -72,9 +69,7 @@ gruta_in := $(grutatxt:=.in.html) gruta_in := $(patsubst %,web/%,$(gruta_in)) gruta_html := $(grutatxt:=.html) gruta_html := $(patsubst %,web/sync/%,$(gruta_html)) -shots := gui-2005-11-12.png para_audiod-startup.txt para_krell-2005-02.png \ - para_server-startup.txt para_slider-2004-12.png sdl_gui.jpg \ - para_krell-2005-02.png +shots := gui-2005-11-12.png para_audiod-startup.txt para_server-startup.txt shots := $(patsubst %,web/sync/%,$(shots)) web_pics := web/sync/paraslash.png web/sync/paraslash.ico web_misc := overview.pdf versions/@PACKAGE_TARNAME@-@PACKAGE_VERSION@.tar.bz2 PUBLIC_KEY \ @@ -97,11 +92,7 @@ gruta: $(gen_html) $(gruta_html) man: $(man_pages) html_man: $(man_pages_html) -sdl_gui_objs = sdl_gui.cmdline.o SFont.o sdl_gui.o gui_common.o exec.o \ - close_on_fork.o string.o stat.o fd.o fade_objs = fade.cmdline.o fade.o exec.o close_on_fork.o string.o fd.o -krell_objs = krell.o string.o -slider_objs = slider.o string.o fsck_objs = osl.o rbtree.o fsck.o string.o sha1.o fsck.cmdline.o *.o: para.h config.h gcc-compat.h @@ -205,12 +196,6 @@ aac_common.o: aac_common.c aac_afh.o: aac_afh.c $(CC) -c $(CPPFLAGS) $(DEBUG_CPPFLAGS) @faad_cppflags@ $< -slider.o: slider.c - $(CC) -c -Wall -o $@ -g @GLIB_CFLAGS@ @GTK_CFLAGS@ $< - -krell.o: krell.c - $(CC) -Wall -O -g -fPIC @GTK_CFLAGS@ -c -o $@ krell.c - %.cmdline.o: %.cmdline.c $(CC) -c $(CPPFLAGS) $< @@ -223,9 +208,6 @@ para_recv: @recv_objs@ para_filter: @filter_objs@ $(CC) $(LDFLAGS) @filter_objs@ -o $@ @filter_ldflags@ -para_slider: $(slider_objs) - $(CC) $(LDFLAGS) $(slider_objs) -o $@ @GTK_LIBS@ @GLIB_LIBS@ -lzmw - para_client: @client_objs@ $(CC) $(LDFLAGS) -o $@ @client_objs@ @client_ldflags@ @@ -247,15 +229,9 @@ para_server: @server_objs@ para_fsck: @fsck_objs@ $(CC) $(LDFLAGS) -o $@ @fsck_objs@ @fsck_ldflags@ -para_sdl_gui: $(sdl_gui_objs) - $(CC) $(LDFLAGS) -o $@ $(sdl_gui_objs) -lSDL_image - para_write: @write_objs@ $(CC) $(LDFLAGS) -o $@ @write_objs@ @write_ldflags@ -para_krell.so: $(krell_objs) - $(CC) -Wall -fPIC @GTK_CFLAGS@ krell.o -o $@ @GTK_LIBS@ -shared - clean: rm -f *.o $(BINARIES) distclean: clean @@ -271,9 +247,8 @@ maintainer-clean: distclean install: all man - mkdir -p $(BINDIR) $(FONTDIR) $(PICDIR) $(MANDIR) + mkdir -p $(BINDIR) $(PICDIR) $(MANDIR) $(install_sh) -s -m 755 $(BINARIES) $(BINDIR) - $(install_sh) -m 644 $(FONTS) $(FONTDIR) $(install_sh) -m 644 $(PICS) $(PICDIR) $(install_sh) -m 644 $(man_pages) $(MANDIR) mkdir -p $(VARDIR) >/dev/null 2>&1 || true # not fatal, so don't complain diff --git a/configure.ac b/configure.ac index aef9d1ec..0ecc297f 100644 --- a/configure.ac +++ b/configure.ac @@ -30,7 +30,7 @@ AC_CHECK_HEADERS([arpa/inet.h ctype.h fcntl.h limits.h netdb.h netinet/in.h \ sys/ipc.h unistd.h utime.h stddef.h], [], [AC_MSG_ERROR([$ac_header not found])]) -AC_CHECK_HEADER(linux/soundcard.h, [extras="$extras para_fade"], +AC_CHECK_HEADER(linux/soundcard.h, [extras="$extras para_fade"], [AC_MSG_WARN([linux/soundcard.h not found, cannot build para_fade])]) # Checks for typedefs, structures, and compiler characteristics. @@ -271,35 +271,6 @@ if test ${have_core_audio} = yes; then default_writer="OSX_WRITE" AC_DEFINE(HAVE_CORE_AUDIO, 1, define to 1 on Mac Os X) fi -########################################################################### gtk2 -build_para_krell="yes" -OLD_CPPFLAGS="$CPPFLAGS" -OLD_LD_FLAGS="$LDFLAGS" -OLD_LIBS="$LIBS" -pkg_modules="gtk+-2.0 >= 2.0.0" -PKG_CHECK_MODULES(GLIB, [glib-2.0 >= 2.0.4], [], [build_para_krell="no"]) -PKG_CHECK_MODULES(GTK, [$pkg_modules], [], [build_para_krell="no"]) -CPPFLAGS="$GTK_CFLAGS $GLIB_CFLAGS" -LDFLAGS="$LDFLAGS $GTK_LIBS" -AC_CHECK_HEADER(gkrellm2/gkrellm.h, [], [build_para_krell="no"]) -if test "$build_para_krell" = "yes"; then - AC_SUBST(GTK_CFLAGS) - AC_SUBST(GTK_LIBS) - extras="$extras para_krell.so" -else - AC_MSG_WARN([can not build para_krell]) -fi -CPPFLAGS="$OLD_CPPFLAGS" -LDFLAGS="$OLD_LDFLAGS" -LIBS="$OLD_LIBS" -########################################################################### sdl -# FIXME -AC_CHECK_LIB([SDL_image], [SDL_Init], [extras="$extras para_sdl_gui"], [ - AC_MSG_WARN([libSDL_image not found, cannot build para_sdl_gui]) -]) -AC_CHECK_HEADER(SDL/SDL.h, [], - [AC_MSG_WARN([SDL/SDL.h not found])]) - ########################################################################### ogg have_ogg="yes" OLD_CPPFLAGS="$CPPFLAGS" @@ -510,28 +481,6 @@ fi CPPFLAGS="$OLD_CPPFLAGS" LDFLAGS="$OLD_LDFLAGS" LIBS="$OLD_LIBS" -########################################################################### zmw -build_slider="yes" -OLD_CPPFLAGS="$CPPFLAGS" -OLD_LD_FLAGS="$LDFLAGS" -OLD_LIBS="$LIBS" -PKG_CHECK_MODULES(GTK, [$pkg_modules], [], [build_para_slider="no"]) -PKG_CHECK_MODULES(GLIB, [glib-2.0 >= 2.0.4], [], [build_slider="no"]) -CPPFLAGS="$GTK_CFLAGS $GLIB_CFLAGS" -LDFLAGS="$LDFLAGS $GTK_LIBS" -AC_CHECK_HEADERS([zmw/zmw.h], [], [build_slider="no"]) -AC_CHECK_LIB([zmw], [zmw_init], [], [build_slider="no"]) -if test "$build_slider" = "no"; then - AC_MSG_WARN([will not build para_slider]) -else - extras="$extras para_slider" -fi -CPPFLAGS="$OLD_CPPFLAGS" -LDFLAGS="$OLD_LDFLAGS" -LIBS="$OLD_LIBS" - - - AC_SUBST(extra_binaries, [$extras]) @@ -541,7 +490,6 @@ AC_SUBST(install_sh, [$INSTALL]) AC_CONFIG_FILES([Makefile]) - AC_DEFUN([add_dot_o],[$(for i in $@; do printf "$i.o "; done)]) AC_DEFUN([objlist_to_errlist],[$(for i in $@; do printf "DEFINE_ERRLIST($(echo $i| tr 'a-z' 'A-Z'));"; done) [const char **para_errlist[[]]] = {$(for i in $@; do printf "PARA_ERRLIST($(echo $i | tr 'a-z' 'A-Z')), "; done) }]) diff --git a/fonts/24P_Arial_Blue.png b/fonts/24P_Arial_Blue.png deleted file mode 100644 index bc71187f..00000000 Binary files a/fonts/24P_Arial_Blue.png and /dev/null differ diff --git a/fonts/24P_Arial_Metallic_Yellow.png b/fonts/24P_Arial_Metallic_Yellow.png deleted file mode 100644 index 2eec3992..00000000 Binary files a/fonts/24P_Arial_Metallic_Yellow.png and /dev/null differ diff --git a/fonts/24P_Arial_NeonBlue.png b/fonts/24P_Arial_NeonBlue.png deleted file mode 100644 index 184218f6..00000000 Binary files a/fonts/24P_Arial_NeonBlue.png and /dev/null differ diff --git a/fonts/24P_Arial_NeonYellow.png b/fonts/24P_Arial_NeonYellow.png deleted file mode 100644 index eecd4e52..00000000 Binary files a/fonts/24P_Arial_NeonYellow.png and /dev/null differ diff --git a/fonts/24P_Copperplate_Blue.png b/fonts/24P_Copperplate_Blue.png deleted file mode 100644 index 7d481956..00000000 Binary files a/fonts/24P_Copperplate_Blue.png and /dev/null differ diff --git a/krell.c b/krell.c deleted file mode 100644 index baafbf3a..00000000 --- a/krell.c +++ /dev/null @@ -1,404 +0,0 @@ -/* - * Copyright (C) 2004-2005 Andre Noll - * - * Licensed under the GPL v2. For licencing details see COPYING. - */ - - -//#define PRINTF printf -#define PRINTF(a, ...) - -#include -#include -#include -#include -#include -#include -#include - -static void create_para_ctrl(GtkWidget *, gint); -static void update_para_ctrl(void); -static void create_tab(GtkWidget *); -static void apply_config(void); -static void load_config(gchar *); -static void save_config(FILE *); - -static GkrellmMonitor monitor = { - "Parakrell", /* Name, for config tab. */ - 0, /* Id, 0 if a plugin */ - create_para_ctrl, /* The create function */ - update_para_ctrl, /* The update function */ - create_tab, /* The config tab create function */ - apply_config, /* Apply the config function */ - save_config, /* Save user config */ - load_config, /* Load user config */ - "para_krell", /* config keyword */ - NULL, /* Undefined 2 */ - NULL, /* Undefined 1 */ - NULL, /* Undefined 0 */ - MON_APM, /* Insert plugin before this monitor */ - NULL, /* Handle if a plugin, filled in by GKrellM */ - NULL /* path if a plugin, filled in by GKrellM */ -}; - -typedef struct { - GkrellmPiximage *image; - GkrellmDecalbutton *button; - gint x,y,w,h; - double x_scale,y_scale; -} ControlButton; - -static ControlButton prev_button = { - .image = NULL, - .button = NULL, - .x = 10, - .y = 10, - .w = 50, - .h = 50, - .x_scale = 1, - .y_scale = 1, -}; - -GkrellmPiximage *piximage; -GkrellmPanel *panel; -GtkWidget *fileread_vbox; -GdkPixbuf *pixbuf; -gint song_change_input_id; -FILE *song_change_fd; -GIOChannel *song_change_channel; - -static struct timeval sc_open_time; - -static gchar *info_text = - "Parakrell displays an image corresponding to the soundfile\n" - "currently played by paraslash.\n\n" - - "The plugin's panel is divided in 9 small squares, like \n" - "the numpad on a PC keyboard. For each square there is an \n" - "associated button and a number between 1 and 9.\n \n" - - "Each button is bound to three different commands for left, \n" - "middle and right mouse button. Middle and right button are \n" - "reserved for setting volume and jumping around in the song, \n" - "respectively. Left button works as follows:\n \n" - - "7 8 9 7: slider, 8: sdl_gui, 9: next \n" - "4 5 6 4: ps, 5: play, 6: dbadm \n" - "1 2 3 1: stop, 2: gui, 3: pause\n" - - "\n\nAuthor:\n" - "Andre Noll \n" - "Copyright (C) 2004-2005\n" - "Distributed under the GNU General Public License.\n"; - -#define MAXLINE 255 - -static gboolean launch_cmd(char *cmd) -{ - - gchar **argv; - GError *err = NULL; - gboolean res; - - PRINTF("%s: \n", __func__); - if (!cmd || *cmd == '\0') - return -1; - - g_shell_parse_argv(cmd, NULL, &argv, NULL); - res = g_spawn_async( - NULL, - argv, - NULL, - G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL, - NULL, - NULL, - NULL, - &err - ); - if (!res && err) { - gkrellm_message_dialog(NULL, err->message); - g_error_free(err); - } - g_strfreev(argv); - return res; -} - -static gboolean cb_in_button(GkrellmDecalbutton *b, - GdkEventButton *ev, ControlButton *cbut) -{ - gint x, y, area, width = gkrellm_chart_width(); - x = (int) (3 * ev->x / width); - y = (int) (3 - 3 * ev->y / width); - area = 3 * y + x + 1; - char buf[MAXLINE]; - - PRINTF("%s: button %i pressed on area %i\n", __func__, - ev->button, area); - if (ev->button == 1) { - switch (area) { - case 1: - launch_cmd("para_client stop"); - return 0; - case 2: - launch_cmd("xterm -e para_gui -a"); - return 0; - case 3: - launch_cmd("para_client pause"); - return 0; - case 4: - launch_cmd("para_client ps"); - return 0; - case 5: - launch_cmd("para_client play"); - return 0; - case 6: - launch_cmd("xterm -e para_dbadm"); - return 0; - case 7: - launch_cmd("para_slider"); - return 0; - case 8: - launch_cmd("para_sdl_gui -f"); - return 0; - case 9: - launch_cmd("para_client next"); - return 0; - } - return 0; - } - sprintf(buf, "%s %i", ev->button == 2? "aumix -v" : "para_client jmp", - area * 10); - return launch_cmd(buf); -} - -static void make_button(ControlButton *cbut, gint fn_id) -{ - PRINTF("%s: gkrellm_make_scaled_button\n", __func__); - cbut->button = gkrellm_make_scaled_button( - panel, - cbut->image, - NULL, - GINT_TO_POINTER(fn_id), - FALSE, - FALSE, - 2, - 0, - 1, - cbut->x, - cbut->y, - cbut->w, - cbut->h - ); - PRINTF("%s: making botton\n", __func__); - gkrellm_set_in_button_callback(cbut->button, cb_in_button, cbut); -} - - -static void load_img(void) -{ - gint width = gkrellm_chart_width(); - gint out = 0, ret; - FILE *pipe = NULL; - char buf[MAXLINE]; - size_t num_read = 0; - gchar *filename = gkrellm_make_data_file_name("para", "pic.jpg"); - - PRINTF("%s: Opening %s\n", __func__, filename); - if ((out = creat(filename, S_IRUSR | S_IWUSR)) < 0) { - perror("open"); - goto out; - } - pipe = popen("para_client pic", "r"); - if (!pipe) - goto out; - while ((ret = read(fileno(pipe), buf, sizeof(buf) - 1)) > 0) { - if (write(out, buf, ret) < 0) { - perror("Write"); - goto out; - } - num_read += ret; - } - if (ret < 0) { - PRINTF("%s: Read Error\n", __func__); - goto out; - } - PRINTF("%s: new pic created (%i bytes)\n", __func__, num_read); - if (num_read < 500) - goto out; - - if (piximage) { - gkrellm_destroy_piximage(piximage); - g_free(pixbuf); - } - PRINTF("%s: creating new piximage\n", __func__); - piximage = gkrellm_piximage_new_from_file(filename); - if (!piximage) { - PRINTF("%s: can not load image\n", __func__); - goto out; - } - pixbuf = gkrellm_scale_piximage_to_pixbuf(piximage, width, width); -out: - g_free(filename); - if (pipe) - pclose(pipe); - if (out) - close(out); -} - -static void create_tab(GtkWidget *tab_vbox) -{ - GtkTextBuffer *textbuf; - GtkWidget *text; - GtkWidget *scrolled, *vbox = tab_vbox; - - PRINTF("%s: \n", __func__); - - scrolled = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - textbuf = gtk_text_buffer_new(NULL); - gtk_text_buffer_set_text(textbuf, info_text, -1); - text = gtk_text_view_new_with_buffer(textbuf); - gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE); - gtk_container_add(GTK_CONTAINER(scrolled), text); - gtk_box_pack_start(GTK_BOX(vbox), scrolled, TRUE, TRUE, 0); -} - -static gboolean song_change(GIOChannel *channel, GIOCondition condition, - gpointer panel) -{ - char *str_return; - gsize length; - - PRINTF("%s: input condition %i " - "(song_change channel fd = %i)\n", __func__, condition, - g_io_channel_unix_get_fd(song_change_channel)); - if (!song_change_fd) { - PRINTF("%s: no song_change_fd\n", __func__); - goto err_out; - } - if (!(condition & (G_IO_IN | G_IO_PRI))) { - PRINTF("%s: song change pipe died\n", __func__); - song_change_fd = NULL; - wait(NULL); - return TRUE; - goto err_out; - } - if (!channel->is_readable) { - PRINTF("%s: fd not readable\n", __func__); - goto err_out; - } - PRINTF("%s: reading data\n", __func__); - if (g_io_channel_read_line(channel, &str_return, - &length, NULL, NULL) == G_IO_STATUS_NORMAL) { - PRINTF("%s: next song: %s", __func__, str_return); - g_free(str_return); - if (channel != song_change_channel) - goto err_out; - load_img(); - return TRUE; - } -err_out: - g_io_channel_unref(channel); - g_io_channel_shutdown(channel, TRUE, NULL); - return FALSE; -} - -static void create_song_change(void) -{ - if (song_change_fd) - return; - gettimeofday(&sc_open_time, NULL); - PRINTF("%s: para_client sc\n", __func__); - song_change_fd = popen("para_client sc", "r"); - if (!song_change_fd) { - PRINTF("%s: para_client sc failed\n", __func__); - return; - } - song_change_channel = g_io_channel_unix_new(fileno(song_change_fd)); - g_io_channel_set_close_on_unref(song_change_channel, TRUE); - g_io_add_watch(song_change_channel, - G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL, - &song_change, panel); -} - -static void update_para_ctrl(void) -{ - GdkDrawable *drawable = panel->drawing_area->window; - gint width = gkrellm_chart_width(); - - if (!drawable) - PRINTF("%s: No drawable\n", __func__); - else - gkrellm_paste_pixbuf(pixbuf, drawable, 0, 0, width, width); - if (!song_change_fd) { - struct timeval now; - PRINTF("%s: no song_change_fd\n", __func__); - - gettimeofday(&now, NULL); - if (now.tv_sec > sc_open_time.tv_sec + 5) - create_song_change(); - } -} - -static void destroy_panel(void) -{ - PRINTF("%s: \n", __func__); - if (!panel) - return; - PRINTF("%s: destroying panel\n", __func__); - gkrellm_panel_destroy(panel); - panel = NULL; -} - -#if 0 -static void destroy_song_change(void) -{ - PRINTF("%s: \n", __func__); - if (!song_change_fd) - return; -} -#endif -static void destroy_all(void) -{ -// destroy_song_change(); - destroy_panel(); -} - -static void create_para_ctrl(GtkWidget *vbox, gint first_create) -{ - gint style_id = gkrellm_lookup_meter_style_id(UPTIME_STYLE_NAME); - GkrellmStyle *style = gkrellm_meter_style(style_id); - gint width = gkrellm_chart_width(); - - destroy_all(); - create_song_change(); - panel = gkrellm_panel_new0(); - gkrellm_panel_configure(panel, NULL, style); - gkrellm_panel_configure_set_height(panel, width); - PRINTF("%s: creating panel\n", __func__); - gkrellm_panel_create(vbox, &monitor, panel); - make_button(&prev_button, 1); -} - -static void apply_config(void) -{ - PRINTF("%s: \n", __func__); -} - -static void load_config(gchar * arg) -{ - PRINTF("%s: \n", __func__); - -} - -static void save_config(FILE * f) -{ - PRINTF("%s: \n", __func__); -} - -GkrellmMonitor *gkrellm_init_plugin(void) -{ - return &monitor; -} diff --git a/pics/screenshots/para_krell-2005-02.png b/pics/screenshots/para_krell-2005-02.png deleted file mode 100644 index 1aa25d81..00000000 Binary files a/pics/screenshots/para_krell-2005-02.png and /dev/null differ diff --git a/pics/screenshots/para_slider-2004-12.png b/pics/screenshots/para_slider-2004-12.png deleted file mode 100644 index f997fbad..00000000 Binary files a/pics/screenshots/para_slider-2004-12.png and /dev/null differ diff --git a/pics/screenshots/sdl_gui.jpg b/pics/screenshots/sdl_gui.jpg deleted file mode 100644 index f6e3d484..00000000 Binary files a/pics/screenshots/sdl_gui.jpg and /dev/null differ diff --git a/sdl_gui.c b/sdl_gui.c deleted file mode 100644 index 9668fad1..00000000 --- a/sdl_gui.c +++ /dev/null @@ -1,820 +0,0 @@ -/* - * Copyright (C) 2003-2007 Andre Noll - * - * Licensed under the GPL v2. For licencing details see COPYING. - */ - -/** \file sdl_gui.c SDL-based interface for paraslash */ - -#include -#include - -#include "para.h" -#include "gui_common.h" -#include "fd.h" - - -#include -#include "SFont.h" - -#include -#include -#include -#include -#include /* timeval, needed for select */ - -#include "sdl_gui.cmdline.h" - -#define FRAME_RED 100 -#define FRAME_GREEN 200 -#define FRAME_BLUE 200 - -SDL_Surface *screen; -static int width = 0; -static int height = 0; - -extern const char *status_item_list[NUM_STAT_ITEMS]; -struct sdl_gui_args_info args_info; - -#define FRAME_WIDTH 10 -#define FONT_HEIGHT 36 - -#define INPUT_WIDTH width - 2 * FRAME_WIDTH -#define INPUT_X FRAME_WIDTH -#define INPUT_HEIGHT (args_info.interactive_flag? FONT_HEIGHT : 0) -#define INPUT_Y height - FRAME_WIDTH - INPUT_HEIGHT - -#define OUTPUT_WIDTH width - 2 * FRAME_WIDTH -#define OUTPUT_X FRAME_WIDTH -#define OUTPUT_Y FRAME_WIDTH -#define OUTPUT_HEIGHT (height - INPUT_HEIGHT - 2 * FRAME_WIDTH) - -#define NUM_LINES (height - 2 * FRAME_WIDTH - INPUT_HEIGHT) / FONT_HEIGHT - -#define M_YELLOW 0 -#define N_YELLOW 1 - -#define LEFT 1 -#define RIGHT 2 -#define CENTER 3 - - -struct stat_item{ - const char *name; - const char *prefix; - const char *postfix; - char *content; - unsigned x; - unsigned y; - unsigned w; - unsigned h; - Uint8 r; - Uint8 g; - Uint8 b; - int font; - int align; -}; - -struct font { - char name[MAXLINE]; - SFont_FontInfo fontinfo; -}; - -struct font fonts[] = { - { - .name = "24P_Arial_Metallic_Yellow.png", - .fontinfo = {NULL, {0}, 0} - }, - { - .name = "24P_Arial_NeonYellow.png", - .fontinfo = {NULL, {0}, 0} - }, - { - .name = "24P_Copperplate_Blue.png", - .fontinfo = {NULL, {0}, 0} - }, - { - .name = "", - .fontinfo = {NULL, {0}, 0} - } -}; - - -#define PIC_WIDTH width * 3 / 10 -#define PIC_HEIGHT height / 3 - -#define INPUT_FONT 0 -#define OUTPUT_FONT 1 -#define MSG_FONT 2 - - -static struct stat_item stat_items[NUM_STAT_ITEMS]; - -void para_log(__a_unused int ll, __a_unused const char* fmt,...) /* no logging */ -{ -} - -static void init_stat_items(void) -{ - int i; - struct stat_item *s = stat_items; - - for (i = 0; i < NUM_STAT_ITEMS; i++) { - s[i].w = 0; - s[i].content = NULL; - } - - - s[SI_STATUS_BAR].prefix = ""; - s[SI_STATUS_BAR].postfix = ""; - s[SI_STATUS_BAR].x = 0; - s[SI_STATUS_BAR].y = 10; - s[SI_STATUS_BAR].w = 100; - s[SI_STATUS_BAR].h = FONT_HEIGHT; - s[SI_STATUS_BAR].r = 0; - s[SI_STATUS_BAR].g = 0; - s[SI_STATUS_BAR].b = 0; - s[SI_STATUS_BAR].font = M_YELLOW; - s[SI_STATUS_BAR].align = CENTER; - - s[SI_PLAY_TIME].prefix = ""; - s[SI_PLAY_TIME].postfix = ""; - s[SI_PLAY_TIME].x = 35; - s[SI_PLAY_TIME].y = 20; - s[SI_PLAY_TIME].w = 65; - s[SI_PLAY_TIME].h = FONT_HEIGHT; - s[SI_PLAY_TIME].r = 0; - s[SI_PLAY_TIME].g = 0; - s[SI_PLAY_TIME].b = 0; - s[SI_PLAY_TIME].font = M_YELLOW; - s[SI_PLAY_TIME].align = CENTER; - - s[SI_STATUS].prefix = ""; - s[SI_STATUS].postfix = ""; - s[SI_STATUS].x = 35; - s[SI_STATUS].y = 28; - s[SI_STATUS].w = 12; - s[SI_STATUS].h = FONT_HEIGHT; - s[SI_STATUS].r = 0; - s[SI_STATUS].g = 0; - s[SI_STATUS].b = 0; - s[SI_STATUS].font = N_YELLOW; - s[SI_STATUS].align = LEFT; - - s[SI_STATUS_FLAGS].prefix = " ("; - s[SI_STATUS_FLAGS].postfix = ")"; - s[SI_STATUS_FLAGS].x = 47; - s[SI_STATUS_FLAGS].y = 28; - s[SI_STATUS_FLAGS].w = 15; - s[SI_STATUS_FLAGS].h = FONT_HEIGHT; - s[SI_STATUS_FLAGS].r = 0; - s[SI_STATUS_FLAGS].g = 0; - s[SI_STATUS_FLAGS].b = 0; - s[SI_STATUS_FLAGS].font = N_YELLOW; - s[SI_STATUS_FLAGS].align = CENTER; - - s[SI_NUM_PLAYED].prefix = "#"; - s[SI_NUM_PLAYED].postfix = ""; - s[SI_NUM_PLAYED].x = 62; - s[SI_NUM_PLAYED].y = 28; - s[SI_NUM_PLAYED].w = 13; - s[SI_NUM_PLAYED].h = FONT_HEIGHT; - s[SI_NUM_PLAYED].r = 0; - s[SI_NUM_PLAYED].g = 0; - s[SI_NUM_PLAYED].b = 0; - s[SI_NUM_PLAYED].font = N_YELLOW; - s[SI_NUM_PLAYED].align = CENTER; - - s[SI_UPTIME].prefix = "Up: "; - s[SI_UPTIME].postfix = ""; - s[SI_UPTIME].x = 75; - s[SI_UPTIME].y = 28; - s[SI_UPTIME].w = 25; - s[SI_UPTIME].h = FONT_HEIGHT; - s[SI_UPTIME].r = 0; - s[SI_UPTIME].g = 0; - s[SI_UPTIME].b = 0; - s[SI_UPTIME].font = N_YELLOW; - s[SI_UPTIME].align = RIGHT; - - s[SI_SELECTOR].prefix = "selector: "; - s[SI_SELECTOR].postfix = ""; - s[SI_SELECTOR].x = 35; - s[SI_SELECTOR].y = 48; - s[SI_SELECTOR].w = 35; - s[SI_SELECTOR].h = FONT_HEIGHT; - s[SI_SELECTOR].r = 0; - s[SI_SELECTOR].g = 0; - s[SI_SELECTOR].b = 0; - s[SI_SELECTOR].font = N_YELLOW; - s[SI_SELECTOR].align = LEFT; - - s[SI_FORMAT].prefix = "Format: "; - s[SI_FORMAT].postfix = ""; - s[SI_FORMAT].x = 70; - s[SI_FORMAT].y = 48; - s[SI_FORMAT].w = 30; - s[SI_FORMAT].h = FONT_HEIGHT; - s[SI_FORMAT].r = 0; - s[SI_FORMAT].g = 0; - s[SI_FORMAT].b = 0; - s[SI_FORMAT].font = N_YELLOW; - s[SI_FORMAT].align = RIGHT; - - s[SI_MTIME].prefix = "MTime: "; - s[SI_MTIME].postfix = ""; - s[SI_MTIME].x = 35; - s[SI_MTIME].y = 35; - s[SI_MTIME].w = 65; - s[SI_MTIME].h = FONT_HEIGHT; - s[SI_MTIME].r = 0; - s[SI_MTIME].g = 0; - s[SI_MTIME].b = 0; - s[SI_MTIME].font = N_YELLOW; - s[SI_MTIME].align = LEFT; - - s[SI_FILE_SIZE].prefix = "Size: "; - s[SI_FILE_SIZE].postfix = "kb"; - s[SI_FILE_SIZE].x = 35; - s[SI_FILE_SIZE].y = 42; - s[SI_FILE_SIZE].w = 20; - s[SI_FILE_SIZE].h = FONT_HEIGHT; - s[SI_FILE_SIZE].r = 0; - s[SI_FILE_SIZE].g = 0; - s[SI_FILE_SIZE].b = 0; - s[SI_FILE_SIZE].font = N_YELLOW; - s[SI_FILE_SIZE].align = LEFT; - - s[SI_AUDIO_INFO1].prefix = ""; - s[SI_AUDIO_INFO1].postfix = ""; - s[SI_AUDIO_INFO1].x = 0; - s[SI_AUDIO_INFO1].y = 60; - s[SI_AUDIO_INFO1].w = 100; - s[SI_AUDIO_INFO1].h = FONT_HEIGHT; - s[SI_AUDIO_INFO1].r = 0; - s[SI_AUDIO_INFO1].g = 0; - s[SI_AUDIO_INFO1].b = 0; - s[SI_AUDIO_INFO1].font = N_YELLOW; - s[SI_AUDIO_INFO1].align = CENTER; - - s[SI_AUDIO_INFO2].prefix = ""; - s[SI_AUDIO_INFO2].postfix = ""; - s[SI_AUDIO_INFO2].x = 0; - s[SI_AUDIO_INFO2].y = 65; - s[SI_AUDIO_INFO2].w = 100; - s[SI_AUDIO_INFO2].h = FONT_HEIGHT; - s[SI_AUDIO_INFO2].r = 0; - s[SI_AUDIO_INFO2].g = 0; - s[SI_AUDIO_INFO2].b = 0; - s[SI_AUDIO_INFO2].font = N_YELLOW; - s[SI_AUDIO_INFO2].align = CENTER; - - s[SI_AUDIO_INFO3].prefix = ""; - s[SI_AUDIO_INFO3].postfix = ""; - s[SI_AUDIO_INFO3].x = 0; - s[SI_AUDIO_INFO3].y = 70; - s[SI_AUDIO_INFO3].w = 100; - s[SI_AUDIO_INFO3].h = FONT_HEIGHT; - s[SI_AUDIO_INFO3].r = 0; - s[SI_AUDIO_INFO3].g = 0; - s[SI_AUDIO_INFO3].b = 0; - s[SI_AUDIO_INFO3].font = N_YELLOW; - s[SI_AUDIO_INFO3].align = CENTER; - - s[SI_AFS_MODE].name = "afs_mode:"; - s[SI_AFS_MODE].prefix = ""; - s[SI_AFS_MODE].postfix = ""; - s[SI_AFS_MODE].x = 0; - s[SI_AFS_MODE].y = 83; - s[SI_AFS_MODE].w = 100; - s[SI_AFS_MODE].h = FONT_HEIGHT; - s[SI_AFS_MODE].r = 0; - s[SI_AFS_MODE].g = 0; - s[SI_AFS_MODE].b = 0; - s[SI_AFS_MODE].font = N_YELLOW; - s[SI_AFS_MODE].align = CENTER; - - s[SI_DBINFO2].prefix = ""; - s[SI_DBINFO2].postfix = ""; - s[SI_DBINFO2].x = 0; - s[SI_DBINFO2].y = 88; - s[SI_DBINFO2].w = 100; - s[SI_DBINFO2].h = FONT_HEIGHT; - s[SI_DBINFO2].r = 0; - s[SI_DBINFO2].g = 0; - s[SI_DBINFO2].b = 0; - s[SI_DBINFO2].font = N_YELLOW; - s[SI_DBINFO2].align = CENTER; - - s[SI_DBINFO3].name = "dbinfo3:"; - s[SI_DBINFO3].prefix = ""; - s[SI_DBINFO3].postfix = ""; - s[SI_DBINFO3].x = 0; - s[SI_DBINFO3].y = 93; - s[SI_DBINFO3].w = 100; - s[SI_DBINFO3].h = FONT_HEIGHT; - s[SI_DBINFO3].r = 0; - s[SI_DBINFO3].g = 0; - s[SI_DBINFO3].b = 0; - s[SI_DBINFO3].font = N_YELLOW; - s[SI_DBINFO3].align = CENTER; -} - -/* - * init SDL libary and set window title - */ -static void init_SDL(void) -{ - if (SDL_Init(SDL_INIT_VIDEO) == -1) { - fprintf(stderr, - "Couldn't initialize SDL: %s\n", SDL_GetError()); - exit(1); - } - /* Clean up on exit */ - atexit(SDL_Quit); - /* Initialize the display */ - if (args_info.fullscreen_flag) - screen = SDL_SetVideoMode(width, height, 0, SDL_FULLSCREEN); - else - screen = SDL_SetVideoMode(width, height, 0, 0); - if (!screen) { - fprintf(stderr, "Couldn't set video mode: %s\n", - SDL_GetError()); - exit(1); - } - SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); - SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_IGNORE); - SDL_EventState(SDL_MOUSEBUTTONUP, SDL_IGNORE); - /* Set the window manager title bar */ - SDL_WM_SetCaption("The Gui of death that makes you blind (paraslash " - PACKAGE_VERSION ")", "SFont"); -} - -/* - * draw rectangular frame of width FRAME_WIDTH - */ -static void draw_frame(Uint8 r, Uint8 g, Uint8 b) { - SDL_Rect rect; - - rect.x = 0; - rect.y = 0; - rect.w = width; - rect.h = FRAME_WIDTH; - SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, r, g, b)); - SDL_UpdateRect(screen, rect.x, rect.y, rect.w, rect.h); - - rect.x = 0; - rect.y = height - FRAME_WIDTH; - rect.w = width; - rect.h = FRAME_WIDTH; - SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, r, g, b)); - SDL_UpdateRect(screen, rect.x, rect.y, rect.w, rect.h); - - rect.x = 0; - rect.y = FRAME_WIDTH; - rect.w = FRAME_WIDTH; - rect.h = height - 2 * FRAME_WIDTH; - SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, r, g, b)); - SDL_UpdateRect(screen, rect.x, rect.y, rect.w, rect.h); - - rect.x = width - FRAME_WIDTH; - rect.y = FRAME_WIDTH; - rect.w = FRAME_WIDTH; - rect.h = height - 2 * FRAME_WIDTH; - SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, r, g, b)); - SDL_UpdateRect(screen, rect.x, rect.y, rect.w, rect.h); -} - -/* - * fill input rect with color - */ -static void fill_input_rect(void) -{ - SDL_Rect rect; - - rect.x = INPUT_X; - rect.y = INPUT_Y; - rect.w = INPUT_WIDTH; - rect.h = INPUT_HEIGHT; - SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, 10, 150, 10)); -} - -/* - * fill output rect with color - */ -static void fill_output_rect(void) -{ - SDL_Rect rect; - - rect.x = OUTPUT_X; - rect.y = OUTPUT_Y; - rect.w = OUTPUT_WIDTH; - rect.h = OUTPUT_HEIGHT; - SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, 0, 0, 0)); -} - -/* - * convert tab to space - */ -static void tab2space(char *text) -{ - char *p = text; - while (*p) { - if (*p == '\t') - *p = ' '; - p++; - } -} - -static void print_msg(const char *msg) -{ - SFont_FontInfo *font = &(fonts[MSG_FONT].fontinfo); - char *buf = strdup(msg); - int len = strlen(buf); - - if (!buf) - return; - while (TextWidth2(font, buf) > INPUT_WIDTH && len > 0) { - *(buf + len) = '\0'; - len--; - } - fill_input_rect(); - PutString2(screen, font, INPUT_X, INPUT_Y, buf); - free(buf); -} - -static void update_all(void) -{ - SDL_UpdateRect(screen, 0, 0, 0, 0); -} - -static void update_input(void) -{ - SDL_UpdateRect(screen, INPUT_X, INPUT_Y, INPUT_WIDTH, INPUT_HEIGHT); - -} - -/* - * wait for key, ignore all other events, return 0 if there is no key event - * pending. Otherwise return keysym of key - */ -SDLKey get_key(void) -{ - SDL_Event event; - - while (SDL_PollEvent(&event) > 0) { - if(event.type != SDL_KEYDOWN) - continue; -// printf("Key pressed, scancode: 0x%x\n", -// event.key.keysym.scancode); - return event.key.keysym.sym; - } - return 0; -} - -/* - * print message, wait for key (blocking), return 1 for 'q', 0 else - */ -static SDLKey hit_key(const char *msg) -{ - SDLKey sym; - - print_msg(msg); - update_input(); - while (!(sym = get_key())) - ; - fill_input_rect(); - update_input(); - if (sym == SDLK_q) - return 1; - else - return 0; -} - -/* - * read paraslash command from input, execute it and print results - */ -static int command_handler(void) -{ - FILE *f; - unsigned count = 0; - char text[MAXLINE]=""; - char buf[MAXLINE]=""; - SFont_FontInfo *font = &fonts[OUTPUT_FONT].fontinfo; - -// printf("string input\n"); - SFont_Input2(screen, &fonts[INPUT_FONT].fontinfo, - INPUT_X, INPUT_Y - 5, INPUT_WIDTH, text); - if (!strlen(text)) - return 1; - if (!strcmp(text, "exit") || !strcmp(text, "quit")) - return 0; - if (text[0] == '!') { - if (text[1] == '\0') - return 1; - f = popen(text + 1, "r"); - } else { - sprintf(buf, BINDIR "/para_client %s 2>&1", text); - f = popen(buf, "r"); - } - if (!f) - return 0; - fill_output_rect(); - while(fgets(text, MAXLINE - 1, f)) { - int len; - - tab2space(text); - len = strlen(text); - // printf("string: %s\n", dest); - while (TextWidth2(font, text) > width - 2 * FRAME_WIDTH && - len > 0) { - text[len] = '\0'; - len--; - } - PutString2(screen, font, OUTPUT_X, - OUTPUT_Y + count * FONT_HEIGHT, text); - count++; - if (count >= NUM_LINES) { - update_all(); - if (hit_key("Hit any key to continue, q to return")) - goto out; - count = 0; - fill_output_rect(); - } - } - update_all(); - hit_key("Hit any key to return"); -out: fill_output_rect(); - pclose(f); - return 1; -} - - -/* - * Add prefix and postfix to string, delete characters from the end - * if its length exceeds the max length defined in stat_items[item] - */ -char *transform_string(int item) -{ - struct stat_item s = stat_items[item]; - size_t len; - char *ret; - unsigned pixels = s.w * (width - 2 * FRAME_WIDTH) / 100; - SFont_FontInfo *font = &(fonts[s.font].fontinfo); - - ret = make_message("%s%s%s", s.prefix, s.content, s.postfix); - len = strlen(ret); - while (TextWidth2(font, ret) > pixels && len > 0) { - *(ret + len) = '\0'; - len--; - } - return ret; -} - -SDL_Surface *load_jpg(void) -{ - SDL_RWops *rwop; - int fds[3] = {0, 1, 0}; - pid_t pid; - FILE *f; - - if (para_exec_cmdline_pid(&pid, args_info.pic_cmd_arg, fds) < 0) - return NULL; - f = fdopen(fds[1], "r"); - if (!f) - return NULL; - if (!(rwop = SDL_RWFromFP(f, 0))) - return NULL; - return IMG_LoadJPG_RW(rwop); -} - -void update_pic(void) -{ - SDL_Surface *img; - SDL_Rect src_pic_rect = { - .x = 0, - .y = 0, - .w = PIC_WIDTH, - .h = PIC_HEIGHT, - }; - SDL_Rect dest_pic_rect = { - .x = FRAME_WIDTH, - .y = OUTPUT_HEIGHT / 5, - .w = PIC_WIDTH, - .h = PIC_HEIGHT, - }; - - if (!screen) - return; - - if (!(img = load_jpg())) - return; - SDL_FillRect(screen, &dest_pic_rect, SDL_MapRGB(screen->format, - 0, 0, 0)); - SDL_BlitSurface(img, &src_pic_rect, screen, &dest_pic_rect); - SDL_Flip(screen); - SDL_FreeSurface(img); -} - -/* - * update status item number i. - */ -static void do_update(int i) -{ - static int last_played = -1; - SDL_Rect rect; - char *buf; - SFont_FontInfo *font = &(fonts[stat_items[i].font].fontinfo); - if (!stat_items[i].w) - return; - - rect.x = stat_items[i].x * (width - FRAME_WIDTH * 2) / 100 - + FRAME_WIDTH; - rect.y = stat_items[i].y * (height - 2 * FRAME_WIDTH - INPUT_HEIGHT) - / 100; - rect.w = stat_items[i].w * (width - 2 * FRAME_WIDTH) / 100; - rect.h = stat_items[i].h; - buf = transform_string(i); - SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, - stat_items[i].r, stat_items[i].g, stat_items[i].b)); - switch(stat_items[i].align) { - case CENTER: - PutString2(screen, font, - rect.x + (rect.w - TextWidth2(font, buf)) / 2, - rect.y, buf); - break; - case LEFT: - PutString2(screen, font, rect.x, rect.y, buf); - break; - case RIGHT: - PutString2(screen, font, rect.x + (rect.w - - TextWidth2(font, buf)), rect.y, buf); - break; - } - free(buf); - SDL_UpdateRect(screen, rect.x, rect.y, rect.w, rect.h); - if (i == SI_NUM_PLAYED && atoi(stat_items[i].content) != last_played) { - update_pic(); - last_played = atoi(stat_items[i].content); - }; -} - -/* - * Check if buf is a known status line. If so call do_update and return 1. - * Return 0 otherwise. - */ -int update_status(char *buf, __a_unused void *data) -{ - int i; - - i = stat_line_valid(buf); - if (i < 0) - return 1; - //free(stat_items[i].content); - stat_items[i].content = para_strdup(buf + - strlen(status_item_list[i]) + 1); - do_update(i); - return 1; -} - -/* - * Read stat line from pipe if pipe is ready, call update_status to - * display information. - */ -static int draw_status(int fd) -{ - fd_set rfds; - int ret; - struct timeval tv; - - tv.tv_sec = 0; - tv.tv_usec = 3000000; - FD_ZERO(&rfds); - FD_SET(fd, &rfds); - ret = para_select(fd + 1, &rfds, NULL, &tv); - if (ret <= 0) - return 0; - if (read_audiod_pipe(fd, update_status) > 0) - return 1; - free(stat_items[SI_STATUS_BAR].content); - stat_items[SI_STATUS_BAR].content = - para_strdup("audiod not running!?\n"); - update_all(); - sleep(1); - return -1; -} - -static void clean_exit(int ret) -{ - SDL_Quit(); - exit(ret); -} - -static void print_help(void) -{ - print_msg("Hit q to quit, any other key to enter command mode"); -} - -static int configfile_exists(void) -{ - if (!args_info.config_file_given) { - char *home = para_homedir(); - args_info.config_file_arg = make_message( - "%s/.paraslash/sdl_gui.conf", home); - free(home); - } - return file_exists(args_info.config_file_arg); -} - -/* - * MAIN - */ -int main(int argc, char *argv[]) -{ - int i, ret, fd = -1; - SDLKey sym; - - sdl_gui_cmdline_parser(argc, argv, &args_info); - HANDLE_VERSION_FLAG("sdl_gui", args_info); - ret = configfile_exists(); -// printf("w=%i,h=%i,ret=%i, cf=%s\n", width, height, ret, args_info.config_file_arg); - - if (!ret && args_info.config_file_given) { - fprintf(stderr, "Can't read config file %s\n", - args_info.config_file_arg); - exit(EXIT_FAILURE); - } - if (ret) { - struct sdl_gui_cmdline_parser_params params = { - .override = 0, - .initialize = 0, - .check_required = 0, - .check_ambiguity = 0 - }; - sdl_gui_cmdline_parser_config_file(args_info.config_file_arg, - &args_info, ¶ms); - } - signal(SIGCHLD, SIG_IGN); - width = args_info.width_arg; - height = args_info.height_arg; -// printf("w=%i,h=%i,ret=%i, cf=%s\n", width, height, ret, args_info.config_file_arg); - init_stat_items(); - init_SDL(); - for (i = 0; fonts[i].name[0]; i++) { - char buf[MAXLINE]; - sprintf(buf, "%s/%s", FONTDIR, fonts[i].name); - /* Load the font - You don't have to use the IMGlib for this */ - fonts[i].fontinfo.Surface = IMG_Load(buf); - /* Prepare the font for use */ - InitFont2(&fonts[i].fontinfo); - } - draw_frame(FRAME_RED, FRAME_GREEN, FRAME_BLUE); - if (args_info.interactive_flag) { - print_help(); - update_input(); - } - for (;;) { - if (fd < 0) { - fd = para_open_audiod_pipe(args_info.stat_cmd_arg); - if (fd < 0) - clean_exit(EXIT_FAILURE); - } - ret = draw_status(fd); - if (ret < 0) { - close(fd); - fd = -1; - } - if (SDL_QuitRequested()) - clean_exit(0); - while ((sym = get_key())) { - if (!args_info.interactive_flag) - clean_exit(0); - if (sym == SDLK_q) - clean_exit(0); - if ( sym == SDLK_LSHIFT - || sym == SDLK_RSHIFT - || sym == SDLK_LMETA - || sym == SDLK_RMETA - || sym == SDLK_RCTRL - || sym == SDLK_LCTRL - || sym == SDLK_MODE - || sym == SDLK_CAPSLOCK - || sym == SDLK_LALT - || sym == SDLK_RALT - || sym == SDLK_RSUPER - || sym == SDLK_LSUPER - || sym == SDLK_COMPOSE - ) - continue; - fill_input_rect(); - update_input(); - if (!command_handler()) - clean_exit(0); - fill_output_rect(); - print_help(); - update_pic(); - SDL_UpdateRect(screen, 0, 0, 0, 0); - break; - } - } -} diff --git a/sdl_gui.ggo b/sdl_gui.ggo deleted file mode 100644 index 8ea49287..00000000 --- a/sdl_gui.ggo +++ /dev/null @@ -1,8 +0,0 @@ -option "fullscreen" f "Use fullscreeen mode" flag off -option "interactive" i "Activate interactive mode" flag off -option "width" x "Specify screen width" int typestr="pixels" default="1024" optional -option "height" y "Specify screen height" int typestr="pixels" default="768" optional -option "config_file" c "(default='~/.paraslash/sdl_gui.conf')" string typestr="filename" optional -option "window-id" w "(currently ignored)" string typestr="filename" optional -option "stat_cmd" s "command to read server and audiod status data from" string typestr="command" default="para_audioc stat" optional -option "pic_cmd" p "command to read pic from" string typestr="command" default="para_client pic" optional diff --git a/slider.c b/slider.c deleted file mode 100644 index 242f1c35..00000000 --- a/slider.c +++ /dev/null @@ -1,330 +0,0 @@ -/* - * Copyright (C) 2004-2006 Andre Noll - * - * Licensed under the GPL v2. For licencing details see COPYING. - */ - -/** \file slider.c libzmw-based stream creator for paraslash */ - -#include "para.h" -#include "zmw/zmw.h" -#include "math.h" -#include "string.h" - -#define WIDTH 300 -#define SLIDER_RATIO 6 -#define VAL_2_SL_VAL(v) (v) * (SLIDER_RATIO - 1.0) / SLIDER_RATIO -#define SL_VAL_2_VAL(v) (v) * SLIDER_RATIO / (SLIDER_RATIO - 1.0) -#define VAL_2_SCORE(v) (v) > 0.5? 1 / (1.03 - (v)) / (1.03 - (v)) :\ - - 1 / ((v) + 0.03) / ((v) + 0.03) - -#define RGB(R,G,B) (((R)<<12) + ((G)<<6) + (B)) - -#define EPSILON 0.001 -#define LASTPLAYED_FORMULA(v) \ - 1 / (pow((v), 10) + EPSILON * EPSILON) - 1 / (1 + EPSILON) + EPSILON - -#define NUMPLAYED_FORMULA(v)\ - 10 * (v) + (v) / (1 - (v) * (1 - EPSILON)) - -static int argc; -static char **argv; -char *streamname = NULL; -static Zmw_Float_0_1 *slider_vals, lastplayed_val, numplayed_val; - -void para_log(int ll, const char* fmt,...) /* no logging */ -{ -} - -static void rst(void) -{ - int i; - for (i = 1; argv[i]; i++) - slider_vals[i] = VAL_2_SL_VAL(.5); - if (streamname) - free(streamname); - streamname = para_strdup("slider"); - //printf("rst: \n"); -} - -static char *get_value_filename(void) -{ - char *ret, *home =para_homedir(); - ret = make_message("%s/.paraslash/slide.values", home); - free(home); - return ret; -} - -static void load(void) -{ - char *tmp; - char att[999]; - FILE *f; - int i; - Zmw_Float_0_1 val; - - tmp = get_value_filename(); - f = fopen(tmp, "r"); - free(tmp); - if (!f) - return; - while (fscanf(f, "%900s %g", att, &val) == 2) { - if (!strcmp(att, "lastplayed")) { - lastplayed_val = val; - continue; - } - if (!strcmp(att, "numplayed")) { - numplayed_val = val; - continue; - } - for (i = 1; argv[i]; i++) - if (!strcmp(argv[i], att)) { - slider_vals[i] = val; - break; - } - - } - fclose(f); -} - -static void save(void) -{ - char *filename; - FILE *f; - int i; - - filename = get_value_filename(); - f = fopen(filename, "w"); - free(filename); - if (!f) - return; - fprintf(f, "lastplayed %g\n", lastplayed_val); - fprintf(f, "numplayed %g\n", numplayed_val); - for (i = 1; argv[i]; i++) - fprintf(f, "%s %g\n", argv[i], slider_vals[i]); - fclose(f); -} - - -static void print_score(FILE *fd) -{ - int i; - - for (i = 1; argv[i]; i++) { - if (SL_VAL_2_VAL(slider_vals[i]) > .99) - fprintf(fd, "deny: IS_N_SET(%s)\n", argv[i]); - if (slider_vals[i] < .01) - fprintf(fd, "deny: IS_SET(%s)\n", argv[i]); - } - fprintf(fd, "score: 0 "); - for (i = 1; argv[i]; i++) { - if (slider_vals[i] < .01) - continue; - fprintf(fd, "+ %i * IS_SET(%s) ", - (int) (VAL_2_SCORE(SL_VAL_2_VAL(slider_vals[i]))), - argv[i] - ); - } - fprintf(fd, " + round((LASTPLAYED()/1440 - 1000 / (LASTPLAYED()/1440 + 1)) / %f" - " - %f * NUMPLAYED(), 2)\n", - LASTPLAYED_FORMULA(SL_VAL_2_VAL(lastplayed_val)), - NUMPLAYED_FORMULA(SL_VAL_2_VAL(numplayed_val))); -} - -static void stradd(void) -{ - FILE *pipe; - char *cmd = make_message("para_client stradd %s", streamname); - - pipe = popen(cmd, "w"); - free(cmd); - if (!pipe) - return; - print_score(pipe); - pclose(pipe); -} - -static void b_save(void) -{ - stradd(); - save(); -} - -static void go(void) -{ - stradd(); - system("para_client cs slider"); - system("para_client stop"); - system("para_client play"); -} - -static void ok() -{ - stradd(); - system("para_client cs slider"); - system("para_client play"); - save(); - zmw_main_quit(EXIT_SUCCESS); -} - -static void make_buttons(void) -{ - /* Add a frame around the box */ - ZMW(zmw_decorator(Zmw_Decorator_Border_Embossed)) { - /* the buttons */ - ZMW(zmw_hbox()) { - zmw_button("save"); - if (zmw_activated()) - b_save(); - zmw_button("ok"); - if (zmw_activated()) - ok(); - zmw_button("go!"); - if (zmw_activated()) - go(); - zmw_button("rst"); - if (zmw_activated()) - rst(); -// zmw_x(WIDTH); - zmw_button("abort"); - if (zmw_activated()) - zmw_main_quit(EXIT_FAILURE); - } - } -} -static void make_stream_input_field(void) -{ - static char *text1 = NULL; - static int cursor_pos = 1; // Must be static - static int text1_length ; - - ZMW(zmw_vbox()) { - if ( text1 == NULL ) { - // The initial value must be malloced - text1 = strdup("slider") ; - text1_length = strlen(text1) ; - } - ZMW(zmw_fixed()) { - zmw_y(6); - zmw_x(0); - zmw_label("stream: "); - zmw_color(Zmw_Color_Foreground, RGB(63, 63, 63)); - zmw_y(0); - zmw_x(100); - zmw_width(WIDTH); - zmw_entry_with_cursor(&streamname, &cursor_pos); - if (zmw_changed()) - text1_length = strlen(text1); - } - } -} - -/* the sliders, one for each member in argv */ -static void make_sliders(void) -{ - int i; - char *txt; - - zmw_height(ZMW_VALUE_UNDEFINED); -// zmw_horizontal_expand(Zmw_True); - ZMW(zmw_hbox()) { - ZMW(zmw_vbox()) { - zmw_color(Zmw_Color_Foreground, RGB(0, 63, 63)); /* font */ - txt = make_message("lp: (%i%%)", - (int)(.5 + 100 * SL_VAL_2_VAL(lastplayed_val))); - zmw_label(txt); - free(txt); - txt = make_message("np: (%i%%)", - (int)(.5 + 100 * SL_VAL_2_VAL(numplayed_val))); - zmw_label(txt); - free(txt); - zmw_color(Zmw_Color_Foreground, RGB(63, 63, 0)); /* font */ - for (i = 1; argv[i]; i++) { - txt = make_message("%s: (%i%%)", argv[i], - (int)(.5 + 100 * SL_VAL_2_VAL(slider_vals[i]))); - zmw_label(txt); - free(txt); - } - } - ZMW(zmw_vbox()) { - zmw_width(200) ; - zmw_hscrollbar(&lastplayed_val, 1.0 / SLIDER_RATIO); - zmw_hscrollbar(&numplayed_val, 1.0 / SLIDER_RATIO); - for (i = 1; argv[i]; i++) { - zmw_hscrollbar(&slider_vals[i], - 1.0 / SLIDER_RATIO); - } - } - } -} - -static void anchor(void) -{ - - zmw_font_family("terminal"); - zmw_font_size(14); - zmw_rgb(0.1, 0.1, 0.1); - zmw_color(Zmw_Color_Foreground, RGB(63, 63, 0)); /* font */ - zmw_color(Zmw_Color_Background_Pushed, RGB(0, 10, 4)); /* slider bg */ - zmw_color(Zmw_Color_Background_Poped, RGB(0, 42, 42)); /* button bg */ - zmw_color(Zmw_Color_Border_Light, RGB(0, 7, 63)); /* slider/button border */ - - ZMW(zmw_window("para_slider")) { - ZMW(zmw_vbox()) { - make_buttons(); - make_stream_input_field(); - zmw_color(Zmw_Color_Foreground, RGB(0, 63, 63)); /* font */ -// make_special_sliders(); - zmw_color(Zmw_Color_Foreground, RGB(63, 63, 0)); /* font */ - make_sliders(); - } - } -} - -static void get_atts(void) -{ - char buf[256]; - FILE *p = popen("para_client laa", "r"); - argv = para_malloc(255 * sizeof(char *)); /* FIXME */ - - argv[0] = para_strdup("all_attributes"); - argc = 1; - if (!p) - goto err_out; - while (fgets(buf, 255, p)) { - chop(buf); - argv[argc] = para_strdup(buf); - argc++; - } - pclose(p); - argv[argc] = NULL; - argc--; - if (argc > 1) - return; /* success */ -err_out: - if (argc > 1) - for (argc = 1; argv[argc]; argc++) - free(argv[argc]); - free(argv); - argc = 1; -} - -int main(int the_argc, char *the_argv[]) -{ - argc = the_argc; - argv = the_argv; - if (argc < 2) { - get_atts(); - if (argc < 2) - return -1; - } - slider_vals = para_malloc((argc + 1) * sizeof(int*)); - rst(); - load(); -// printf("argc: %d\n", argc); -// for (i = 1; argv[i]; i++) -// printf("argv[%d]: %s\n", i, argv[i]); - zmw_init(&argc, &argv); - zmw_main(anchor); - return 0; -}