yakov pushed a commit to branch master.

http://git.enlightenment.org/tools/erigo.git/commit/?id=a7b5a4ceed0834201974ba4826b9a97b6f0986ac

commit a7b5a4ceed0834201974ba4826b9a97b6f0986ac
Author: Yakov Goldberg <yako...@samsung.com>
Date:   Thu Apr 2 10:52:38 2015 +0300

    Add themes management into Erigo settings
---
 CMakeLists.txt                        |   1 +
 src/bin/egui_gui/CMakeLists.txt       |   2 +
 src/bin/egui_gui/editor.c             |  77 ++++++++++++++++
 src/bin/egui_gui/egui_layout.json     | 167 ++++++++++++++++++++++++++++++++--
 src/bin/egui_gui/egui_logic.c         |   6 ++
 src/bin/egui_gui/egui_logic_private.h |   1 +
 src/bin/egui_gui/settings.c           | 148 ++++++++++++++++++++++++++++++
 src/bin/egui_gui/settings.h           |  26 ++++++
 src/bin/egui_gui/settings_view.c      | 128 ++++++++++++++++++++++++++
 src/lib/gui_parser.c                  |  26 +++++-
 src/lib/gui_widget.c                  |  18 ++++
 src/lib/gui_widget.h                  |   6 ++
 src/lib/json_generator.c              |  23 +++++
 13 files changed, 619 insertions(+), 10 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7ed2f5f..94621c6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -22,6 +22,7 @@ find_package(Eolian REQUIRED)
 find_package(Ecore REQUIRED)
 find_package(Evas REQUIRED)
 find_package(Efl REQUIRED)
+find_package(Efreet REQUIRED)
 find_package(Edje REQUIRED)
 find_package(Elementary 1.13.0 REQUIRED)
 find_package(Ffi REQUIRED)
diff --git a/src/bin/egui_gui/CMakeLists.txt b/src/bin/egui_gui/CMakeLists.txt
index 41f1e59..83035ad 100644
--- a/src/bin/egui_gui/CMakeLists.txt
+++ b/src/bin/egui_gui/CMakeLists.txt
@@ -58,6 +58,7 @@ add_executable(${TARGET}
    ${EGUI_BINARY_SRC}/main.c
    egui_layout.c
    egui_logic.c
+   settings.c
    props_helper.c
    objtree.c
    propview.c
@@ -84,6 +85,7 @@ target_link_libraries (${TARGET}
    ${EINA_LIBRARIES}
    ${ECORE_LIBRARIES}
    ${EFL_LIBRARIES}
+   ${EFREET_LIBRARIES}
    ${EVAS_LIBRARIES}
    ${EDJE_LIBRARIES}
    ${ELEMENTARY_LIBRARIES}
diff --git a/src/bin/egui_gui/editor.c b/src/bin/egui_gui/editor.c
index 4cca4d2..b0085b6 100644
--- a/src/bin/egui_gui/editor.c
+++ b/src/bin/egui_gui/editor.c
@@ -13,6 +13,7 @@
 #include "propview.h"
 #include "cbview.h"
 #include "key_bindings.h"
+#include "settings.h"
 
 #include "dnd.h"
 
@@ -2400,6 +2401,16 @@ _widget_add(Gui_Session *session, const Gui_Widget *wdg, 
void *data)
 
         Eo *win = eo_add(ELM_WIN_CLASS, parent_win, 
elm_obj_win_constructor(NULL, ELM_WIN_INLINED_IMAGE));
         if (!win) return EINA_FALSE;
+
+        /* Apply edit theme to widgets. */
+        Elm_Theme *theme = elm_theme_new();
+        const char *theme_name = 
gui_context_edit_theme_name_get(wdg_context_get(wdg));
+        char *str = malloc(strlen(theme_name) + 9);
+        sprintf(str, "%s:default", theme_name);
+        elm_theme_set(theme, str);
+        elm_object_theme_set(win, theme);
+        free(str);
+
         /* Add black background, so dragged elemets will be redrawn. */
         Eo *bg = eo_add(ELM_BG_CLASS, win,
               elm_obj_bg_color_set(0, 0, 0, 255),
@@ -2472,6 +2483,7 @@ _widget_add(Gui_Session *session, const Gui_Widget *wdg, 
void *data)
              eo_do(fr, eo_key_data_set("winwdg", wdg, NULL));
           }
         fr = main_wdg_info_frame_get(wi);
+        elm_object_theme_set(fr, theme);
         eo_do(iwin, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_DOWN, 
_mouse_down_main, wdg));
         eo_do(iwin, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_UP, 
_mouse_up_main, wdg));
 
@@ -2524,6 +2536,7 @@ _widget_add(Gui_Session *session, const Gui_Widget *wdg, 
void *data)
              eo_do(fr, efl_gfx_size_set(ow + dw, oh + dh));
              eo_do(iwin, efl_gfx_size_set(ow, oh));
           }
+        elm_theme_free(theme);
      }
 
    return EINA_TRUE;
@@ -4371,6 +4384,69 @@ _key_binding_wdg_del_cb(void *data EINA_UNUSED)
      }
 }
 
