extra: change the theme selector from a list with names to a grid

the new ui brings a grid selection so the user can see the screenshot of
each theme when scrolling through it. This also refactors the progress
popup creation into its own file.
This commit is contained in:
Marcel Hollerbach 2017-01-14 14:04:54 +01:00
parent 285cb4864a
commit bec53e0c59
5 changed files with 463 additions and 442 deletions

View File

@ -9,11 +9,13 @@ AM_CPPFLAGS = -DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \
-I$(top_srcdir)/src/lib/ \
@EFL_CFLAGS@
extra_SOURCES = extra_main.c
extra_SOURCES = extra_main.c \
extra_theme_selector.c \
extra_util.c
extra_LDADD = @EFL_LIBS@ $(top_builddir)/src/lib/libextra.la
localedir = $(datadir)/locale
DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
EXTRA_DIST = extra_private.h
EXTRA_DIST = extra_private.h

View File

@ -12,230 +12,11 @@
#include "gettext.h"
#include "extra.h"
#include "extra_private.h"
#define COPYRIGHT "Copyright © 2016 Andy Williams <andy@andywilliams.me> and various contributors (see AUTHORS)."
typedef struct {
Evas_Object *title;
Evas_Object *screenshot;
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;
Evas_Object *fullscreen_image;
} Ui;
static Elm_Genlist_Item_Class _theme_class;
static Extra_Progress _sync_progress, _install_progress, _preview_progress;
static Extra_Theme *_selected_theme;
static Ui ui;
static void
_delete_inwin(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, Evas *e EINA_UNUSED, void *event_info)
{
Evas_Event_Mouse_Up *ev = event_info;
if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
evas_object_del(ui.fullscreen_image);
ui.fullscreen_image = NULL;
ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
}
static void
_extra_win_fullscreen_preview(Extra_Theme *theme)
{
Evas_Object *win, *image;
char *path;
if (ui.fullscreen_image) return;
path = extra_theme_preview_get(theme);
if (!path) return;
ui.fullscreen_image = win = elm_win_util_standard_add("Extra - Screenshot", "Extra - Screenshot");
elm_win_fullscreen_set(win, EINA_TRUE);
evas_object_size_hint_weight_set(win, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(win, EVAS_HINT_FILL, EVAS_HINT_FILL);
image = elm_image_add(win);
evas_object_size_hint_weight_set(image, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(image, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_image_file_set(image, path, NULL);
evas_object_show(image);
elm_object_content_set(win, image);
evas_object_show(win);
evas_object_event_callback_add(ui.fullscreen_image, EVAS_CALLBACK_MOUSE_UP, _delete_inwin, NULL);
}
static void
_extra_win_progress_popup_cb(double progress)
{
Evas_Object *p;
p = elm_object_content_get(ui.sync_popup);
if (elm_progressbar_pulse_get(p))
{
elm_progressbar_pulse(p, EINA_FALSE);
elm_progressbar_pulse_set(p, EINA_FALSE);
}
elm_progressbar_value_set(p, progress);
}
static void
_extra_win_progress_popup_show(const char *title)
{
Evas_Object *progress;
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(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(ui.sync_popup);
ui.sync_popup = NULL;
}
static void
_extra_win_ask_yes(void *data,
Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Extra_Theme *theme = data;
extra_theme_use(theme);
evas_object_del(ui.ask_popup);
ui.ask_popup = NULL;
}
static void
_extra_win_ask_no(void *data EINA_UNUSED,
Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
evas_object_del(ui.ask_popup);
ui.ask_popup = NULL;
}
static void
_extra_win_ask_for_default(Extra_Theme *theme)
{
Evas_Object *o, *table;
ui.ask_popup = elm_popup_add(ui.win);
table = elm_table_add(ui.ask_popup);
elm_object_content_set(ui.ask_popup, table);
evas_object_show(table);
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(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(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(ui.ask_popup);
}
static void
_download_progress_cb(double progress)
{
elm_progressbar_value_set(ui.theme_ui.progress, progress);
}
static void
_download_done(void)
{
char *preview;
preview = extra_theme_preview_get(_selected_theme);
if (preview)
{
elm_image_file_set(ui.theme_ui.screenshot, preview, NULL);
evas_object_show(ui.theme_ui.screenshot);
free(preview);
}
evas_object_hide(ui.theme_ui.progress);
}
static void
extra_theme_show(Extra_Theme *theme)
{
char title[1024], author[1024];
char *preview;
_selected_theme = theme;
if (!theme) return;
snprintf(title, sizeof(title), "<title>%s</title>", theme->name);
elm_object_text_set(ui.theme_ui.title, title);
snprintf(author, sizeof(author), "<link>%s</link>", theme->author);
elm_object_text_set(ui.theme_ui.author, author);
elm_object_text_set(ui.theme_ui.description, theme->description);
elm_progressbar_value_set(ui.theme_ui.progress, 0.0);
preview = extra_theme_preview_get(theme);
if (preview)
{
elm_image_file_set(ui.theme_ui.screenshot, preview, NULL);
free(preview);
}
else
{
_preview_progress.progress_cb = _download_progress_cb;
_preview_progress.done_cb = _download_done;
extra_theme_preview_download(&_preview_progress, theme);
evas_object_hide(ui.theme_ui.screenshot);
evas_object_show(ui.theme_ui.progress);
}
elm_object_disabled_set(ui.theme_ui.install, extra_theme_installed(theme));
}
Ui _ui;
static void
_extra_win_del(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
@ -243,243 +24,41 @@ _extra_win_del(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event
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 Evas_Object*
_theme_content_get(void *data, Evas_Object *obj, const char *source)
{
Extra_Theme *theme;
theme = (Extra_Theme *) data;
if (!!strcmp(source, "elm.swallow.end"))
return NULL;
if (extra_theme_installed(theme))
{
Evas_Object *icon;
icon = elm_icon_add(obj);
elm_icon_standard_set(icon, "emblem-favorite");
evas_object_show(icon);
return icon;
}
return NULL;
}
static void
_theme_select(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
_extra_win_sync_done_cb(void *data)
{
extra_theme_show(data);
}
Evas_Object *new_view;
static void
_extra_win_theme_add(Extra_Theme *theme)
{
elm_genlist_item_append(ui.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;
elm_genlist_clear(ui.theme_list);
EINA_LIST_FOREACH(extra_themes_list(), item, theme)
_extra_win_theme_add(theme);
}
static void
_extra_win_sync_done_cb()
{
Extra_Theme *first;
_extra_win_progress_popup_del();
_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(ui.theme_list), EINA_TRUE);
new_view = extra_theme_selector_create();
_ui.current_view = new_view;
elm_win_resize_object_add(_ui.win, _ui.current_view);
}
static void
extra_win_sync(void)
{
_sync_progress.progress_cb = _extra_win_progress_popup_cb;
_sync_progress.done_cb = _extra_win_sync_done_cb;
Extra_Progress *progress;
_extra_win_progress_popup_show("Updating themes");
extra_sync(&_sync_progress);
}
static void
_extra_win_download_done_cb()
{
_extra_win_progress_popup_del();
_extra_win_theme_list_refresh();
extra_theme_show(_selected_theme);
_extra_win_ask_for_default(_selected_theme);
}
static void
_extra_win_install_execute()
{
_extra_win_progress_popup_show("Installing theme");
_install_progress.progress_cb = _extra_win_progress_popup_cb;
_install_progress.done_cb = _extra_win_download_done_cb;
extra_theme_download(&_install_progress, _selected_theme);
}
static void
_extra_win_install_click_cb(void *data EINA_UNUSED,
Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
_extra_win_install_execute();
}
static void
_show_fullscreen(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, Evas *e EINA_UNUSED, void *event_info)
{
Evas_Event_Mouse_Up *ev = event_info;
if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
if (!ui.fullscreen_image)
{
_extra_win_fullscreen_preview(_selected_theme);
ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
}
progress = extra_ui_progress_popup_show("Updating themes", _extra_win_sync_done_cb, NULL);
extra_sync(progress);
}
static Evas_Object *
extra_win_setup(void)
{
Evas_Object *list, *pane, *box, *frame, *table, *install, *icon, *scroller;
ui.win = elm_win_util_standard_add("main", "Extra!");
if (!ui.win) return NULL;
_ui.win = elm_win_util_standard_add("main", "Extra!");
if (!_ui.win) return NULL;
elm_win_focus_highlight_enabled_set(ui.win, EINA_TRUE);
evas_object_smart_callback_add(ui.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(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(ui.win, pane);
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);
ui.theme_list = list;
frame = elm_frame_add(pane);
elm_object_text_set(frame, "Theme info");
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);
scroller = elm_scroller_add(frame);
evas_object_size_hint_weight_set(scroller, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(scroller, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_object_content_set(frame, scroller);
evas_object_show(scroller);
table = elm_table_add(frame);
evas_object_size_hint_weight_set(table, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(table, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_object_content_set(scroller, table);
evas_object_show(table);
ui.theme_ui.title = elm_label_add(table);
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);
elm_icon_standard_set(icon, "emblem-downloads");
elm_object_part_content_set(install, "icon", icon);
elm_table_pack(table, install, 3, 0, 1, 1);
evas_object_show(icon);
elm_object_text_set(install, "Install");
elm_object_disabled_set(install, EINA_TRUE);
evas_object_size_hint_weight_set(install, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(install, 1.0, 0.5);
evas_object_show(install);
evas_object_smart_callback_add(install, "clicked", _extra_win_install_click_cb, NULL);
ui.theme_ui.install = install;
ui.theme_ui.screenshot = elm_image_add(table);
elm_object_cursor_set(ui.theme_ui.screenshot, ELM_CURSOR_HAND2);
elm_object_cursor_style_set(ui.theme_ui.screenshot, ELM_CURSOR_HAND2);
evas_object_event_callback_add(ui.theme_ui.screenshot, EVAS_CALLBACK_MOUSE_UP, _show_fullscreen, 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.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.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.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(ui.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(ui.win);
evas_object_show(_ui.win);
return ui.win;
return _ui.win;
}
static const Ecore_Getopt optdesc = {
@ -543,7 +122,7 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
goto end;
if (skip_option)
_extra_win_sync_done_cb();
_extra_win_sync_done_cb(NULL);
else
extra_win_sync();

View File

@ -1,6 +1,19 @@
#ifndef EXTRA_PRIVATE_H_
# define EXTRA_PRIVATE_H_
// FIXME: put some private stuff related to your binary
#include "../lib/extra.h"
typedef struct {
Evas_Object *win;
Evas_Object *current_view;
} Ui;
extern Ui _ui;
Evas_Object* extra_theme_selector_create(void);
void extra_ui_theme_ask_for_default(Extra_Theme *theme);
Extra_Progress* extra_ui_progress_popup_show(const char *title, Extra_Done_Cb done, void *data);
#endif

View File

@ -0,0 +1,296 @@
#include <Elementary.h>
#include <Elementary_Cursor.h>
#include "extra_private.h"
#include "../lib/extra.h"
typedef struct {
Evas_Object *image;
Evas_Object *progress;
Extra_Progress p;
Extra_Theme *theme;
} Small_Preview;
static Evas_Object* extra_theme_small_preview_new(Evas_Object *par, Extra_Theme *theme);
static Elm_Gengrid_Item_Class *_item_class_basic;
static void
_delete_inwin(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
{
Evas_Event_Mouse_Up *ev = event_info;
if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
evas_object_del(data);
ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
}
static void
_extra_win_fullscreen_preview(Extra_Theme *theme)
{
Evas_Object *win, *image;
char *path;
path = extra_theme_preview_get(theme);
if (!path) return;
win = elm_win_util_standard_add("Extra - Screenshot", "Extra - Screenshot");
elm_win_fullscreen_set(win, EINA_TRUE);
evas_object_size_hint_weight_set(win, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(win, EVAS_HINT_FILL, EVAS_HINT_FILL);
image = elm_image_add(win);
evas_object_event_callback_add(image, EVAS_CALLBACK_MOUSE_UP, _delete_inwin, win);
evas_object_size_hint_weight_set(image, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(image, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_image_file_set(image, path, NULL);
evas_object_show(image);
elm_object_content_set(win, image);
evas_object_show(win);
}
static void
_fullscreen_picture(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
_extra_win_fullscreen_preview(data);
}
static void
_detail_preview_del(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info)
{
Evas_Event_Mouse_Up *up = event_info;
Eina_Rectangle box;
evas_object_geometry_get(data, &box.x, &box.y, &box.w, &box.h);
if (eina_rectangle_coords_inside(&box, up->output.x , up->output.y)) return;
evas_object_del(obj);
}
static void
_install_done(void *data)
{
Extra_Theme *theme = data;
extra_ui_theme_ask_for_default(theme);
}
static void
_install_theme(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
Extra_Theme *candidate = data;
Extra_Progress *progress;
Eina_Strbuf *title;
title = eina_strbuf_new();
eina_strbuf_append_printf(title, "Installing theme %s!", candidate->name);
progress = extra_ui_progress_popup_show(eina_strbuf_string_get(title), _install_done, candidate);
extra_theme_download(progress, candidate);
}
static void
_popup_theme(Evas_Object *win, Extra_Theme *theme)
{
Evas_Object *o, *inwin, *table, *title, *author, *description, *install, *icon;
char title_str[1024], author_str[1024];
snprintf(title_str, sizeof(title_str), "<title>%s</title>", theme->name);
snprintf(author_str, sizeof(author_str), "<link>%s</link>", theme->author);
inwin = o = elm_win_inwin_add(win);
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);
table = o = elm_table_add(inwin);
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_content_set(inwin, o);
evas_object_show(o);
evas_object_event_callback_add(inwin, EVAS_CALLBACK_MOUSE_UP, _detail_preview_del, o);
title = o = elm_label_add(inwin);
elm_object_text_set(o, title_str);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(o, 0.0, EVAS_HINT_FILL);
evas_object_show(o);
elm_table_pack(table, o, 0, 0, 1, 1);
icon = elm_icon_add(table);
elm_icon_standard_set(icon, "emblem-downloads");
evas_object_show(icon);
install = o = elm_button_add(table);
evas_object_smart_callback_add(install, "clicked", _install_theme, theme);
elm_object_part_content_set(install, "icon", icon);
elm_object_text_set(install, "Install");
elm_object_disabled_set(install, extra_theme_installed(theme));
evas_object_size_hint_weight_set(install, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(install, 1.0, 0.5);
elm_table_pack(table, o, 1, 0, 1, 1);
evas_object_show(install);
o = extra_theme_small_preview_new(inwin, theme);
evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _fullscreen_picture, theme);
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);
evas_object_show(o);
elm_table_pack(table, o, 0, 1, 2, 1);
author = o = elm_entry_add(inwin);
elm_object_text_set(o, author_str);
elm_entry_editable_set(o, EINA_FALSE);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(o);
elm_table_pack(table, o, 0, 2, 2, 1);
description = o = elm_entry_add(inwin);
elm_entry_editable_set(o, EINA_FALSE);
elm_object_text_set(o, theme->description);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(o);
elm_table_pack(table, o, 0, 3, 2, 2);
elm_win_inwin_activate(inwin);
}
static Evas_Object*
_content_basic_get(void *data, Evas_Object *obj, const char *source)
{
if (!strcmp(source, "elm.swallow.end"))
return NULL;
return extra_theme_small_preview_new(obj, data);
}
static char*
_text_basic_get(void *data, Evas_Object *obj EINA_UNUSED, const char *source EINA_UNUSED)
{
Extra_Theme *t = data;
return strdup(t->name);
}
static void
_item_selected(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
{
Elm_Gengrid_Item *it = event_info;
_popup_theme(data, elm_object_item_data_get(it));
}
Evas_Object*
extra_theme_selector_create(void)
{
Evas_Object *grid;
_item_class_basic = elm_gengrid_item_class_new();
_item_class_basic->item_style = "thumb";
_item_class_basic->func.content_get = _content_basic_get;
_item_class_basic->func.text_get = _text_basic_get;
grid = elm_gengrid_add(_ui.win);
elm_gengrid_select_mode_set(grid, ELM_OBJECT_SELECT_MODE_ALWAYS);
elm_gengrid_multi_select_set(grid, EINA_FALSE);
evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_gengrid_item_size_set(grid, 300, 300);
evas_object_smart_callback_add(grid, "selected", _item_selected, _ui.win);
evas_object_show(grid);
{
Eina_List *themes;
Extra_Theme *theme;
themes = extra_themes_list();
EINA_LIST_FREE(themes, theme)
{
elm_gengrid_item_append(grid, _item_class_basic, theme, NULL, NULL);
}
}
return grid;
}
//==== Small preview
static void
_small_preview_progress_cb(void *data, double progress)
{
Small_Preview *p = data;
elm_progressbar_value_set(p->progress, progress);
}
static void
_small_preview_done_cb(void *data)
{
Small_Preview *p = data;
char *preview;
preview = extra_theme_preview_get(p->theme);
if (preview)
{
elm_image_file_set(p->image , preview, NULL);
evas_object_show(p->image);
free(preview);
}
evas_object_hide(p->progress);
}
static Evas_Object*
extra_theme_small_preview_new(Evas_Object *par, Extra_Theme *theme)
{
Evas_Object *table;
Small_Preview *small;
char *preview;
small = calloc(1, sizeof(Small_Preview));
small->theme = theme;
table = elm_table_add(par);
evas_object_size_hint_weight_set(table, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(table, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(table);
small->image = elm_image_add(table);
evas_object_size_hint_weight_set(small->image, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(small->image, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_table_pack(table, small->image, 0, 1, 4, 2);
evas_object_show(small->image);
small->progress = elm_progressbar_add(table);
evas_object_size_hint_weight_set(small->progress, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(small->progress, EVAS_HINT_FILL, 0.0);
elm_table_pack(table, small->progress, 0, 2, 4, 1);
elm_progressbar_value_set(small->progress, 0.0);
preview = extra_theme_preview_get(theme);
if (preview)
{
elm_image_file_set(small->image, preview, NULL);
free(preview);
}
else
{
small->p.data = small;
small->p.done_cb = _small_preview_done_cb;
small->p.progress_cb = _small_preview_progress_cb;
extra_theme_preview_download(&small->p, theme);
evas_object_hide(small->image);
evas_object_show(small->progress);
}
return table;
}

131
src/bin/extra_util.c Normal file
View File

@ -0,0 +1,131 @@
#include <Elementary.h>
#include "extra_private.h"
#include "../lib/extra.h"
void
extra_win_progress_popup_show(const char *title)
{
Evas_Object *progress, *sync_popup;
sync_popup = elm_popup_add(_ui.win);
progress = elm_progressbar_add(sync_popup);
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", title);
elm_object_content_set(sync_popup, progress);
evas_object_show(sync_popup);
}
static void
_extra_win_ask_yes(void *data,
Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Extra_Theme *theme = data;
Evas_Object *popup = evas_object_data_get(obj, "popup");
extra_theme_use(theme);
evas_object_del(popup);
}
static void
_extra_win_ask_no(void *data EINA_UNUSED,
Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Evas_Object *popup = evas_object_data_get(obj, "popup");
evas_object_del(popup);
}
void
extra_ui_theme_ask_for_default(Extra_Theme *theme)
{
Evas_Object *o, *table, *popup;
popup = elm_popup_add(_ui.win);
table = elm_table_add(popup);
elm_object_content_set(popup, table);
evas_object_show(table);
o = elm_label_add(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);
elm_object_text_set(o, "Yes");
elm_table_pack(table, o, 0, 1, 1, 1);
evas_object_data_set(o, "popup", popup);
evas_object_smart_callback_add(o, "clicked", _extra_win_ask_yes, theme);
evas_object_show(o);
o = elm_button_add(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_data_set(o, "popup", popup);
evas_object_show(o);
evas_object_show(popup);
}
typedef struct {
Evas_Object *popup, *indicator;
Extra_Progress progress;
Extra_Done_Cb done_cb;
void *data;
} Extra_Ui_Progress;
static void
_extra_win_progress_popup_cb(void *data, double progress)
{
Extra_Ui_Progress *ui = data;
if (elm_progressbar_pulse_get(ui->indicator))
{
elm_progressbar_pulse(ui->indicator, EINA_FALSE);
elm_progressbar_pulse_set(ui->indicator, EINA_FALSE);
}
elm_progressbar_value_set(ui->indicator, progress);
}
static void
_popup_show_done_cb(void *data)
{
Extra_Ui_Progress *ui = data;
evas_object_del(ui->popup);
if (ui->done_cb)
ui->done_cb(ui->data);
free(ui);
}
Extra_Progress*
extra_ui_progress_popup_show(const char *title, Extra_Done_Cb done, void *data)
{
Extra_Ui_Progress *ui = calloc(1, sizeof(Extra_Ui_Progress));
ui->done_cb = done;
ui->data = data;
ui->progress.done_cb = _popup_show_done_cb;
ui->progress.progress_cb = _extra_win_progress_popup_cb;
ui->progress.data = ui;
ui->popup = elm_popup_add(_ui.win);
ui->indicator = elm_progressbar_add(ui->popup);
elm_progressbar_pulse_set(ui->indicator, EINA_TRUE);
elm_progressbar_pulse(ui->indicator, EINA_TRUE);
evas_object_show(ui->indicator);
elm_object_part_text_set(ui->popup, "title,text", title);
elm_object_content_set(ui->popup, ui->indicator);
evas_object_show(ui->popup);
return &ui->progress;
}