add engine config (save/load and cmdline option) - no gui though

This commit is contained in:
Carsten Haitzler 2014-03-09 16:09:05 +09:00
parent 77aabdae63
commit 8f126343af
6 changed files with 130 additions and 14 deletions

1
TODO
View File

@ -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

View File

@ -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

77
src/bin/config.c Normal file
View File

@ -0,0 +1,77 @@
#include <Elementary.h>
#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);
}
}

16
src/bin/config.h Normal file
View File

@ -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

View File

@ -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++)
{
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;
}

View File

@ -2,6 +2,7 @@
#include <Emotion.h>
#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;