+Eina_Bool
+_theme_selector_hover_selected_cb(void *data EINA_UNUSED, Eo *obj, const 
Eo_Event_Description *desc EINA_UNUSED, void *event_info)
+{
+   const char *choosen_value;
+   eo_do(event_info, choosen_value = elm_wdg_item_part_text_get(NULL));
+   eo_do(obj, elm_obj_widget_part_text_set(NULL, choosen_value));
+
+   gui_context_edit_theme_name_set(_active_context_get(), choosen_value);
+
+   /* Apply theme to main widgets. */
+   Eid *wdg_id;
+   const Eina_List *list, *itr;
+   Elm_Theme *theme = elm_theme_new();
+   const Gui_Context *ctx = _active_context_get();
+   const Gui_Session *session = gui_context_editor_session_get(ctx);
+   const char *theme_name = gui_context_edit_theme_name_get(ctx);
+   char *str = malloc(strlen(theme_name) + 9);
+   sprintf(str, "%s:default", theme_name);
+   elm_theme_set(theme, str);
+   free(str);
+
+   list = gui_context_main_widgets_get(ctx);
+   EINA_LIST_FOREACH(list, itr, wdg_id)
+     {
+        Gui_Widget *wdg = wdg_get(wdg_id);
+        Eo *weo = session_eo_get(session, wdg);
+        elm_object_theme_set(weo, theme);
+        Main_Wdg_Info *wi = wdg_data_get(wdg, MAIN_WDG_INFO);
+        Eo *fr = main_wdg_info_frame_get(wi);
+        elm_object_theme_set(fr, theme);
+     }
+
+   elm_theme_free(theme);
+   return EO_CALLBACK_CONTINUE;
+}
+
+void
+_theme_hoversel_fill()
+{
+   Eina_Stringshare *theme_name;
+   const Eina_List *custom_themes_lst, *l;
+   eo_do(g->main_win->theme_selector_hoversel, elm_obj_hoversel_clear());
+
+   /* Add installed available themes into hoversel. */
+   Eina_List *lst = elm_theme_name_available_list_new();
+   EINA_LIST_FOREACH(lst, l, theme_name)
+     {
+        eo_do(g->main_win->theme_selector_hoversel, 
elm_obj_hoversel_item_add(theme_name, NULL, ELM_ICON_NONE, NULL, NULL));
+     }
+   elm_theme_name_available_list_free(lst);
+
+   /* Add custom themes into hoversel. */
+   custom_themes_lst = settings_custom_themes_list_get();
+   EINA_LIST_FOREACH(custom_themes_lst, l, theme_name)
+     {
+        eo_do(g->main_win->theme_selector_hoversel, 
elm_obj_hoversel_item_add(theme_name, NULL, ELM_ICON_NONE, NULL, NULL));
+     }
+
+   /* Set name of selected theme as header of hoversel. */
+   theme_name = gui_context_edit_theme_name_get(_active_context_get());
+   eo_do(g->main_win->theme_selector_hoversel, 
elm_obj_widget_part_text_set(NULL, theme_name));
+}
+
 void
 editor_init(GuiLogicCbs *_guilogic_cbs)
 {
@@ -4411,6 +4487,7 @@ editor_init(GuiLogicCbs *_guilogic_cbs)
    _guilogic_cbs->_editor_selected_wdg_get = _editor_wdg_selected_get;
    _guilogic_cbs->_project_close = _project_close;
    _guilogic_cbs->_project_new = _project_new;
+   _guilogic_cbs->_theme_hoversel_fill = _theme_hoversel_fill;
 
    objtree_init();
    proplayout_init();
diff --git a/src/bin/egui_gui/egui_layout.json 
b/src/bin/egui_gui/egui_layout.json
index 6e9eca4..a102a46 100644
--- a/src/bin/egui_gui/egui_layout.json
+++ b/src/bin/egui_gui/egui_layout.json
@@ -3,7 +3,8 @@
   "Settings":
   {
     "project":"egui_layout",
-    "start_points":["main_win"]
+    "start_points":["main_win"],
+    "edit_theme":"detourious-elm"
   },
   "Resources":
   {
@@ -36,7 +37,10 @@
       "_contentview_del_btn_clicked":"_contentview_del_btn_clicked",
       "_itemview_up_btn_clicked":"_itemview_up_btn_clicked",
       "_itemview_down_btn_clicked":"_itemview_down_btn_clicked",
-      "_settingsview_toolbar_clicked":"_settingsview_toolbar_clicked"
+      "_settingsview_toolbar_clicked":"_settingsview_toolbar_clicked",
+      "_custom_theme_add_button_clicked":"_custom_theme_add_button_clicked",
+      "_custom_theme_del_button_clicked":"_custom_theme_del_button_clicked",
+      "_theme_selector_hover_selected_cb":"_theme_selector_hover_selected_cb"
     },
     "Edjes":
     {
@@ -690,7 +694,7 @@
           "type":"regular",
           "public":true,
           "icon":"preferences-system",
-          "label":"Erigo Settings",
+          "label":"Themes",
           "callback":"_settingsview_toolbar_clicked"
         }
       }
