Remove para_sdl_gui, para_slider, para_krell.
[paraslash.git] / slider.c
diff --git a/slider.c b/slider.c
deleted file mode 100644 (file)
index 242f1c3..0000000
--- a/slider.c
+++ /dev/null
@@ -1,330 +0,0 @@
-/*
- * Copyright (C) 2004-2006 Andre Noll <maan@systemlinux.org>
- *
- * 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;
-}