From 8f126343af94370c5f99c5b5e7c28f9d25283323 Mon Sep 17 00:00:00 2001 From: "Carsten Haitzler (Rasterman)" Date: Sun, 9 Mar 2014 16:09:05 +0900 Subject: [PATCH] add engine config (save/load and cmdline option) - no gui though --- TODO | 1 - src/bin/Makefile.am | 3 +- src/bin/config.c | 77 +++++++++++++++++++++++++++++++++++++++++++++ src/bin/config.h | 16 ++++++++++ src/bin/main.c | 32 ++++++++++++++++++- src/bin/video.c | 15 +++------ 6 files changed, 130 insertions(+), 14 deletions(-) create mode 100644 src/bin/config.c create mode 100644 src/bin/config.h diff --git a/TODO b/TODO index 54197bf..387ce4a 100644 --- a/TODO +++ b/TODO @@ -8,7 +8,6 @@ * spu channel list/selection * video channel list/selection * handle non-seekable content (eg streams) -* cmdline options * add subtitle file cmdline * loop all option * show busy anim until opened cb or failure diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index 06f42d8..b992fca 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -18,4 +18,5 @@ main.c main.h \ video.c video.h \ winvid.c winvid.h \ win.c win.h \ -winlist.c winlist.h +winlist.c winlist.h \ +config.c config.h diff --git a/src/bin/config.c b/src/bin/config.c new file mode 100644 index 0000000..1fb9280 --- /dev/null +++ b/src/bin/config.c @@ -0,0 +1,77 @@ +#include +#include "main.h" +#include "config.h" + +static Config *config = NULL; +static Eet_Data_Descriptor *edd_base = NULL; + +void +config_init(void) +{ + Eet_Data_Descriptor_Class eddc; + Eet_File *ef; + char buf[PATH_MAX]; + + elm_need_efreet(); + efreet_init(); + + eet_eina_stream_data_descriptor_class_set + (&eddc, sizeof(eddc), "Config", sizeof(Config)); + edd_base = eet_data_descriptor_stream_new(&eddc); + EET_DATA_DESCRIPTOR_ADD_BASIC + (edd_base, Config, "emotion_engine", emotion_engine, EET_T_STRING); + snprintf(buf, sizeof(buf), "%s/rage/config/standard/base.cfg", efreet_config_home_get()); + ef = eet_open(buf, EET_FILE_MODE_READ); + if (ef) + { + config = eet_data_read(ef, edd_base, "config"); + eet_close(ef); + } + if (!config) + { + config = calloc(1, sizeof(Config)); + if (!config) abort(); + // xine vlc gstreamer1 + config->emotion_engine = eina_stringshare_add("gstreamer1"); + config_save(); + } +} + +void +config_shutdown(void) +{ + if (config->emotion_engine) eina_stringshare_del(config->emotion_engine); + free(config); + if (edd_base) + { + eet_data_descriptor_free(edd_base); + edd_base = NULL; + } + efreet_shutdown(); +} + +Config * +config_get(void) +{ + return config; +} + +void +config_save(void) +{ + Eet_File *ef; + Eina_Bool ok; + char buf[PATH_MAX], buf2[PATH_MAX]; + + snprintf(buf, sizeof(buf), "%s/rage/config/standard/", efreet_config_home_get()); + ecore_file_mkpath(buf); + snprintf(buf, sizeof(buf), "%s/rage/config/standard/base.cfg.tmp", efreet_config_home_get()); + snprintf(buf2, sizeof(buf2), "%s/rage/config/standard/base.cfg", efreet_config_home_get()); + ef = eet_open(buf, EET_FILE_MODE_WRITE); + if (ef) + { + ok = eet_data_write(ef, edd_base, "config", config, 1); + eet_close(ef); + if (ok) ecore_file_mv(buf, buf2); + } +} diff --git a/src/bin/config.h b/src/bin/config.h new file mode 100644 index 0000000..3e4f51e --- /dev/null +++ b/src/bin/config.h @@ -0,0 +1,16 @@ +#ifndef _CONFIG_H__ +#define _CONFIG_H__ 1 + +typedef struct _Config Config; + +struct _Config +{ + const char *emotion_engine; +}; + +void config_init(void); +void config_shutdown(void); +Config *config_get(void); +void config_save(void); + +#endif diff --git a/src/bin/main.c b/src/bin/main.c index fb509c6..56cb17d 100644 --- a/src/bin/main.c +++ b/src/bin/main.c @@ -3,6 +3,7 @@ #include "win.h" #include "winvid.h" #include "winlist.h" +#include "config.h" static Eina_Bool _cb_show_timeout(void *data) @@ -30,9 +31,37 @@ elm_main(int argc, char **argv) Eina_List *list = NULL; int i; Inf *inf; + Config *config; + config_init(); + config = config_get(); for (i = 1; i < argc; i++) - list = eina_list_append(list, eina_stringshare_add(argv[i])); + { + if ((!strcmp(argv[i], "-h")) || + (!strcmp(argv[i], "-help")) || + (!strcmp(argv[i], "--help"))) + { + printf("Usage: rage [OPTIONS] [file1] [file2] [...]\n" + " Where OPTIONS can ben" + " -e ENGINE\n" + " ENGINE is one of gstreamer1, xine or vlc\n" + " The default is gtsreamer1\n" + " -h | -help | --help\n" + " This help\n"); + exit(0); + } + else if (!strcmp(argv[i], "-e")) + { + if (i < (argc - 1)) + { + i++; + eina_stringshare_del(config->emotion_engine); + config->emotion_engine = eina_stringshare_add(argv[i]); + } + } + else + list = eina_list_append(list, eina_stringshare_add(argv[i])); + } elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR); @@ -68,6 +97,7 @@ elm_main(int argc, char **argv) elm_run(); + config_shutdown(); elm_shutdown(); return 0; } diff --git a/src/bin/video.c b/src/bin/video.c index 264816c..500e6a5 100644 --- a/src/bin/video.c +++ b/src/bin/video.c @@ -2,6 +2,7 @@ #include #include "video.h" #include "rage_config.h" +#include "config.h" typedef struct _Video Video; @@ -407,15 +408,7 @@ video_add(Evas_Object *parent) Evas *e; Evas_Object *obj, *o; Video *sd; - char *modules[] = - { - NULL, - "gstreamer", - "xine", - "vlc", - "gstreamer1" - }; - char *mod = NULL; + Config *config; EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL); e = evas_object_evas_get(parent); @@ -429,8 +422,8 @@ video_add(Evas_Object *parent) emotion_init(); o = sd->o_vid = emotion_object_add(evas_object_evas_get(obj)); emotion_object_keep_aspect_set(o, EMOTION_ASPECT_KEEP_NONE); - mod = modules[4]; - if (!emotion_object_init(o, mod)) + config = config_get(); + if (!emotion_object_init(o, config->emotion_engine)) { evas_object_del(sd->o_vid); sd->o_vid = NULL;