@@ -722,7 +726,7 @@
     {
       "Desc":
       {
-        "parent":"project_settings_box",
+        "parent":"settings_table",
         "class":"Elm_Box",
         "public":true
       },
@@ -885,7 +889,7 @@
     {
       "Desc":
       {
-        "parent":"main_win",
+        "parent":"main_box",
         "class":"Elm_Toolbar",
         "public":true
       },
@@ -1002,7 +1006,7 @@
     {
       "Desc":
       {
-        "parent":"main_win",
+        "parent":"main_box",
         "class":"Elm_Box",
         "public":true
       },
@@ -1080,7 +1084,7 @@
         "Evas.Object.size_hint_align":[-1, -1],
         "Efl.Gfx.Base.visible":[true]
       },
-      "Contains":["fctr_scroll"]
+      "Contains":["theme_selector_box", "fctr_scroll"]
     },
     "fctr_scroll":
     {
@@ -3832,7 +3836,7 @@
         "Efl.Gfx.Base.visible":[true],
         "Evas.Object.size_hint_align":[-1, -1]
       },
-      "Contains":["project_settings_table", "settings_buttons_box"]
+      "Contains":["project_settings_table"]
     },
     "settings_table":
     {
@@ -3851,7 +3855,8 @@
       {
         "settings_toolbar":[0, 0, 1, 1],
         "project_settings_box":[0, 1, 1, 1],
-        "erigo_settings_box":[0, 1, 1, 1]
+        "erigo_settings_box":[0, 1, 1, 1],
+        "settings_buttons_box":[0, 2, 1, 1]
       }
     },
     "erigo_settings_box":
@@ -3867,6 +3872,150 @@
         "Evas.Object.size_hint_weight":[1, 1],
         "Efl.Gfx.Base.visible":[true],
         "Evas.Object.size_hint_align":[-1, -1]
+      },
+      "Contains":["erigo_settings_table"]
+    },
+    "erigo_settings_table":
+    {
+      "Desc":
+      {
+        "parent":"erigo_settings_box",
+        "class":"Elm_Table"
+      },
+      "Properties":
+      {
+        "Evas.Object.size_hint_weight":[1, 1],
+        "Efl.Gfx.Base.visible":[true],
+        "Efl.Gfx.Base.size":[70, 60],
+        "Evas.Object.size_hint_align":[-1, -1]
+      },
+      "Contains":
+      {
+        "custom_themes_genlist":[0, 1, 1, 1],
+        "custom_theme_buttons":[0, 0, 1, 1]
+      }
+    },
+    "custom_themes_genlist":
+    {
+      "Desc":
+      {
+        "parent":"erigo_settings_table",
+        "class":"Elm_Genlist",
+        "public":true
+      },
+      "Properties":
+      {
+        "Evas.Object.size_hint_weight":[1, 1],
+        "Efl.Gfx.Base.visible":[true],
+        "Efl.Gfx.Base.size":[70, 60],
+        "Evas.Object.size_hint_align":[-1, -1]
+      }
+    },
+    "cutom_theme_fs_bt":
+    {
+      "Desc":
+      {
+        "parent":"custom_theme_buttons",
+        "class":"Elm_Button",
+        "public":true
+      },
+      "Properties":
+      {
+        "Evas.Object.size_hint_weight":[1, 1],
+        "Efl.Gfx.Base.visible":[true],
+        "Efl.Gfx.Base.size":[73, 30],
+        "Elm_Widget.part_text":[null, "Add"]
+      },
+      "Callbacks":
+      {
+        "clicked":["Invoke", "_custom_theme_add_button_clicked", null]
+      }
+    },
+    "custom_theme_buttons":
+    {
+      "Desc":
+      {
+        "parent":"erigo_settings_table",
+        "class":"Elm_Box"
+      },
+      "Properties":
+      {
+        "Efl.Gfx.Base.visible":[true],
+        "Evas.Object.size_hint_weight":[1, 0],
+        "Elm_Box.horizontal":[true],
+        "Evas.Object.size_hint_align":[-1, 0]
+      },
+      "Contains":["cutom_theme_fs_bt", "custom_theme_del_bt"]
+    },
+    "custom_theme_del_bt":
+    {
+      "Desc":
+      {
+        "parent":"custom_theme_buttons",
+        "class":"Elm_Button"
+      },
+      "Properties":
+      {
+        "Evas.Object.size_hint_weight":[1, 1],
+        "Efl.Gfx.Base.visible":[true],
+        "Efl.Gfx.Base.size":[73, 30],
+        "Elm_Widget.part_text":[null, "Delete"]
+      },
+      "Callbacks":
+      {
+        "clicked":["Invoke", "_custom_theme_del_button_clicked", null]
+      }
+    },
+    "theme_selector_box":
+    {
+      "Desc":
+      {
+        "parent":"left_panel_box",
+        "class":"Elm_Box"
+      },
+      "Properties":
+      {
+        "Efl.Gfx.Base.visible":[true],
+        "Elm_Box.horizontal":[true],
+        "Evas.Object.size_hint_align":[-1, 0],
+        "Evas.Object.size_hint_weight":[1, 0]
+      },
+      "Contains":["theme_selector_label", "theme_selector_hoversel"]
+    },
+    "theme_selector_label":
+    {
+      "Desc":
+      {
+        "parent":"theme_selector_box",
+        "class":"Elm_Label"
+      },
+      "Properties":
+      {
+        "Evas.Object.size_hint_weight":[1, 1],
+        "Efl.Gfx.Base.visible":[true],
+        "Efl.Gfx.Base.size":[60, 30],
+        "Elm_Widget.part_text":[null, "Select Theme:"]
+      }
+    },
+    "theme_selector_hoversel":
+    {
+      "Desc":
+      {
+        "parent":"theme_selector_box",
+        "class":"Elm_Hoversel",
+        "public":true
+      },
+      "Properties":
+      {
+        "Evas.Object.size_hint_weight":[1, 1],
+        "Efl.Gfx.Base.visible":[true],
+        "Efl.Gfx.Base.size":[73, 30],
+        "Elm_Widget.part_text":[null, "default"],
+        "Elm_Hoversel.hover_parent":["hor_box"]
+      },
+      "Callbacks":
+      {
+        "selected":["Invoke", "_theme_selector_hover_selected_cb", null]
       }
     }
   }
