ui: Actually list themes after we sync
Grabbing theme list from server - no cache yet
This commit is contained in:
parent
1af204ab37
commit
c73cfc2106
|
@ -17,17 +17,92 @@
|
|||
|
||||
#define COPYRIGHT "Copyright © 2016 Andy Williams <andy@andywilliams.me> and various contributors (see AUTHORS)."
|
||||
|
||||
static Elm_Genlist_Item_Class _theme_class;
|
||||
static Extra_Progress _sync_progress;
|
||||
static Evas_Object *_sync_popup, *_theme_list;
|
||||
|
||||
static void
|
||||
_extra_win_del(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
||||
{
|
||||
elm_exit();
|
||||
}
|
||||
|
||||
static char *
|
||||
_theme_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *source EINA_UNUSED)
|
||||
{
|
||||
Extra_Theme *theme;
|
||||
|
||||
theme = (Extra_Theme *)data;
|
||||
|
||||
return strdup(theme->name);
|
||||
}
|
||||
|
||||
static void
|
||||
_theme_select(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
||||
{
|
||||
Extra_Theme *theme;
|
||||
|
||||
theme = (Extra_Theme *)data;
|
||||
|
||||
printf("SELECTED %s\n", theme->id);
|
||||
}
|
||||
|
||||
static void
|
||||
_extra_win_theme_add(Extra_Theme *theme)
|
||||
{
|
||||
elm_genlist_item_append(_theme_list, &_theme_class, theme, NULL,
|
||||
ELM_GENLIST_ITEM_NONE, _theme_select, theme);
|
||||
}
|
||||
|
||||
static void
|
||||
_extra_win_theme_list_refresh()
|
||||
{
|
||||
Extra_Theme *theme;
|
||||
Eina_List *item;
|
||||
|
||||
EINA_LIST_FOREACH(extra_themes_list(), item, theme)
|
||||
_extra_win_theme_add(theme);
|
||||
}
|
||||
|
||||
static void
|
||||
_extra_win_sync_done_cb()
|
||||
{
|
||||
ecore_thread_main_loop_begin();
|
||||
|
||||
elm_genlist_clear(_theme_list);
|
||||
|
||||
evas_object_hide(_sync_popup);
|
||||
_sync_popup = NULL;
|
||||
_extra_win_theme_list_refresh();
|
||||
|
||||
ecore_thread_main_loop_end();
|
||||
}
|
||||
|
||||
static void
|
||||
extra_win_sync(Evas_Object *win)
|
||||
{
|
||||
Evas_Object *progress;
|
||||
|
||||
// _sync_progress.progress_cb = _extra_win_sync_progress_cb;
|
||||
_sync_progress.done_cb = _extra_win_sync_done_cb;
|
||||
|
||||
_sync_popup = elm_popup_add(win);
|
||||
progress = elm_progressbar_add(win);
|
||||
elm_progressbar_pulse_set(progress, EINA_TRUE);
|
||||
elm_progressbar_pulse(progress, EINA_TRUE);
|
||||
evas_object_show(progress);
|
||||
|
||||
elm_object_part_text_set(_sync_popup, "title,text", "Downloading themes");
|
||||
elm_object_content_set(_sync_popup, progress);
|
||||
evas_object_show(_sync_popup);
|
||||
|
||||
extra_sync(&_sync_progress);
|
||||
}
|
||||
|
||||
static Evas_Object *
|
||||
extra_win_setup(void)
|
||||
{
|
||||
Evas_Object *win;
|
||||
Evas_Object *label;
|
||||
Evas_Object *win, *list, *pane, *box, *frame;
|
||||
|
||||
win = elm_win_util_standard_add("main", "Extra!");
|
||||
if (!win) return NULL;
|
||||
|
@ -35,14 +110,39 @@ extra_win_setup(void)
|
|||
elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
|
||||
evas_object_smart_callback_add(win, "delete,request", _extra_win_del, NULL);
|
||||
|
||||
label = elm_label_add(win);
|
||||
elm_object_text_set(label, "Available Themes:");
|
||||
evas_object_size_hint_weight_set(label, 0.0, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(label, 0.0, EVAS_HINT_FILL);
|
||||
evas_object_show(label);
|
||||
pane = elm_panes_add(win);
|
||||
elm_panes_horizontal_set(pane, EINA_FALSE);
|
||||
elm_panes_content_left_size_set(pane, 0.33);
|
||||
evas_object_size_hint_weight_set(pane, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(pane, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
evas_object_show(pane);
|
||||
elm_win_resize_object_add(win, pane);
|
||||
|
||||
elm_win_resize_object_add(win, label);
|
||||
box = elm_box_add(pane);
|
||||
evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
evas_object_show(box);
|
||||
elm_object_part_content_set(pane, "left", box);
|
||||
|
||||
list = elm_genlist_add(box);
|
||||
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);
|
||||
evas_object_show(list);
|
||||
elm_box_pack_end(box, list);
|
||||
_theme_list = list;
|
||||
|
||||
frame = elm_frame_add(pane);
|
||||
elm_object_text_set(frame, "Description");
|
||||
evas_object_size_hint_weight_set(frame, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(frame, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
evas_object_show(frame);
|
||||
elm_object_part_content_set(pane, "right", frame);
|
||||
|
||||
evas_object_resize(win, 360 * elm_config_scale_get(),
|
||||
240 * elm_config_scale_get());
|
||||
|
||||
_theme_class.item_style = "default";
|
||||
_theme_class.func.text_get = _theme_text_get;
|
||||
evas_object_show(win);
|
||||
|
||||
return win;
|
||||
|
@ -105,7 +205,7 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
|
|||
if (!(win = extra_win_setup()))
|
||||
goto end;
|
||||
|
||||
extra_library_call();
|
||||
extra_win_sync(win);
|
||||
|
||||
elm_run();
|
||||
|
||||
|
|
|
@ -9,6 +9,23 @@
|
|||
static int _extra_init = 0;
|
||||
int _extra_lib_log_dom = -1;
|
||||
|
||||
Eina_List *_theme_list;
|
||||
|
||||
static void
|
||||
_extra_theme_add(const char *id, const char *name, const char *author,
|
||||
int version)
|
||||
{
|
||||
Extra_Theme *theme;
|
||||
|
||||
theme = malloc(sizeof(*theme));
|
||||
theme->id = strdup(id);
|
||||
theme->name = strdup(name);
|
||||
theme->author = strdup(author);
|
||||
theme->version = version;
|
||||
|
||||
_theme_list = eina_list_append(_theme_list, theme);
|
||||
}
|
||||
|
||||
EAPI int
|
||||
extra_init(void)
|
||||
{
|
||||
|
@ -57,35 +74,40 @@ extra_shutdown(void)
|
|||
return _extra_init;
|
||||
}
|
||||
|
||||
static void
|
||||
_url_data_line_cb(char *buf, int len)
|
||||
{
|
||||
buf[len] = '\0';
|
||||
if (buf[0] == '"')
|
||||
{
|
||||
buf[len-1] = '\0';
|
||||
_extra_theme_add(buf+1, buf+1, "", 0);
|
||||
}
|
||||
else
|
||||
_extra_theme_add(buf, buf, "", 0);
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_url_data_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void *event_info)
|
||||
{
|
||||
Ecore_Con_Event_Url_Data *url_data = event_info;
|
||||
char buf[1024];
|
||||
int i, p = 0;
|
||||
int i, start = 0, end = 0;
|
||||
|
||||
for (i = 0; i < url_data->size; i++)
|
||||
{
|
||||
if (url_data->data[i] == '\r' || url_data->data[i] == '\n')
|
||||
{
|
||||
if (p == 0)
|
||||
if (end == start)
|
||||
continue;
|
||||
|
||||
buf[p] = '\0';
|
||||
if (buf[0] == '"')
|
||||
{
|
||||
buf[p-1] = '\0';
|
||||
printf("THEME %s\n", buf+1);
|
||||
}
|
||||
else
|
||||
printf("THEME %s\n", buf);
|
||||
|
||||
p = 0;
|
||||
_url_data_line_cb(buf + start, end - start);
|
||||
start = end;
|
||||
}
|
||||
else
|
||||
{
|
||||
buf[p] = url_data->data[i];
|
||||
p++;
|
||||
buf[end] = url_data->data[i];
|
||||
end++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,22 +117,33 @@ _url_data_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void *event_info)
|
|||
static Eina_Bool
|
||||
_url_complete_cb(void *data, int type EINA_UNUSED, void *event_info EINA_UNUSED)
|
||||
{
|
||||
Ecore_Con_Url *url = data;
|
||||
Extra_Progress *progress = data;;
|
||||
|
||||
ecore_con_url_free(url);
|
||||
if (progress->done_cb)
|
||||
progress->done_cb();
|
||||
|
||||
ecore_con_url_free(progress->url);
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
EAPI void
|
||||
extra_library_call(void)
|
||||
extra_sync(Extra_Progress *progress)
|
||||
{
|
||||
Ecore_Con_Url *url;
|
||||
|
||||
url = ecore_con_url_custom_new("http://" HOSTNAME "/v1/themes/", "GET");
|
||||
ecore_con_url_additional_header_add(url, "Accept", "text/csv");
|
||||
|
||||
progress->url = url;
|
||||
ecore_event_handler_add(ECORE_CON_EVENT_URL_DATA, _url_data_cb, NULL);
|
||||
ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, _url_complete_cb, url);
|
||||
ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, _url_complete_cb, progress);
|
||||
|
||||
ecore_con_url_get(url);
|
||||
}
|
||||
|
||||
EAPI Eina_List *
|
||||
extra_themes_list(void)
|
||||
{
|
||||
return _theme_list;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,22 @@ extern "C" {
|
|||
* @brief These routines are used for extra library interaction.
|
||||
*/
|
||||
|
||||
typedef struct _Extra_Theme
|
||||
{
|
||||
const char *id;
|
||||
const char *name;
|
||||
const char *author;
|
||||
int version;
|
||||
} Extra_Theme;
|
||||
|
||||
typedef struct _Extra_Progress
|
||||
{
|
||||
Ecore_Con_Url *url;
|
||||
|
||||
void (*progress_cb)(double progress);
|
||||
void (*done_cb)(void);
|
||||
} Extra_Progress;
|
||||
|
||||
/**
|
||||
* @brief Init / shutdown functions.
|
||||
* @defgroup Init Init / Shutdown
|
||||
|
@ -90,15 +106,32 @@ EAPI int extra_shutdown(void);
|
|||
|
||||
/**
|
||||
* @brief Main group API that wont do anything
|
||||
* @defgroup Main Main
|
||||
* @defgroup Storage Storage
|
||||
*
|
||||
* @{
|
||||
*
|
||||
* @brief A function that doesn't do any good nor any bad
|
||||
* @brief Sync the library with the extra_server to get the theme list.
|
||||
*
|
||||
* @ingroup Main
|
||||
* @ingroup Storage
|
||||
*/
|
||||
EAPI void extra_library_call(void);
|
||||
EAPI void extra_sync(Extra_Progress *progress);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Theme management functions
|
||||
* @defgroup Themes Themes
|
||||
*
|
||||
* @{
|
||||
* @brief Get a list of all the themes that are available.
|
||||
*
|
||||
* @see extra_sync
|
||||
*
|
||||
* @ingroup Themes
|
||||
*/
|
||||
EAPI Eina_List *extra_themes_list(void);
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
|
|
@ -20,9 +20,12 @@ static const struct {
|
|||
|
||||
START_TEST(extra_initialization)
|
||||
{
|
||||
Eina_List *themes;
|
||||
fail_if(extra_init() != 1);
|
||||
|
||||
extra_library_call();
|
||||
extra_sync(NULL);
|
||||
themes = extra_themes_list();
|
||||
fail_if(eina_list_count(themes) == 0);
|
||||
|
||||
fail_if(extra_shutdown() != 0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue