2012-06-26 17:53:57 -07:00
|
|
|
#include "private.h"
|
|
|
|
|
|
|
|
#include <Elementary.h>
|
2015-02-14 03:08:50 -08:00
|
|
|
#include <Efreet.h>
|
2012-06-26 17:53:57 -07:00
|
|
|
#include "config.h"
|
|
|
|
#include "termio.h"
|
|
|
|
#include "options.h"
|
|
|
|
#include "options_theme.h"
|
2013-10-09 06:51:15 -07:00
|
|
|
#include "options_themepv.h"
|
2012-10-09 01:40:37 -07:00
|
|
|
#include "utils.h"
|
2013-09-08 11:16:24 -07:00
|
|
|
#include "main.h"
|
2012-06-26 17:53:57 -07:00
|
|
|
|
2012-10-02 13:24:13 -07:00
|
|
|
typedef struct _Theme Theme;
|
|
|
|
struct _Theme
|
|
|
|
{
|
|
|
|
Elm_Object_Item *item;
|
|
|
|
const char *name;
|
|
|
|
Evas_Object *term;
|
|
|
|
};
|
|
|
|
|
2013-12-02 22:25:37 -08:00
|
|
|
static Evas_Object *op_themelist;
|
|
|
|
static Eina_List *themes = NULL;
|
|
|
|
static Ecore_Timer *seltimer = NULL;
|
|
|
|
|
2012-10-02 13:24:13 -07:00
|
|
|
static char *
|
2013-08-27 06:36:50 -07:00
|
|
|
_cb_op_theme_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
|
2012-10-02 13:24:13 -07:00
|
|
|
{
|
|
|
|
Theme *t = data;
|
|
|
|
char buf[4096], *p;
|
|
|
|
|
|
|
|
eina_strlcpy(buf, t->name, sizeof(buf));
|
|
|
|
p = strrchr(buf, '.');
|
|
|
|
if (p) *p = 0;
|
|
|
|
|
|
|
|
return strdup(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Evas_Object *
|
|
|
|
_cb_op_theme_content_get(void *data, Evas_Object *obj, const char *part)
|
|
|
|
{
|
|
|
|
Theme *t = data;
|
|
|
|
|
|
|
|
if (!strcmp(part, "elm.swallow.icon"))
|
|
|
|
{
|
|
|
|
Evas_Object *o;
|
2013-10-09 06:51:15 -07:00
|
|
|
Config *config = termio_config_get(t->term);
|
2014-02-26 14:03:27 -08:00
|
|
|
|
2013-10-09 06:51:15 -07:00
|
|
|
if (config)
|
|
|
|
{
|
2014-02-26 14:03:27 -08:00
|
|
|
o = options_theme_preview_add(obj, config,
|
|
|
|
theme_path_get(t->name),
|
2013-10-09 06:51:15 -07:00
|
|
|
128 * elm_config_scale_get(),
|
|
|
|
64 * elm_config_scale_get());
|
2013-10-11 22:18:08 -07:00
|
|
|
return o;
|
2013-10-09 06:51:15 -07:00
|
|
|
}
|
2012-10-02 13:24:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-08-27 06:36:50 -07:00
|
|
|
_cb_op_theme_sel(void *data, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
|
2012-10-02 13:24:13 -07:00
|
|
|
{
|
|
|
|
Theme *t = data;
|
|
|
|
Config *config = termio_config_get(t->term);
|
|
|
|
|
|
|
|
if ((config->theme) && (!strcmp(t->name, config->theme)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
eina_stringshare_replace(&(config->theme), t->name);
|
|
|
|
config_save(config, NULL);
|
2013-09-08 11:16:24 -07:00
|
|
|
change_theme(termio_win_get(t->term), config);
|
2012-10-02 13:24:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_cb_op_theme_sort(const void *d1, const void *d2)
|
|
|
|
{
|
|
|
|
return strcasecmp(d1, d2);
|
|
|
|
}
|
|
|
|
|
2013-12-02 22:25:37 -08:00
|
|
|
static Eina_Bool
|
|
|
|
_cb_sel_item(void *data)
|
|
|
|
{
|
|
|
|
Theme *t = data;
|
|
|
|
|
|
|
|
if (t)
|
|
|
|
{
|
|
|
|
elm_gengrid_item_selected_set(t->item, EINA_TRUE);
|
|
|
|
elm_gengrid_item_bring_in(t->item, ELM_GENGRID_ITEM_SCROLLTO_MIDDLE);
|
|
|
|
}
|
|
|
|
seltimer = NULL;
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
2012-06-26 17:53:57 -07:00
|
|
|
void
|
2012-10-02 13:24:13 -07:00
|
|
|
options_theme(Evas_Object *opbox, Evas_Object *term)
|
2012-06-26 17:53:57 -07:00
|
|
|
{
|
2012-10-02 13:24:13 -07:00
|
|
|
Evas_Object *o, *box, *fr;
|
2013-12-02 22:25:37 -08:00
|
|
|
Elm_Gengrid_Item_Class *it_class;
|
2014-02-26 14:03:27 -08:00
|
|
|
Eina_List *files, *userfiles, *l, *l_next;
|
2012-10-02 13:24:13 -07:00
|
|
|
char buf[4096], *file;
|
2014-02-26 14:03:27 -08:00
|
|
|
const char *config_dir = efreet_config_home_get(),
|
|
|
|
*data_dir = elm_app_data_dir_get();
|
2013-10-09 08:28:18 -07:00
|
|
|
Config *config = termio_config_get(term);
|
2014-02-26 14:03:27 -08:00
|
|
|
Eina_Bool to_skip = EINA_FALSE;
|
|
|
|
double scale = elm_config_scale_get();
|
2012-06-26 17:53:57 -07:00
|
|
|
|
2012-10-02 13:24:13 -07:00
|
|
|
options_theme_clear();
|
|
|
|
|
|
|
|
fr = o = elm_frame_add(opbox);
|
2012-06-26 17:53:57 -07:00
|
|
|
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
|
|
|
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
2014-07-20 14:04:47 -07:00
|
|
|
elm_object_text_set(o, _("Theme"));
|
2012-06-26 17:53:57 -07:00
|
|
|
elm_box_pack_end(opbox, o);
|
2012-10-02 13:24:13 -07:00
|
|
|
evas_object_show(o);
|
|
|
|
|
|
|
|
box = o = elm_box_add(opbox);
|
|
|
|
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
|
|
|
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
|
|
|
elm_box_horizontal_set(o, EINA_TRUE);
|
|
|
|
elm_object_content_set(fr, o);
|
|
|
|
evas_object_show(o);
|
|
|
|
|
2013-12-02 22:25:37 -08:00
|
|
|
it_class = elm_gengrid_item_class_new();
|
|
|
|
it_class->item_style = "thumb";
|
2012-10-02 13:24:13 -07:00
|
|
|
it_class->func.text_get = _cb_op_theme_text_get;
|
|
|
|
it_class->func.content_get = _cb_op_theme_content_get;
|
|
|
|
|
2013-12-02 22:25:37 -08:00
|
|
|
op_themelist = o = elm_gengrid_add(opbox);
|
2012-10-02 13:24:13 -07:00
|
|
|
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
|
|
|
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
2014-02-26 14:03:27 -08:00
|
|
|
elm_gengrid_item_size_set(o, scale * 160, scale * 180);
|
2012-10-02 13:24:13 -07:00
|
|
|
|
2014-02-26 14:03:27 -08:00
|
|
|
snprintf(buf, sizeof(buf), "%s/themes", data_dir);
|
2012-10-02 13:24:13 -07:00
|
|
|
files = ecore_file_ls(buf);
|
|
|
|
if (files)
|
|
|
|
files = eina_list_sort(files, eina_list_count(files),
|
|
|
|
_cb_op_theme_sort);
|
|
|
|
|
2014-02-26 14:03:27 -08:00
|
|
|
snprintf(buf, sizeof(buf), "%s/terminology/themes", config_dir);
|
|
|
|
userfiles = ecore_file_ls(buf);
|
|
|
|
if (userfiles)
|
|
|
|
userfiles = eina_list_sort(userfiles, eina_list_count(userfiles),
|
|
|
|
_cb_op_theme_sort);
|
|
|
|
|
|
|
|
if (files && userfiles)
|
|
|
|
files = eina_list_sorted_merge(files, userfiles, _cb_op_theme_sort);
|
|
|
|
else if (userfiles)
|
|
|
|
files = userfiles;
|
|
|
|
|
2013-12-02 22:25:37 -08:00
|
|
|
if (seltimer)
|
|
|
|
{
|
|
|
|
ecore_timer_del(seltimer);
|
|
|
|
seltimer = NULL;
|
|
|
|
}
|
2014-02-26 14:03:27 -08:00
|
|
|
|
|
|
|
EINA_LIST_FOREACH_SAFE(files, l, l_next, file)
|
2012-10-02 13:24:13 -07:00
|
|
|
{
|
2013-10-09 08:28:18 -07:00
|
|
|
const char *ext = strchr(file, '.');
|
2014-02-26 14:03:27 -08:00
|
|
|
|
|
|
|
if (!((config) && (file[0] != '.') &&
|
|
|
|
((ext) && (!strcasecmp(".edj", ext)))))
|
2013-10-09 08:28:18 -07:00
|
|
|
{
|
2014-02-26 14:03:27 -08:00
|
|
|
free(file);
|
|
|
|
files = eina_list_remove_list(files, l);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EINA_LIST_FOREACH_SAFE(files, l, l_next, file)
|
|
|
|
{
|
|
|
|
Theme *t;
|
|
|
|
if (to_skip == EINA_TRUE)
|
|
|
|
{
|
|
|
|
to_skip = EINA_FALSE;
|
|
|
|
goto end_loop;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (l_next && l_next->data && !strcmp(file, l_next->data))
|
|
|
|
{
|
|
|
|
to_skip = EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
t = calloc(1, sizeof(Theme));
|
2015-11-19 12:07:18 -08:00
|
|
|
if (!t) break;
|
2014-02-26 14:03:27 -08:00
|
|
|
t->name = eina_stringshare_add(file);
|
|
|
|
t->term = term;
|
|
|
|
t->item = elm_gengrid_item_append(o, it_class, t,
|
|
|
|
_cb_op_theme_sel, t);
|
|
|
|
if (t->item)
|
|
|
|
{
|
|
|
|
themes = eina_list_append(themes, t);
|
2014-02-27 14:56:19 -08:00
|
|
|
if ((config) && (config->theme) &&
|
2014-02-26 14:03:27 -08:00
|
|
|
(!strcmp(config->theme, t->name)))
|
2013-10-09 08:28:18 -07:00
|
|
|
{
|
2014-02-26 14:03:27 -08:00
|
|
|
if (seltimer) ecore_timer_del(seltimer);
|
|
|
|
seltimer = ecore_timer_add(0.2, _cb_sel_item, t);
|
2013-10-09 08:28:18 -07:00
|
|
|
}
|
|
|
|
}
|
2014-02-26 14:03:27 -08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
eina_stringshare_del(t->name);
|
|
|
|
free(t);
|
|
|
|
}
|
|
|
|
end_loop:
|
|
|
|
files = eina_list_remove_list(files, l);
|
2012-10-02 13:24:13 -07:00
|
|
|
free(file);
|
|
|
|
}
|
|
|
|
|
2013-12-02 22:25:37 -08:00
|
|
|
elm_gengrid_item_class_free(it_class);
|
2012-10-02 13:24:13 -07:00
|
|
|
|
|
|
|
elm_box_pack_end(box, o);
|
|
|
|
evas_object_size_hint_weight_set(opbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
|
|
|
evas_object_size_hint_align_set(opbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
|
|
|
evas_object_show(o);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
options_theme_clear(void)
|
|
|
|
{
|
|
|
|
Theme *t;
|
|
|
|
|
|
|
|
op_themelist = NULL;
|
|
|
|
|
2013-12-02 22:25:37 -08:00
|
|
|
if (seltimer)
|
|
|
|
{
|
|
|
|
ecore_timer_del(seltimer);
|
|
|
|
seltimer = NULL;
|
|
|
|
}
|
2012-10-02 13:24:13 -07:00
|
|
|
EINA_LIST_FREE(themes, t)
|
|
|
|
{
|
|
|
|
eina_stringshare_del(t->name);
|
|
|
|
free(t);
|
|
|
|
}
|
2012-06-26 17:53:57 -07:00
|
|
|
}
|