diff --git a/src/bin/egui_gui/egui_logic.c b/src/bin/egui_gui/egui_logic.c
index e3ed433..6536a76 100644
--- a/src/bin/egui_gui/egui_logic.c
+++ b/src/bin/egui_gui/egui_logic.c
@@ -18,6 +18,7 @@
 #include "target.h"
 #include "dnd.h"
 #include "key_bindings.h"
+#include "settings.h"
 
 /*FIXME: remove this include */
 #include "objtree.h"
@@ -179,6 +180,7 @@ _on_fs_done(void *data, Evas_Object *obj EINA_UNUSED, void 
*event)
                    _menu_item_disabled_set(project_menu, ITEM_SAVE, 
EINA_FALSE);
                    _menu_item_disabled_set(project_menu, ITEM_SAVEAS, 
EINA_FALSE);
                    _menu_item_disabled_set(project_menu, ITEM_EXPORT, 
EINA_FALSE);
+                   _guilogic_cbs->_theme_hoversel_fill();
                 }
               break;
            }
@@ -205,6 +207,7 @@ _on_fs_done(void *data, Evas_Object *obj EINA_UNUSED, void 
*event)
                    _menu_item_disabled_set(project_menu, ITEM_SAVE, 
EINA_FALSE);
                    _menu_item_disabled_set(project_menu, ITEM_SAVEAS, 
EINA_FALSE);
                    _menu_item_disabled_set(project_menu, ITEM_EXPORT, 
EINA_FALSE);
+                   _guilogic_cbs->_theme_hoversel_fill();
                    const char *project_name = NULL;
                    eo_do(fs_win->fs_project_name_entry, project_name = 
elm_obj_widget_part_text_get(NULL));
                    if (!strlen(project_name)) project_name = "New Project";
@@ -927,6 +930,7 @@ egui_start()
    evas_object_size_hint_align_set(propsview_rect, EVAS_HINT_FILL, 
EVAS_HINT_FILL);
    elm_table_pack(g_main_wdgs->main_win->propsview_table, propsview_rect, 0, 
2, 1, 1);
 
+   settings_init();
    key_bindings_init();
    editor_init(guilogic_cbs_get());
 
@@ -1055,6 +1059,7 @@ egui_start()
 void
 egui_stop()
 {
+   settings_shutdown();
    editor_shutdown();
    key_bindings_shutdown();
 }
@@ -1103,6 +1108,7 @@ egui_project_open(char *path)
              _menu_item_disabled_set(project_menu, ITEM_SAVE, EINA_FALSE);
              _menu_item_disabled_set(project_menu, ITEM_SAVEAS, EINA_FALSE);
              _menu_item_disabled_set(project_menu, ITEM_EXPORT, EINA_FALSE);
+             _guilogic_cbs->_theme_hoversel_fill();
           }
      }
 }
diff --git a/src/bin/egui_gui/egui_logic_private.h 
b/src/bin/egui_gui/egui_logic_private.h
index 0f72498..5763719 100644
--- a/src/bin/egui_gui/egui_logic_private.h
+++ b/src/bin/egui_gui/egui_logic_private.h
@@ -15,6 +15,7 @@ typedef struct
 
    void (*_project_close)(const Gui_Context *ctx);
    Eina_Bool (*_project_new)(const char *filename);
+   void (*_theme_hoversel_fill)();
 } GuiLogicCbs;
 
 Eina_Bool
diff --git a/src/bin/egui_gui/settings.c b/src/bin/egui_gui/settings.c
new file mode 100644
index 0000000..36433b9
--- /dev/null
+++ b/src/bin/egui_gui/settings.c
@@ -0,0 +1,148 @@
+
+#include <Elementary.h>
+#include "egui_log.h"
+#include "settings.h"
+#include "eina_json.h"
+#include "gui_parser.h"
+
+static Eina_List *_custom_theme_list = NULL;
+
+static char _filename[PATH_MAX];
+
+void
+settings_init()
+{
+   sprintf(_filename, "%s/erigo", efreet_config_home_get());
+   if (!ecore_file_exists(_filename))
+     {
+        Eina_Bool success = ecore_file_mkdir(_filename);
+        if (!success)
+          {
+             EINA_LOG_ERR("Cannot create a config folder \"%s\"", _filename);
+             return;
+          }
+     }
+   sprintf(_filename, "%s/erigo/config.json", efreet_config_home_get());
+   settings_load();
+}
+
+void
+settings_shutdown()
+{
+   settings_custom_themes_list_clear();
+}
+
+const Eina_List*
+settings_custom_themes_list_get()
+{
+   return _custom_theme_list;
+}
+
+void
+settings_custom_themes_list_clear()
+{
+   char *theme_name;
+   EINA_LIST_FREE(_custom_theme_list, theme_name)
+     {
+        eina_stringshare_del(theme_name);
+     }
+}
+
+void
+settings_custom_theme_add(Eina_Stringshare *theme_name)
+{
+   if (theme_name)
+     {
+        _custom_theme_list = eina_list_append(_custom_theme_list, 
eina_stringshare_add(theme_name));
+     }
+}
+
+Eina_Bool
+settings_load()
+{
+   Eina_Bool ret = EINA_TRUE;
+   char *file_data = gui_parser_file_string_get(_filename);
+
+   Eina_Json_Context *ctx = eina_json_context_dom_new();
+   Eina_Json_Type type;
+   Eina_Bool err = eina_json_context_parse(ctx, file_data);
+   if (!err)
+     {
+        Eina_Json_Error e = -1;
+        e = eina_json_context_error_get(ctx);
+        unsigned int l, c;
+        l = eina_json_context_line_get(ctx);
+        c = eina_json_context_column_get(ctx);
+        ERR("json parsing error: %d, line: %d, column: %d", e, l, c);
+        ret = EINA_FALSE;
+        goto end;
+     }
+
+   Eina_Json_Value *jv, *tmp;
+
+   jv = eina_json_context_dom_tree_take(ctx);
+   type = eina_json_type_get(jv);
+   /* check, that first json value is object, t.e. { win : {...} }*/
+   if (type != EINA_JSON_TYPE_OBJECT)
+     {
+        ERR("Json Value is not Object");
+        ret = EINA_FALSE;
+        goto end;
+     }
+
+   tmp = EINA_JSON_OBJECT_VALUE_GET(jv, "Custom Themes");
+   if (tmp)
+     {
+        Eina_Iterator *it = NULL;
+        Eina_Json_Value *v;
+        const char *s;
+        it = eina_json_array_iterator_new(tmp);
+        EINA_ITERATOR_FOREACH(it, v)
+          {
+             s = eina_json_string_get(v);
+             settings_custom_theme_add(s);
+          }
+     }
+
+end:
+   if (jv) eina_json_value_free(jv);
+   if (ctx) eina_json_context_free(ctx);
+   return ret;
+}
+
+void
+settings_dump()
+{
+   FILE *fp_json = fopen(_filename, "w+");
+
+   if (!fp_json)
+     {
+        ERR("Can't create file: %s", _filename);
+        goto end;
+     }
+
+   Eina_Json_Value *arr = NULL;
+   arr = eina_json_array_new();
+
+   Eina_Json_Value *root_obj = eina_json_object_new();
+
+   arr = eina_json_array_new();
+   const Eina_List *themes_lst = settings_custom_themes_list_get(), *l;
+   const char *theme_name;
+   EINA_LIST_FOREACH(themes_lst, l, theme_name)
+     {
+        Eina_Json_Value *jval = eina_json_string_new(theme_name);
+        if (jval) eina_json_array_append(arr, jval);
+     }
+
+   eina_json_object_append(root_obj, "Custom Themes", arr);
+
+   char *json_str = NULL;
+   json_str = eina_json_format_string_get(root_obj, EINA_JSON_FORMAT_BASIC);
+   eina_json_value_free(root_obj);
+   fprintf(fp_json, "%s", json_str);
+
+end:
+   if (json_str) free(json_str);
+   if (fp_json) fclose(fp_json);
+}
diff --git a/src/bin/egui_gui/settings.h b/src/bin/egui_gui/settings.h
new file mode 100644
index 0000000..20c4621
--- /dev/null
+++ b/src/bin/egui_gui/settings.h
@@ -0,0 +1,26 @@
+
+#ifndef _SETTINGS_H
+#define _SETTINGS_H
+
+void
+settings_init();
+
+void
+settings_shutdown();
+
+Eina_Bool
+settings_load();
+
+void
+settings_dump();
+
+const Eina_List *
+settings_custom_themes_list_get();
+
+void
+settings_custom_theme_add(Eina_Stringshare *theme_name);
+
+void
+settings_custom_themes_list_clear();
+
+#endif
diff --git a/src/bin/egui_gui/settings_view.c b/src/bin/egui_gui/settings_view.c
index 85dc819..872931d 100644
--- a/src/bin/egui_gui/settings_view.c
+++ b/src/bin/egui_gui/settings_view.c
@@ -3,23 +3,32 @@
 #include "egui_log.h"
 #include "settings_view.h"
 #include "gui_widget.h"
