aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/ephoto_config.c
diff options
context:
space:
mode:
authorStephen Houston <smhouston88@gmail.com>2018-02-13 15:23:11 -0600
committerStephen Houston <smhouston88@gmail.com>2018-02-13 15:24:06 -0600
commitd0ec29d753f01abcbe4dc355b8817401784daa70 (patch)
tree4a151604eeaf22e7c9c968f7ab53ca00b9fdbd54 /src/bin/ephoto_config.c
parenton initial config save - if nothing has been selected default to homedir (diff)
downloadephoto-master.tar.gz
Ephoto: Rework the gadget config to support multiple instances better. Always show settings icon when no pictures exists. Delete gadget win/popup on hide.HEADmaster
Diffstat (limited to 'src/bin/ephoto_config.c')
-rw-r--r--src/bin/ephoto_config.c128
1 files changed, 53 insertions, 75 deletions
diff --git a/src/bin/ephoto_config.c b/src/bin/ephoto_config.c
index 4279c32..41bde1b 100644
--- a/src/bin/ephoto_config.c
+++ b/src/bin/ephoto_config.c
@@ -4,12 +4,11 @@
static int _ephoto_config_load(Ephoto *ephoto);
static Eina_Bool _ephoto_on_config_save(void *data);
-static int _ephoto_gadget_config_load(Ephoto *ephoto);
+static int _ephoto_gadget_config_load(Ephoto *ephoto, int id, const char *profile);
static Eina_Bool _ephoto_gadget_on_config_save(void *data);
static Eet_Data_Descriptor *edd = NULL;
static Eet_Data_Descriptor *gedd = NULL;
-static Eet_Data_Descriptor *gedds = NULL;
static void
_config_save_cb(void *data, Evas_Object *obj EINA_UNUSED,
@@ -849,26 +848,29 @@ ephoto_config_init(Ephoto *ephoto)
}
static int
-_ephoto_gadget_config_load(Ephoto *ephoto)
+_ephoto_gadget_config_load(Ephoto *ephoto, int id, const char *profile)
{
Eet_File *ef;
char buf[4096], buf2[4096];
- snprintf(buf2, sizeof(buf2), "%s/ephoto", efreet_config_home_get());
- ecore_file_mkpath(buf2);
- snprintf(buf, sizeof(buf), "%s/ephoto_gadget.cfg", buf2);
-
- ef = eet_open(buf, EET_FILE_MODE_READ);
- if (!ef)
+ if (id >= 0)
{
- ephoto_gadget_config_free(ephoto);
- ephoto->gadget_config = calloc(1, sizeof(Ephoto_Gadget_Config));
- return 0;
- }
+ snprintf(buf2, sizeof(buf2), "%s/ephoto", efreet_config_home_get());
+ ecore_file_mkpath(buf2);
+ snprintf(buf, sizeof(buf), "%s/ephoto_gadget.%d.%s.cfg", buf2, id, profile);
- ephoto->gadget_config = eet_data_read(ef, gedd, "gadget_config");
- eet_close(ef);
+ ef = eet_open(buf, EET_FILE_MODE_READ);
+ if (!ef)
+ {
+ ephoto_gadget_config_free(ephoto);
+ ephoto->gadget_config = calloc(1, sizeof(Ephoto_Gadget_Config));
+ return 0;
+ }
+ ephoto->gadget_config = eet_data_read(ef, gedd, "gadget_config");
+ eet_close(ef);
+ return 1;
+ }
if (!ephoto->gadget_config || ephoto->gadget_config->config_version > CONFIG_VERSION)
{
ephoto_gadget_config_free(ephoto);
@@ -893,20 +895,21 @@ _ephoto_gadget_on_config_save(void *data)
Eet_File *ef;
char buf[4096], buf2[4096];
- snprintf(buf, sizeof(buf), "%s/ephoto/ephoto_gadget.cfg", efreet_config_home_get());
- snprintf(buf2, sizeof(buf2), "%s.tmp", buf);
-
- ef = eet_open(buf2, EET_FILE_MODE_WRITE);
- if (!ef)
- goto save_end;
-
- eet_data_write(ef, gedd, "gadget_config", ephoto->gadget_config, 1);
- if (eet_close(ef))
- goto save_end;
-
- if (!ecore_file_mv(buf2, buf))
- goto save_end;
-
+ if (ephoto->gadget_config->id >= 0)
+ {
+ snprintf(buf, sizeof(buf), "%s/ephoto/ephoto_gadget.%d.%s.cfg", efreet_config_home_get(),
+ ephoto->gadget_config->id, ephoto->gadget_config->profile);
+ snprintf(buf2, sizeof(buf2), "%s.tmp", buf);
+
+ ef = eet_open(buf2, EET_FILE_MODE_WRITE);
+ if (!ef)
+ goto save_end;
+ eet_data_write(ef, gedd, "gadget_config", ephoto->gadget_config, 1);
+ if (eet_close(ef))
+ goto save_end;
+ if (!ecore_file_mv(buf2, buf))
+ goto save_end;
+ }
save_end:
ecore_file_unlink(buf2);
@@ -922,48 +925,33 @@ ephoto_gadget_config_save(Ephoto *ephoto)
void
ephoto_gadget_config_free(Ephoto *ephoto)
{
- Ephoto_Gadget_Config_Item *gci;
if (ephoto->gadget_config)
{
- if (eina_list_count(ephoto->gadget_config->config_items))
- {
- EINA_LIST_FREE(ephoto->gadget_config->config_items, gci)
- {
- eina_stringshare_del(gci->profile);
- eina_stringshare_del(gci->directory);
- free(gci);
- }
- }
+ eina_stringshare_del(ephoto->gadget_config->profile);
+ eina_stringshare_del(ephoto->gadget_config->directory);
free(ephoto->gadget_config);
}
ephoto->gadget_config = NULL;
}
-Ephoto_Gadget_Config_Item *
-ephoto_gadget_config_item_get(Ephoto *ephoto, int id, const char *profile)
+void
+ephoto_gadget_config_remove(Ephoto *ephoto)
{
- Eina_List *l;
- Ephoto_Gadget_Config_Item *gci;
+ char buf[4096];
- EINA_LIST_FOREACH(ephoto->gadget_config->config_items, l, gci)
+ printf("%d x %s\n", ephoto->gadget_config->id, ephoto->gadget_config->profile);
+ if (ephoto->gadget_config->id >= 0)
{
- if (gci->id == id && eina_streq(profile, gci->profile))
- return gci;
+ snprintf(buf, sizeof(buf), "%s/ephoto/ephoto_gadget.%d.%s.cfg", efreet_config_home_get(),
+ ephoto->gadget_config->id, ephoto->gadget_config->profile);
+ printf("%s\n", buf);
+ ecore_file_unlink(buf);
}
- gci = calloc(1, sizeof(Ephoto_Gadget_Config_Item));
- gci->id = id;
- gci->profile = eina_stringshare_add(profile);
- gci->directory = eina_stringshare_add(eina_environment_home_get());;
- gci->slideshow_timeout = 3;
- ephoto->gadget_config->config_items =
- eina_list_append(ephoto->gadget_config->config_items, gci);
-
- return gci;
}
Eina_Bool
-ephoto_gadget_config_init(Ephoto *ephoto)
+ephoto_gadget_config_init(Ephoto *ephoto, int id, const char *profile)
{
Eet_Data_Descriptor_Class geddc;
@@ -974,39 +962,29 @@ ephoto_gadget_config_init(Ephoto *ephoto)
}
if (!gedd)
gedd = eet_data_descriptor_stream_new(&geddc);
- if (!eet_eina_stream_data_descriptor_class_set(&geddc, sizeof(geddc),
- "Ephoto_Gadget_Config_Item", sizeof(Ephoto_Gadget_Config_Item)))
- {
- return EINA_FALSE;
- }
- if (!gedds)
- gedds = eet_data_descriptor_stream_new(&geddc);
#undef GT
#undef GD
#define GT Ephoto_Gadget_Config
#define GD gedd
-#define GST Ephoto_Gadget_Config_Item
-#define GS gedds
#define GC_VAL(gedd, type, member, dtype) \
EET_DATA_DESCRIPTOR_ADD_BASIC(gedd, type, #member, member, dtype)
-#define GCS_VAL(edds, type, member, dtype) \
- EET_DATA_DESCRIPTOR_ADD_BASIC(gedds, type, #member, member, dtype)
-
- GCS_VAL(GS, GST, id, EET_T_INT);
- GCS_VAL(GS, GST, profile, EET_T_STRING);
- GCS_VAL(GS, GST, directory, EET_T_STRING);
- GCS_VAL(GS, GST, slideshow_timeout, EET_T_DOUBLE);
+ GC_VAL(GD, GT, id, EET_T_INT);
+ GC_VAL(GD, GT, profile, EET_T_STRING);
+ GC_VAL(GD, GT, directory, EET_T_STRING);
+ GC_VAL(GD, GT, slideshow_timeout, EET_T_DOUBLE);
GC_VAL(GD, GT, config_version, EET_T_INT);
- EET_DATA_DESCRIPTOR_ADD_LIST(gedd, Ephoto_Gadget_Config, "config_items", config_items, gedds);
-
- switch (_ephoto_gadget_config_load(ephoto))
+ switch (_ephoto_gadget_config_load(ephoto, id, profile))
{
case 0:
/* Start a new config */
ephoto->gadget_config->config_version = CONFIG_VERSION;
+ ephoto->gadget_config->id = id;
+ ephoto->gadget_config->profile = eina_stringshare_add(profile);
+ ephoto->gadget_config->directory = eina_stringshare_add(eina_environment_home_get());;
+ ephoto->gadget_config->slideshow_timeout = 3;
break;
default: