diff --git a/.gitignore b/.gitignore index 673b4129..8596b506 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ /data/fonts/Makefile.in /data/icons/Makefile /data/icons/Makefile.in +/data/backgrounds/Makefile +/data/backgrounds/Makefile.in /data/images/Makefile /data/images/Makefile.in /data/themes/Makefile diff --git a/configure.ac b/configure.ac index 0291be11..55e5b5b8 100644 --- a/configure.ac +++ b/configure.ac @@ -82,6 +82,7 @@ src/bin/Makefile data/Makefile data/desktop/Makefile data/icons/Makefile +data/backgrounds/Makefile data/images/Makefile data/fonts/Makefile data/themes/Makefile diff --git a/data/Makefile.am b/data/Makefile.am index 735ca178..83c45f16 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -1,3 +1,3 @@ MAINTAINERCLEANFILES = Makefile.in -SUBDIRS = desktop icons images fonts themes +SUBDIRS = desktop icons images fonts themes backgrounds diff --git a/data/backgrounds/Makefile.am b/data/backgrounds/Makefile.am new file mode 100644 index 00000000..2069a4b0 --- /dev/null +++ b/data/backgrounds/Makefile.am @@ -0,0 +1,8 @@ +MAINTAINERCLEANFILES = Makefile.in + +filesdir = $(pkgdatadir)/backgrounds +files_DATA = \ +mystic.png \ +texture_background.png + +EXTRA_DIST = $(files_DATA) diff --git a/data/backgrounds/mystic.png b/data/backgrounds/mystic.png new file mode 100644 index 00000000..b26974dd Binary files /dev/null and b/data/backgrounds/mystic.png differ diff --git a/data/backgrounds/texture_background.png b/data/backgrounds/texture_background.png new file mode 100644 index 00000000..ac972624 Binary files /dev/null and b/data/backgrounds/texture_background.png differ diff --git a/src/bin/config.c b/src/bin/config.c index bd936880..ef41de9b 100644 --- a/src/bin/config.c +++ b/src/bin/config.c @@ -26,7 +26,7 @@ config_init(void) 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); @@ -72,6 +72,8 @@ config_init(void) (edd_base, Config, "theme", theme, EET_T_STRING); EET_DATA_DESCRIPTOR_ADD_BASIC (edd_base, Config, "background", background, EET_T_STRING); + EET_DATA_DESCRIPTOR_ADD_LIST_STRING + (edd_base, Config, "wallpaper_paths", wallpaper_paths); EET_DATA_DESCRIPTOR_ADD_BASIC (edd_base, Config, "wordsep", wordsep, EET_T_STRING); EET_DATA_DESCRIPTOR_ADD_BASIC @@ -177,6 +179,9 @@ config_save(Config *config, const char *key) void config_sync(const Config *config_src, Config *config) { + Eina_List *l; + const char *path; + // SOME fields have to be consistent between configs config->font.size = config_src->font.size; eina_stringshare_replace(&(config->font.name), config_src->font.name); @@ -192,6 +197,14 @@ config_sync(const Config *config_src, Config *config) eina_stringshare_replace(&(config->theme), config_src->theme); eina_stringshare_replace(&(config->wordsep), config_src->wordsep); config->scrollback = config_src->scrollback; + if (config->wallpaper_paths) + EINA_LIST_FREE(config->wallpaper_paths, path) + eina_stringshare_del(path); + + config->wallpaper_paths = NULL; + EINA_LIST_FOREACH(config_src->wallpaper_paths, l, path) + config->wallpaper_paths = eina_list_append(config->wallpaper_paths, eina_stringshare_add(path)); + config->tab_zoom = config_src->tab_zoom; config->vidmod = config_src->vidmod; config->jump_on_keypress = config_src->jump_on_keypress; @@ -450,9 +463,10 @@ config_load(const char *key) config->tab_zoom = 0.5; config->theme = eina_stringshare_add("default.edj"); config->background = NULL; + config->wallpaper_paths = NULL; config->translucent = EINA_FALSE; config->jump_on_change = EINA_TRUE; - config->jump_on_keypress = EINA_TRUE; + config->jump_on_keypress = EINA_TRUE; config->flicker_on_key = EINA_TRUE; config->disable_cursor_blink = EINA_FALSE; config->disable_visual_bell = EINA_FALSE; @@ -492,20 +506,26 @@ config_load(const char *key) if (config) config->config_key = eina_stringshare_add(key); /* not in eet */ - - return config; + + return config; } Config * config_fork(Config *config) { Config *config2; - + Eina_List *node; + char *path; config2 = calloc(1, sizeof(Config)); if (!config2) return NULL; #define CPY(fld) config2->fld = config->fld; #define SCPY(fld) if (config->fld) config2->fld = eina_stringshare_add(config->fld) - +#define SLSTCPY(fld) \ + do { Eina_List *__l; const char *__s; \ + EINA_LIST_FOREACH(config->fld, __l, __s) \ + config2->fld = eina_list_append \ + (config2->fld, eina_stringshare_add(__s)); } while (0) + CPY(version); SCPY(font.name); CPY(font.size); @@ -520,6 +540,7 @@ config_fork(Config *config) CPY(helper.inline_please); SCPY(theme); SCPY(background); + SLSTCPY(wallpaper_paths); SCPY(wordsep); CPY(scrollback); CPY(tab_zoom); @@ -551,8 +572,12 @@ config_fork(Config *config) void config_del(Config *config) { + const char *path; if (!config) return; - + + EINA_LIST_FREE(config->wallpaper_paths,path) + eina_stringshare_del(path); + eina_stringshare_del(config->font.name); eina_stringshare_del(config->font.orig_name); eina_stringshare_del(config->theme); @@ -565,7 +590,7 @@ config_del(Config *config) eina_stringshare_del(config->helper.local.general); eina_stringshare_del(config->helper.local.video); eina_stringshare_del(config->helper.local.image); - + eina_stringshare_del(config->config_key); /* not in eet */ free(config); } diff --git a/src/bin/config.h b/src/bin/config.h index ecf6cf57..8b4e7445 100644 --- a/src/bin/config.h +++ b/src/bin/config.h @@ -32,7 +32,8 @@ struct _Config Eina_Bool inline_please; } helper; const char *theme; - const char *background; + const char *background; + Eina_List *wallpaper_paths; const char *wordsep; int scrollback; double tab_zoom; diff --git a/src/bin/options.c b/src/bin/options.c index fb9ab5de..2829a910 100644 --- a/src/bin/options.c +++ b/src/bin/options.c @@ -58,6 +58,7 @@ _cb_op_del_delay(void *data EINA_UNUSED) evas_object_del(op_opbox); evas_object_del(op_frame); options_font_clear(); + options_wallpaper_clear(); options_theme_clear(); op_opbox = NULL; op_frame = NULL; diff --git a/src/bin/options_wallpaper.c b/src/bin/options_wallpaper.c index c2d4e590..0245cf89 100644 --- a/src/bin/options_wallpaper.c +++ b/src/bin/options_wallpaper.c @@ -3,18 +3,479 @@ #include #include "config.h" #include "termio.h" +#include "media.h" #include "options.h" #include "options_wallpaper.h" +#include "extns.h" +#include + +typedef struct _Background_Item +{ + const char *path; + Eina_Bool selected; + Elm_Object_Item *item; + Evas_Object *term; +} +Background_Item; + +typedef struct _Wallpaper_Path_Item +{ + const char *path; +} +Wallpaper_Path_Item; + +static void _renew_gengrid_backgrounds(Evas_Object *term); + +static Evas_Object *inwin, *list, *bg_grid, *parent, *bx; +static Ecore_Timer *seltimer = NULL; +static Eina_List *backgroundlist = NULL; +static Eina_List *pathlist = NULL; + +static char * +_grid_text_get(void *data, Evas_Object *obj, const char *part) +{ + Background_Item *item = data; + const char *s; + + if (!item->path) return strdup("None"); + s = ecore_file_file_get(item->path); + if (s) return strdup(s); + return NULL; +} + +static Evas_Object * +_grid_content_get(void *data, Evas_Object *obj, const char *part) +{ + Background_Item *item = data; + Evas_Object *o, *oe; + Config *config = termio_config_get(item->term); + char path[PATH_MAX]; + + if (!strcmp(part, "elm.swallow.icon")) + { + if (item->path) + { + return media_add(obj, item->path, config, MEDIA_THUMB, TYPE_IMG); + } + else + { + if (!config->theme) return NULL; + snprintf(path, PATH_MAX, "%s/themes/%s", elm_app_data_dir_get(), + config->theme); + o = elm_layout_add(obj); + oe = elm_layout_edje_get(o); + edje_object_file_set(oe, path, "terminology/background"); + evas_object_show(o); + return o; + } + } + return NULL; +} + +static void +_item_selected(void *data, Evas_Object *obj, void *event) +{ + Background_Item *item = data; + Config *config = termio_config_get(item->term); + + if (!config) return; + if (!item->path) + { + //no background + eina_stringshare_del(config->background); + config->background = NULL; + config_save(config, NULL); + main_media_update(config); + } + else + { + eina_stringshare_replace(&(config->background), item->path); + config_save(config, NULL); + main_media_update(config); + } +} +/* + * Method to open the in windows + */ +static void +_done_click(void *data, Evas_Object *obj, void *event) +{ + evas_object_del(inwin); + inwin = NULL; +} +/* + * Methods for the genlist + */ +static char * +_item_label_get(void *data, Evas_Object *obj, const char *part) +{ + Wallpaper_Path_Item *item = data; + return strdup(item->path); +} + +static Evas_Object * +_item_content_get(void *data, Evas_Object *obj, const char *part) +{ + return NULL; +} + +static void +_item_sel_cb(void *data, Evas_Object *obj, void *event) +{ +} + +static void +_fill_path_list(Eina_List *paths, Evas_Object *list) +{ + Eina_List *node = NULL; + char *path; + Wallpaper_Path_Item *wpi = NULL; + Elm_Genlist_Item_Class *itc; + + itc = elm_genlist_item_class_new(); + itc->item_style = "default"; + itc->func.text_get = _item_label_get; + itc->func.content_get = _item_content_get; + itc->func.state_get = NULL; + itc->func.del = NULL; + EINA_LIST_FOREACH(paths, node, path) + { + wpi = calloc(1, sizeof(Wallpaper_Path_Item)); + if (wpi) + { + wpi->path = eina_stringshare_add(path); + elm_genlist_item_append(list, itc, wpi, NULL, + ELM_GENLIST_ITEM_NONE, + _item_sel_cb, NULL); + pathlist = eina_list_append(pathlist, wpi); + } + } + elm_gengrid_item_class_free(itc); + evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL); +} + +static void +_file_is_chosen(void *data, Evas_Object *obj, void *event) +{ + Eina_List *node; + char *saved_path; + Config *config = termio_config_get(data); + Wallpaper_Path_Item *item; + + EINA_LIST_FOREACH(config->wallpaper_paths, node, saved_path) + if (!strcmp(event, saved_path)) return; + + config->wallpaper_paths = eina_list_append(config->wallpaper_paths, + eina_stringshare_add(event)); + config_save(config, NULL); + main_media_update(config); + evas_object_del(list); + EINA_LIST_FREE(pathlist, item) + { + eina_stringshare_del(item->path); + free(item); + } + list = elm_genlist_add(inwin); + _fill_path_list(config->wallpaper_paths, list); + elm_box_pack_start(elm_win_inwin_content_get(inwin), list); + evas_object_show(list); + _renew_gengrid_backgrounds(data); +} + +static void +_delete_path_click(void *data, Evas_Object *obj, void *event) +{ + Elm_Object_Item *selected = elm_genlist_selected_item_get(list); + Config *config = termio_config_get(data); + Wallpaper_Path_Item *item; + + if (selected) + { + item = elm_object_item_data_get(selected); + if (item) + { + config->wallpaper_paths = eina_list_remove(config->wallpaper_paths, + item->path); + config_save(config, NULL); + main_media_update(config); + evas_object_del(list); + EINA_LIST_FREE(pathlist, item) + { + eina_stringshare_del(item->path); + free(item); + } + list = elm_genlist_add(inwin); + _fill_path_list(config->wallpaper_paths, list); + elm_box_pack_start(elm_win_inwin_content_get(inwin), list); + evas_object_show(list); + _renew_gengrid_backgrounds(data); + } + } +} + +static void +_path_edit_click(void *data, Evas_Object *obj, void *event) +{ + Config *config = termio_config_get(data); + Evas_Object *parent = elm_object_top_widget_get(obj); + Evas_Object *o, *bx, *bx2; + + inwin = o = elm_win_inwin_add(parent); + evas_object_show(o); + + bx = elm_box_add(inwin); + evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, 0.0); + evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, 0.0); + elm_win_inwin_content_set(o, bx); + evas_object_show(bx); + + list = o = elm_genlist_add(inwin); + _fill_path_list(config->wallpaper_paths, o); + elm_box_pack_end(bx, o); + evas_object_show(o); + + o = elm_box_add(inwin); + evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); + evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0); + elm_box_horizontal_set(o, EINA_TRUE); + elm_box_pack_end(bx, o); + evas_object_show(o); + bx2 = o; + + bx = o = elm_box_add(inwin); + evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); + evas_object_size_hint_align_set(o, 0.0, 0.0); + elm_box_horizontal_set(o, EINA_TRUE); + elm_box_pack_end(bx2, o); + evas_object_show(o); + + o = elm_fileselector_button_add(inwin); + evas_object_size_hint_weight_set(o, 0.0, 0.0); + evas_object_size_hint_align_set(o, 0.0, 0.0); + elm_fileselector_button_inwin_mode_set(o, EINA_TRUE); + elm_fileselector_button_folder_only_set(o, EINA_TRUE); + elm_object_text_set(o, "Add path"); + evas_object_smart_callback_add(o, "file,chosen", _file_is_chosen, data); + elm_box_pack_end(bx, o); + evas_object_show(o); + + o = elm_button_add(inwin); + evas_object_size_hint_weight_set(o, 0.0, 0.0); + evas_object_size_hint_align_set(o, 0.0, 0.0); + elm_object_text_set(o, "Delete path"); + elm_box_pack_end(bx, o); + evas_object_smart_callback_add(o, "clicked", _delete_path_click, data); + evas_object_show(o); + + o = elm_button_add(inwin); + evas_object_size_hint_weight_set(o, 0.0, 0.0); + evas_object_size_hint_align_set(o, 0.0, 0.0); + elm_object_text_set(o, "Done"); + elm_box_pack_end(bx2, o); + evas_object_smart_callback_add(o, "clicked", _done_click, inwin); + evas_object_show(o); +} + +static Eina_List* +_rec_read_directorys(Eina_List *list, char *root_path, Evas_Object *term) +{ + Eina_List *childs = ecore_file_ls(root_path); + char *file_name, *ext; + int i; + char path[PATH_MAX]; + Background_Item *item; + + if (!childs) return list; + EINA_LIST_FREE(childs, file_name) + { + snprintf(path, PATH_MAX, "%s/%s", root_path, file_name); + ext = strchr(file_name, '.'); + if ((!ecore_file_is_dir(path)) && (file_name[0] != '.') && (ext)) + { + for (i = 0; extn_img[i]; i++) + { + if (strcasecmp(extn_img[i], ext)) continue; + item = calloc(1, sizeof(Background_Item)); + if (item) + { + item->path = eina_stringshare_add(path); + item->term = term; + list = eina_list_append(list, item); + } + break; + } + } + else + { + list = _rec_read_directorys(list, path, term); + } + free(file_name); + } + return list; +} + +static void +_read_directorys(Evas_Object *term) +{ + Config *config = termio_config_get(term); + char path[PATH_MAX]; + Background_Item *item; + Eina_List *node; + char *path_iterate; + char *home_dir; + + if (backgroundlist) + { + EINA_LIST_FREE(backgroundlist, item) + { + if (item->path) eina_stringshare_del(item->path); + free(item); + } + } + //first of all append the None !! + item = calloc(1, sizeof(Background_Item)); + item->path = NULL; + item->term = term; + backgroundlist = eina_list_append(backgroundlist, item); + //append the standart directory + snprintf(path, sizeof(path), "%s/backgrounds/", elm_app_data_dir_get()); + backgroundlist = _rec_read_directorys(backgroundlist, path, term); + //append the Home background directory if this directory exists + home_dir = getenv("HOME"); + if(home_dir) + { + snprintf(path, sizeof(path), "%s/.e/e/backgrounds/", home_dir); + backgroundlist = _rec_read_directorys(backgroundlist, path, term); + } + //Now append all the directorys which are stored + EINA_LIST_FOREACH(config->wallpaper_paths, node, path_iterate) + { + backgroundlist = _rec_read_directorys(backgroundlist, path_iterate, term); + } +} + +static int +_cb_path_sort(const void *d1, const void *d2) +{ + const Background_Item *item1 = d1; + const Background_Item *item2 = d2; + + if (!item1->path) return -1; + if (!item2->path) return 1; + return strcasecmp(item1->path, item2->path); +} + +static Eina_Bool +_cb_selection_timer(void *data) +{ + Elm_Object_Item *item = data; + + elm_gengrid_item_selected_set(item, EINA_TRUE); + elm_gengrid_item_bring_in(item, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE); + seltimer = NULL; + return EINA_FALSE; +} + +static void +_renew_gengrid_backgrounds(Evas_Object *term) +{ + Background_Item *item; + Eina_List *node; + Config *config = termio_config_get(term); + Evas_Object *o; + Elm_Gengrid_Item_Class *item_class; + + item_class = elm_gengrid_item_class_new(); + item_class->func.text_get = _grid_text_get; + item_class->func.content_get = _grid_content_get; + + if (bg_grid) evas_object_del(bg_grid); + + bg_grid = o = elm_gengrid_add(parent); + 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_gengrid_item_size_set(o, elm_config_scale_get() * 100, + elm_config_scale_get() * 80); + _read_directorys(term); + backgroundlist = eina_list_sort(backgroundlist, + eina_list_count(backgroundlist), + _cb_path_sort); + EINA_LIST_FOREACH(backgroundlist, node, item) + { + item->item = elm_gengrid_item_append(bg_grid, item_class, item, + _item_selected, item); + if ((!item->path) && (!config->background)) + { + if (!seltimer) ecore_timer_del(seltimer); + seltimer = ecore_timer_add(0.2, _cb_selection_timer, item->item); + } + else if ((item->path) && (config->background)) + { + if (strcmp(item->path, config->background) == 0) + { + if (!seltimer) ecore_timer_del(seltimer); + seltimer = ecore_timer_add(0.2, _cb_selection_timer, item->item); + } + } + } + elm_box_pack_start(bx, o); + evas_object_show(o); + elm_gengrid_item_class_free(item_class); +} void options_wallpaper(Evas_Object *opbox, Evas_Object *term EINA_UNUSED) { - Evas_Object *o; + Evas_Object *frame, *o, *o2; + Config *config = termio_config_get(term); + Background_Item *item; - o = elm_label_add(opbox); + bg_grid = NULL; + parent = opbox; + + frame = o = elm_frame_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_object_text_set(o, "Not Implemented Yet."); + elm_object_text_set(o, "Background"); evas_object_show(o); elm_box_pack_end(opbox, o); + + bx = o = elm_box_add(opbox); + evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); + evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0); + elm_object_content_set(frame, o); + evas_object_show(o); + _renew_gengrid_backgrounds(term); + + o = elm_button_add(opbox); + evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); + evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0); + elm_object_text_set(o, "Edit paths"); + elm_box_pack_end(bx, o); + evas_object_show(o); + evas_object_smart_callback_add(o, "clicked", _path_edit_click, term); + +} +void +options_wallpaper_clear(void) +{ + Background_Item *item; + Wallpaper_Path_Item *wpi; + + EINA_LIST_FREE(backgroundlist, item) + { + if (item->path) eina_stringshare_del(item->path); + free(item); + } + backgroundlist = NULL; + if (pathlist) + { + EINA_LIST_FREE(pathlist, wpi) + { + eina_stringshare_del(wpi->path); + free(wpi); + } + pathlist = NULL; + } } diff --git a/src/bin/options_wallpaper.h b/src/bin/options_wallpaper.h index 141985f0..5c68e5bf 100644 --- a/src/bin/options_wallpaper.h +++ b/src/bin/options_wallpaper.h @@ -1 +1,2 @@ void options_wallpaper(Evas_Object *opbox, Evas_Object *term); +void options_wallpaper_clear(void);