+#include "settings.h"
 #include "egui_logic_private.h"
 
 #include "elm_widget.h"
 #include "elm_widget_container.h"
 #include "elm_interface_scrollable.h"
+#include "elm_interface_fileselector.h"
 
 static SettingsView_Type _toolbar_selected_type = SETTINGSVIEW_NOT_SELECTED;
 
 static Egui_Layout_Settings_Win_Widgets *g_settings_win = NULL;
+static Egui_Layout_Fs_Win_Widgets *fs_win = NULL;
 
 static Elm_Genlist_Item_Class *_start_pt_itc = NULL;
+static Elm_Genlist_Item_Class *_custom_th_itc = NULL;
 static Eina_List *_start_pts = NULL;
 
+static Eina_List *_custom_themes_tmp_list = NULL;
+
+GuiLogicCbs *_guilogic_cbs = NULL;
+
 void settings_win_set(Egui_Layout_Settings_Win_Widgets *settings_win)
 {
    if (g_settings_win) free(g_settings_win);
    g_settings_win = settings_win;
+   _guilogic_cbs = guilogic_cbs_get();
 }
 
 /* Enable "Apply" button." */
@@ -37,6 +46,7 @@ _settingsview_toolbar_clicked(void *data, Evas_Object *obj 
EINA_UNUSED, void *ev
    SettingsView_Type type = (int) (intptr_t) data;
    if (_toolbar_selected_type == type)
      return;
+
    _toolbar_selected_type = type;
 
    eo_do(g_settings_win->project_settings_box, 
efl_gfx_visible_set(EINA_FALSE));
@@ -102,7 +112,18 @@ _settings_apply_button_clicked(void *data EINA_UNUSED, Eo 
*obj EINA_UNUSED, cons
       gui_context_start_point_append(ctx, start_pt_id);
    _start_pts = NULL;
 
+   /* Save custom themes list. */
+   Eina_List *lst;
+   Eina_Stringshare *str;
+   settings_custom_themes_list_clear();
+   EINA_LIST_FOREACH(_custom_themes_tmp_list, lst, str)
+     {
+        settings_custom_theme_add(str);
+     }
+
+   settings_dump();
    eo_do(g_settings_win->settings_button_apply, 
elm_obj_widget_disabled_set(EINA_TRUE));
+   _guilogic_cbs->_theme_hoversel_fill();
    return EO_CALLBACK_CONTINUE;
 }
 
@@ -116,6 +137,68 @@ _settings_win_request_delete(void *data EINA_UNUSED, Eo 
*obj EINA_UNUSED, const
    return EO_CALLBACK_CONTINUE;
 }
 
+static void
+_on_fs_done(void *datai EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event)
+{
+   const char *path = event;
+
+   if (path)
+     {
+        Eina_Stringshare *theme_file = eina_stringshare_add(path);
+        eo_do(g_settings_win->custom_themes_genlist, 
elm_obj_genlist_item_append(_custom_th_itc,
+                                                                               
  (void *) theme_file, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL));
+
+        _custom_themes_tmp_list = eina_list_append(_custom_themes_tmp_list, 
eina_stringshare_add(path));
+        eo_do(g_settings_win->settings_button_apply, 
elm_obj_widget_disabled_set(EINA_FALSE));
+     }
+   eo_del(fs_win->fs_win);
+}
+
+static Eina_Bool
+_all_filter(const char *path EINA_UNUSED, Eina_Bool dir EINA_UNUSED,
+             void *data EINA_UNUSED)
+{
+   return EINA_TRUE;
+}
+
+static Eina_Bool
+_edje_filter(const char *path, Eina_Bool dir,
+             void *data EINA_UNUSED)
+{
+   if (dir) return EINA_TRUE;
+   if (eina_str_has_extension(path, ".edj"))
+     return EINA_TRUE;
+   return EINA_FALSE;
+}
+
+/* "Custom theme add" button "clicked" callback." */
+Eina_Bool
+_custom_theme_add_button_clicked(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, 
const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
+{
+   fs_win = egui_layout_fs_win_create(g_settings_win->settings_win);
+   evas_object_smart_callback_add(fs_win->fileselector, "done", _on_fs_done, 
NULL);
+   eo_do(fs_win->fileselector, 
elm_interface_fileselector_path_set(getenv("HOME")));
+   elm_fileselector_custom_filter_append(fs_win->fileselector, _edje_filter, 
NULL, "Edje Files");
+   elm_fileselector_custom_filter_append(fs_win->fileselector, _all_filter, 
NULL, "All Files");
+   return EO_CALLBACK_CONTINUE;
+}
+
+/* "Custom theme add" button "clicked" callback." */
+Eina_Bool
+_custom_theme_del_button_clicked(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, 
const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
+{
+   Eo *item = NULL;
+   eo_do(g_settings_win->custom_themes_genlist, item = 
elm_obj_genlist_selected_item_get());
+   if (item)
+     {
+        Eina_Stringshare *theme_name = elm_object_item_data_get(item);
+        _custom_themes_tmp_list = eina_list_remove(_custom_themes_tmp_list, 
theme_name);
+        eo_do(item, elm_wdg_item_del());
+        eo_do(g_settings_win->settings_button_apply, 
elm_obj_widget_disabled_set(EINA_FALSE));
+     }
+   return EO_CALLBACK_CONTINUE;
+}
+
 /* This callback is called in the end of creation of settings view window. */
 void
 settings_win_post_configure()
@@ -123,6 +206,22 @@ settings_win_post_configure()
    elm_object_item_data_set(g_settings_win->settings_toolbar_it0, (void *) 
(intptr_t) PROJECT_SETTINGSVIEW);
    elm_object_item_data_set(g_settings_win->settings_toolbar_it1, (void *) 
(intptr_t) ERIGO_SETTINGSVIEW);
    _settingsview_toolbar_clicked((void *) PROJECT_SETTINGSVIEW, NULL, NULL);
+
+   Eina_Stringshare *str;
+   EINA_LIST_FREE(_custom_themes_tmp_list, str)
+     {
+        eina_stringshare_del(str);
+     }
+
+   /* Add custom themest into genlist */
+   const Eina_List *custom_lst = settings_custom_themes_list_get(), *l;
+   const char *th;
+   EINA_LIST_FOREACH(custom_lst, l, th)
+     {
+        eo_do(g_settings_win->custom_themes_genlist, 
elm_obj_genlist_item_append(_custom_th_itc,
+                                                      (void *) 
eina_stringshare_add(th), NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL));
+        _custom_themes_tmp_list = eina_list_append(_custom_themes_tmp_list, 
eina_stringshare_add(th));
+     }
 }
 
 static Eina_Bool
@@ -146,6 +245,12 @@ _start_pt_text_get(void *data, Evas_Object *obj 
EINA_UNUSED, const char *part EI
    return wdg_name ? strdup(wdg_name) : NULL;
 }
 
+static char *
+_custom_th_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part 
EINA_UNUSED)
+{
+   return data ? strdup(data) : NULL;
+}
+
 static Evas_Object *
 _start_pt_content_get(void *data, Evas_Object *obj, const char *part)
 {
@@ -159,6 +264,13 @@ _start_pt_content_get(void *data, Evas_Object *obj, const 
char *part)
    return ck;
 }
 
+static void
+_custom_th_item_del(void *data, Evas_Object *obj EINA_UNUSED)
+{
+   Eina_Stringshare *theme_name = data;
+   eina_stringshare_del(theme_name);
+}
+
 void
 settingsview_init()
 {
@@ -169,6 +281,14 @@ settingsview_init()
         _start_pt_itc->func.content_get = _start_pt_content_get;
         _start_pt_itc->func.text_get = _start_pt_text_get;
      }
+   if (!_custom_th_itc)
+     {
+        _custom_th_itc = elm_genlist_item_class_new();
+        _custom_th_itc->item_style = "default";
+        _custom_th_itc->func.content_get = NULL;
+        _custom_th_itc->func.text_get = _custom_th_text_get;
+        _custom_th_itc->func.del = _custom_th_item_del;
+     }
 }
 
 void
