extra: put all ui elements in a struct so they are a bit sorted

This commit is contained in:
Marcel Hollerbach 2017-01-09 16:44:44 +01:00
parent 4b28a5d844
commit ea26eb5d5e
1 changed files with 83 additions and 77 deletions

View File

@ -23,24 +23,31 @@ typedef struct {
Evas_Object *author;
Evas_Object *description;
Evas_Object *progress;
Evas_Object *install;
} Theme_Ui;
typedef struct {
Theme_Ui theme_ui;
Evas_Object *sync_popup;
Evas_Object *ask_popup;
Evas_Object *win;
Evas_Object *theme_list;
} Ui;
static Elm_Genlist_Item_Class _theme_class;
static Evas_Object *_win, *_popup, *_theme_list, *_install_button;
static Extra_Progress _sync_progress, _install_progress;
static Evas_Object *_theme_list;
static Extra_Theme *_selected_theme;
static Theme_Ui ui;
static Ui ui;
static void
_extra_win_progress_popup_cb(double progress)
{
Evas_Object *p;
p = elm_object_content_get(_popup);
p = elm_object_content_get(ui.sync_popup);
if (elm_progressbar_pulse_get(p))
{
elm_progressbar_pulse(p, EINA_FALSE);
@ -56,22 +63,22 @@ _extra_win_progress_popup_show(const char *title)
{
Evas_Object *progress;
_popup = elm_popup_add(_win);
progress = elm_progressbar_add(_popup);
ui.sync_popup = elm_popup_add(ui.win);
progress = elm_progressbar_add(ui.sync_popup);
elm_progressbar_pulse_set(progress, EINA_TRUE);
elm_progressbar_pulse(progress, EINA_TRUE);
evas_object_show(progress);
elm_object_part_text_set(_popup, "title,text", title);
elm_object_content_set(_popup, progress);
evas_object_show(_popup);
elm_object_part_text_set(ui.sync_popup, "title,text", title);
elm_object_content_set(ui.sync_popup, progress);
evas_object_show(ui.sync_popup);
}
static void
_extra_win_progress_popup_del(void)
{
evas_object_del(_popup);
_popup = NULL;
evas_object_del(ui.sync_popup);
ui.sync_popup = NULL;
}
static void
@ -82,8 +89,8 @@ _extra_win_ask_yes(void *data,
Extra_Theme *theme = data;
extra_theme_use(theme);
evas_object_del(_popup);
_popup = NULL;
evas_object_del(ui.ask_popup);
ui.ask_popup = NULL;
}
static void
@ -91,8 +98,8 @@ _extra_win_ask_no(void *data EINA_UNUSED,
Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
evas_object_del(_popup);
_popup = NULL;
evas_object_del(ui.ask_popup);
ui.ask_popup = NULL;
}
static void
@ -100,30 +107,30 @@ _extra_win_ask_for_default(Extra_Theme *theme)
{
Evas_Object *o, *table;
_popup = elm_popup_add(_win);
ui.ask_popup = elm_popup_add(ui.win);
table = elm_table_add(_popup);
elm_object_content_set(_popup, table);
table = elm_table_add(ui.ask_popup);
elm_object_content_set(ui.ask_popup, table);
evas_object_show(table);
o = elm_label_add(_popup);
o = elm_label_add(ui.ask_popup);
elm_object_text_set(o, "Set the theme as default ?");
elm_table_pack(table, o, 0, 0, 2, 1);
evas_object_show(o);
o = elm_button_add(_popup);
o = elm_button_add(ui.ask_popup);
elm_object_text_set(o, "Yes");
elm_table_pack(table, o, 0, 1, 1, 1);
evas_object_smart_callback_add(o, "clicked", _extra_win_ask_yes, theme);
evas_object_show(o);
o = elm_button_add(_popup);
o = elm_button_add(ui.ask_popup);
elm_object_text_set(o, "No");
elm_table_pack(table, o, 1, 1, 1, 1);
evas_object_smart_callback_add(o, "clicked", _extra_win_ask_no, NULL);
evas_object_show(o);
evas_object_show(_popup);
evas_object_show(ui.ask_popup);
}
static void
extra_win_show(Extra_Theme *theme)
@ -134,16 +141,16 @@ extra_win_show(Extra_Theme *theme)
if (!theme) return;
snprintf(title, sizeof(title), "<title>%s</title>", theme->name);
elm_object_text_set(ui.title, title);
elm_object_text_set(ui.theme_ui.title, title);
snprintf(author, sizeof(author), "<link>%s</link>", theme->author);
elm_object_text_set(ui.author, author);
elm_object_text_set(ui.theme_ui.author, author);
elm_object_text_set(ui.description, theme->description);
elm_object_text_set(ui.theme_ui.description, theme->description);
elm_progressbar_value_set(ui.progress, 0.0);
elm_image_file_set(ui.screenshot, extra_theme_preview_url_get(_selected_theme), NULL);
evas_object_show(ui.progress);
elm_progressbar_value_set(ui.theme_ui.progress, 0.0);
elm_image_file_set(ui.theme_ui.screenshot, extra_theme_preview_url_get(_selected_theme), NULL);
evas_object_show(ui.theme_ui.progress);
}
static void
@ -190,14 +197,14 @@ _theme_select(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UN
{
extra_win_show(data);
elm_object_disabled_set(_install_button, extra_theme_installed(_selected_theme));
elm_object_disabled_set(ui.theme_ui.install, extra_theme_installed(_selected_theme));
}
static void
_extra_win_theme_add(Extra_Theme *theme)
{
elm_genlist_item_append(_theme_list, &_theme_class, theme, NULL,
elm_genlist_item_append(ui.theme_list, &_theme_class, theme, NULL,
ELM_GENLIST_ITEM_NONE, _theme_select, theme);
}
@ -218,13 +225,13 @@ _extra_win_sync_done_cb()
_extra_win_progress_popup_del();
elm_genlist_clear(_theme_list);
elm_genlist_clear(ui.theme_list);
_extra_win_theme_list_refresh();
first = eina_list_data_get(extra_themes_list());
_theme_select(first, NULL, NULL);
elm_genlist_item_selected_set(
elm_genlist_first_item_get(_theme_list), EINA_TRUE);
elm_genlist_first_item_get(ui.theme_list), EINA_TRUE);
}
static void
@ -243,7 +250,7 @@ _extra_win_download_done_cb()
{
_extra_win_progress_popup_del();
elm_genlist_clear(_theme_list);
elm_genlist_clear(ui.theme_list);
_extra_win_theme_list_refresh();
_theme_select(_selected_theme, NULL, NULL);
@ -276,33 +283,33 @@ _download_progress_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void
Elm_Photocam_Progress *prog = event_info;
if (prog->total > 0)
elm_progressbar_value_set(ui.progress, prog->now / prog->total);
elm_progressbar_value_set(ui.theme_ui.progress, prog->now / prog->total);
}
static void
_download_done(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
evas_object_hide(ui.progress);
evas_object_hide(ui.theme_ui.progress);
}
static Evas_Object *
extra_win_setup(void)
{
Evas_Object *win, *list, *pane, *box, *frame, *table, *install, *icon, *scroller;
Evas_Object *list, *pane, *box, *frame, *table, *install, *icon, *scroller;
win = elm_win_util_standard_add("main", "Extra!");
if (!win) return NULL;
ui.win = elm_win_util_standard_add("main", "Extra!");
if (!ui.win) return NULL;
elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
evas_object_smart_callback_add(win, "delete,request", _extra_win_del, NULL);
elm_win_focus_highlight_enabled_set(ui.win, EINA_TRUE);
evas_object_smart_callback_add(ui.win, "delete,request", _extra_win_del, NULL);
pane = elm_panes_add(win);
pane = elm_panes_add(ui.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(ui.win, pane);
box = elm_box_add(pane);
evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
@ -315,7 +322,7 @@ extra_win_setup(void)
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;
ui.theme_list = list;
frame = elm_frame_add(pane);
elm_object_text_set(frame, "Theme info");
@ -336,12 +343,12 @@ extra_win_setup(void)
elm_object_content_set(scroller, table);
evas_object_show(table);
ui.title = elm_label_add(table);
elm_entry_editable_set(ui.title, EINA_FALSE);
evas_object_size_hint_weight_set(ui.title, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(ui.title, 0.0, EVAS_HINT_FILL);
elm_table_pack(table, ui.title, 0, 0, 3, 1);
evas_object_show(ui.title);
ui.theme_ui.title = elm_label_add(table);
elm_entry_editable_set(ui.theme_ui.title, EINA_FALSE);
evas_object_size_hint_weight_set(ui.theme_ui.title, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(ui.theme_ui.title, 0.0, EVAS_HINT_FILL);
elm_table_pack(table, ui.theme_ui.title, 0, 0, 3, 1);
evas_object_show(ui.theme_ui.title);
install = elm_button_add(table);
icon = elm_icon_add(table);
@ -356,45 +363,44 @@ extra_win_setup(void)
evas_object_show(install);
evas_object_smart_callback_add(install, "clicked", _extra_win_install_click_cb, NULL);
_install_button = install;
ui.theme_ui.install = install;
ui.screenshot = elm_image_add(table);
evas_object_smart_callback_add(ui.screenshot, "download,progress", _download_progress_cb, NULL);
evas_object_smart_callback_add(ui.screenshot, "download,done", _download_done, NULL);
evas_object_size_hint_weight_set(ui.screenshot, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(ui.screenshot, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_table_pack(table, ui.screenshot, 0, 1, 4, 2);
evas_object_show(ui.screenshot);
ui.theme_ui.screenshot = elm_image_add(table);
evas_object_smart_callback_add(ui.theme_ui.screenshot, "download,progress", _download_progress_cb, NULL);
evas_object_smart_callback_add(ui.theme_ui.screenshot, "download,done", _download_done, NULL);
evas_object_size_hint_weight_set(ui.theme_ui.screenshot, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(ui.theme_ui.screenshot, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_table_pack(table, ui.theme_ui.screenshot, 0, 1, 4, 2);
evas_object_show(ui.theme_ui.screenshot);
ui.progress = elm_progressbar_add(table);
evas_object_size_hint_weight_set(ui.progress, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(ui.progress, EVAS_HINT_FILL, 0.0);
elm_table_pack(table, ui.progress, 0, 2, 4, 1);
ui.theme_ui.progress = elm_progressbar_add(table);
evas_object_size_hint_weight_set(ui.theme_ui.progress, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(ui.theme_ui.progress, EVAS_HINT_FILL, 0.0);
elm_table_pack(table, ui.theme_ui.progress, 0, 2, 4, 1);
ui.author = elm_entry_add(table);
elm_entry_editable_set(ui.author, EINA_FALSE);
evas_object_size_hint_weight_set(ui.author, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(ui.author, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_table_pack(table, ui.author, 0, 3, 4, 1);
evas_object_show(ui.author);
ui.theme_ui.author = elm_entry_add(table);
elm_entry_editable_set(ui.theme_ui.author, EINA_FALSE);
evas_object_size_hint_weight_set(ui.theme_ui.author, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(ui.theme_ui.author, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_table_pack(table, ui.theme_ui.author, 0, 3, 4, 1);
evas_object_show(ui.theme_ui.author);
ui.description = elm_entry_add(table);
elm_entry_editable_set(ui.description, EINA_FALSE);
evas_object_size_hint_weight_set(ui.description, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(ui.description, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_table_pack(table, ui.description, 0, 4, 4, 1);
evas_object_show(ui.description);
ui.theme_ui.description = elm_entry_add(table);
elm_entry_editable_set(ui.theme_ui.description, EINA_FALSE);
evas_object_size_hint_weight_set(ui.theme_ui.description, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(ui.theme_ui.description, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_table_pack(table, ui.theme_ui.description, 0, 4, 4, 1);
evas_object_show(ui.theme_ui.description);
evas_object_resize(win, 420 * elm_config_scale_get(),
evas_object_resize(ui.win, 420 * elm_config_scale_get(),
280 * elm_config_scale_get());
_theme_class.item_style = "default";
_theme_class.func.text_get = _theme_text_get;
_theme_class.func.content_get = _theme_content_get;
evas_object_show(win);
evas_object_show(ui.win);
_win = win;
return win;
return ui.win;
}
static const Ecore_Getopt optdesc = {