@@ -176,4 +296,12 @@ settingsview_shutdown()
 {
    elm_genlist_item_class_free(_start_pt_itc);
    _start_pt_itc = NULL;
+   elm_genlist_item_class_free(_custom_th_itc);
+   _custom_th_itc = NULL;
+
+   Eina_Stringshare *str;
+   EINA_LIST_FREE(_custom_themes_tmp_list, str)
+     {
+        eina_stringshare_del(str);
+     }
 }
diff --git a/src/lib/gui_parser.c b/src/lib/gui_parser.c
index bf84391..09676ad 100644
--- a/src/lib/gui_parser.c
+++ b/src/lib/gui_parser.c
@@ -944,6 +944,22 @@ _settings_parse(Gui_Context *gui_ctx, Eina_Json_Value 
*res_js)
    return ret;
 }
 
+static Eina_Bool
+_erigo_settings_parse(Gui_Context *gui_ctx, Eina_Json_Value *res_js)
+{
+   Eina_Bool ret = EINA_FALSE;
+   /* Order is important. */
+
+   const char* val;
+   Eina_Json_Value *tmp = EINA_JSON_OBJECT_VALUE_GET(res_js, "edit_theme");
+   if (tmp)
+     {
+        val = eina_json_string_get(tmp);
+        gui_context_edit_theme_name_set(gui_ctx, val);
+     }
+   ret = EINA_TRUE;
+   return ret;
+}
 
 /* Register name and save JSON in list. */
 static Eina_Bool
@@ -1018,7 +1034,15 @@ _gui_parser_parse(Gui_Context *gui_ctx, char *_data)
      }
 
    _tmp = EINA_JSON_OBJECT_VALUE_GET(jv, "Settings");
-   parse_ret = _settings_parse(gui_ctx, _tmp);
+   if (_tmp)
+     {
+        parse_ret = _settings_parse(gui_ctx, _tmp);
+     }
+   _tmp = EINA_JSON_OBJECT_VALUE_GET(jv, "Erigo");
+   if (_tmp)
+     {
+        parse_ret = _erigo_settings_parse(gui_ctx, _tmp);
+     }
 
    /* Iterate over widgets again, in order to create widgets.  */
    _tmp = EINA_JSON_OBJECT_VALUE_GET(jv, "Widgets");
diff --git a/src/lib/gui_widget.c b/src/lib/gui_widget.c
index ff99239..1e77cd4 100644
--- a/src/lib/gui_widget.c
+++ b/src/lib/gui_widget.c
@@ -160,6 +160,8 @@ struct _Gui_Context
 
    Eina_List *current_memento;
    Eina_List *memento_list;
+
+   char *edit_theme_name;
 };
 
 struct _Gui_Session
@@ -336,6 +338,7 @@ gui_context_new()
    ctx->eids = eina_hash_int32_new(_eids_free_func);
 #endif
    ctx->eids_by_name = eina_hash_string_superfast_new(NULL);
+   ctx->edit_theme_name = strdup("default");
    ctx->counter = 1;
    return ctx;
 }
@@ -576,6 +579,8 @@ gui_context_del(Gui_Context *ctx)
    eina_stringshare_del(ctx->export_c_filename);
    eina_stringshare_del(ctx->export_h_filename);
 
+   if (ctx->edit_theme_name) free(ctx->edit_theme_name);
+
    context_array[ctx->id] = NULL;
    free(ctx);
    return EINA_TRUE;
@@ -648,6 +653,19 @@ gui_context_simulate_session_list_get(const Gui_Context 
*ctx)
    return ctx->simulate_sessions;
 }
 
+void
+gui_context_edit_theme_name_set(Gui_Context *ctx, const char *theme_name)
+{
+   if (ctx->edit_theme_name) free(ctx->edit_theme_name);
+   ctx->edit_theme_name = strdup(theme_name);
+}
+
+const char *
+gui_context_edit_theme_name_get(const Gui_Context *ctx)
+{
+   return ctx->edit_theme_name;
+}
+
 Eid_Data *
 _eid_data_get(Eid *eid)
 {
diff --git a/src/lib/gui_widget.h b/src/lib/gui_widget.h
index 5af8349..10efb58 100644
--- a/src/lib/gui_widget.h
+++ b/src/lib/gui_widget.h
@@ -963,4 +963,10 @@ gui_context_memento_discard(Gui_Context *ctx);
 void
 gui_context_memento_discard_all(Gui_Context *ctx);
 
+void
+gui_context_edit_theme_name_set(Gui_Context *ctx, const char *theme_name);
+
+const char *
+gui_context_edit_theme_name_get(const Gui_Context *ctx);
+
 #endif
diff --git a/src/lib/json_generator.c b/src/lib/json_generator.c
index f62e0a0..f560632 100644
--- a/src/lib/json_generator.c
+++ b/src/lib/json_generator.c
@@ -205,6 +205,27 @@ _settings_json_generate(const Gui_Context *ctx)
         eina_json_array_append(pts_js, eina_json_string_new(wdg_name));
      }
    if (pts_js) eina_json_object_append(obj, "start_points", pts_js);
+
+   return obj;
+}
+
+/* Create JSON Object/string for Erigo settings.
+ * Settings which are specific only for Erigo, but per project.
+ * T.e. edit theme */
+static Eina_Json_Value *
+_erigo_settings_json_generate(const Gui_Context *ctx)
+{
+   Eina_Json_Value *obj = NULL;
+
+   const char *p = NULL;
+
+   p = gui_context_edit_theme_name_get(ctx);
+   if (strcmp(p, "default"))
+     {
+        if (!obj)
+          obj = eina_json_object_new();
+        eina_json_object_append(obj, "edit_theme", eina_json_string_new(p));
+     }
    return obj;
 }
 
@@ -602,12 +623,14 @@ static Eina_Json_Value *
 _context_json_generate(const Gui_Context *ctx)
 {
    Eina_Json_Value *settings_json = _settings_json_generate(ctx);
+   Eina_Json_Value *erigo_settings_json = _erigo_settings_json_generate(ctx);
    Eina_Json_Value *resources_json = _resources_json_generate(ctx);
    Eina_Json_Value *widgets_json = _widgets_json_generate(ctx);
 
    Eina_Json_Value *root_obj = eina_json_object_new();
    eina_json_object_append(root_obj, "JSON_Version", 
eina_json_string_new(EGUI_JSON_VERSION));
    if (settings_json) eina_json_object_append(root_obj, "Settings", 
settings_json);
+   if (erigo_settings_json) eina_json_object_append(root_obj, "Erigo", 
erigo_settings_json);
    if (resources_json) eina_json_object_append(root_obj, "Resources", 
resources_json);
    if (widgets_json) eina_json_object_append(root_obj, "Widgets", 
widgets_json);
 

-- 


Reply via email to