Merge branch 'devs/bu5hm4n/ui-change'

This merges a new interface for extra. This brings:

1. Grid selection. There is a grid where you can select between the
themes. Themes are displayed with theire screenshots and names.

2. The state of the theme is be displayed. A theme can be downloaded,
set as default, or old-version available.

3. Different operations depending on the state of the theme. You have a
button to set a theme as default. Update the downloaded file. Or install
it, for the case its not even downloaded.
This commit is contained in:
Marcel Hollerbach 2017-01-15 21:16:30 +01:00
commit a458862760
7 changed files with 645 additions and 464 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 EINA_UNUSED)
{
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,391 @@
#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 *_selector;
static void _fill_gengrid(void);
static Evas_Object* extra_theme_small_preview_new(Evas_Object *par, Extra_Theme *theme);
static Evas_Object* extra_theme_small_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;
if (extra_theme_installed(theme))
extra_ui_theme_ask_for_default(theme);
elm_gengrid_clear(_selector);
_fill_gengrid();
}
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
_set_as_default(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
Extra_Theme *candidate = data;
extra_theme_use(candidate);
}
static void
_popup_theme(Evas_Object *win, Extra_Theme *theme)
{
Evas_Object *o, *inwin, *table;
Evas_Object *install = NULL, *icon = NULL;
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);
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);
if (!extra_theme_default_get(theme))
{
icon = elm_icon_add(table);
evas_object_show(icon);
install = o = elm_button_add(table);
elm_object_part_content_set(install, "icon", icon);
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);
}
if (!extra_theme_installed(theme) && extra_theme_installed_old(theme))
{
//there is a update available add a update button
elm_icon_standard_set(icon, "software-update-available");
evas_object_smart_callback_add(install, "clicked", _install_theme, theme);
elm_object_text_set(install, "Update");
}
else if (!extra_theme_installed(theme))
{
//that is not installed add a install utton
elm_icon_standard_set(icon, "emblem-downloads");
evas_object_smart_callback_add(install, "clicked", _install_theme, theme);
elm_object_text_set(install, "Install");
}
else if (extra_theme_installed(theme) && !extra_theme_default_get(theme))
{
//the theme is installed but not the default
elm_icon_standard_set(icon, "emblem-favorite");
evas_object_smart_callback_add(install, "clicked", _set_as_default, theme);
elm_object_text_set(install, "Set as default");
}
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);
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);
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_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));
}
static void
_fill_gengrid(void)
{
Eina_List *themes, *n;
Extra_Theme *theme;
themes = extra_themes_list();
EINA_LIST_FOREACH(themes, n, theme)
{
elm_gengrid_item_append(_selector, _item_class_basic, theme, NULL, NULL);
}
elm_gengrid_item_bring_in(elm_gengrid_first_item_get(_selector), ELM_GENGRID_ITEM_SCROLLTO_TOP);
}
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;
_selector = 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);
_fill_gengrid();
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*
_icon_add(Evas_Object *obj, const char *name, const char *desc)
{
Evas_Object *ret;
ret = elm_icon_add(obj);
evas_object_size_hint_min_set(ret, 20, 20);
elm_icon_standard_set(ret, name);
evas_object_show(ret);
elm_object_tooltip_text_set(ret, desc);
elm_object_tooltip_orient_set(ret, ELM_TOOLTIP_ORIENT_TOP);
return ret;
}
static Evas_Object*
extra_theme_small_new(Evas_Object *par, Extra_Theme *theme)
{
Evas_Object *table, *o;
int counter = 0;
table = extra_theme_small_preview_new(par, theme);
//for available states: downloaded, set as default, new-version available
if (extra_theme_installed(theme))
{
//theme is installed
o = _icon_add(par, "emblem-downloads", "This theme is installed");
elm_table_pack(table, o, counter, 0, 1, 1);
counter ++;
}
if (extra_theme_default_get(theme))
{
//theme is default
o = _icon_add(par, "emblem-default", "This theme is set as default");
elm_table_pack(table, o, counter, 0, 1, 1);
counter ++;
}
if (!extra_theme_installed(theme) && extra_theme_installed_old(theme))
{
o = _icon_add(par, "software-update-available", "There are updates available");
elm_table_pack(table, o, counter, 0, 1, 1);
counter ++;
}
return table;
}
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, 0, 4, 3);
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;
}

View File

@ -23,6 +23,8 @@ void _extra_theme_cache_load();
#define PREVIEW_DOWNLOAD 1
#define THEME_DOWNLOAD 2
#define GEN_FILE_NAME(buf, t) eina_strbuf_append_printf(buf, "%s-%d.edj", t->id, t->version);
typedef struct {
Extra_Theme theme;
char state; //indicates if some downloads are in progress
@ -269,7 +271,7 @@ _url_complete_cb(void *data, int type EINA_UNUSED, void *event_info)
}
if (progress->done_cb)
progress->done_cb();
progress->done_cb(progress->data);
ecore_event_handler_del(_data);
ecore_event_handler_del(_complete);
@ -335,7 +337,8 @@ extra_theme_install_path_get(Extra_Theme *theme)
buf = eina_strbuf_new();
eina_strbuf_append(buf, elm_theme_user_dir_get());
eina_strbuf_append_printf(buf, "/%s-%d.edj", theme->id, theme->version);
eina_strbuf_append(buf, "/");
GEN_FILE_NAME(buf, theme);
path = eina_strbuf_string_steal(buf);
eina_strbuf_free(buf);
return path;
@ -348,8 +351,11 @@ _download_complete_cb(void *data, const char *file EINA_UNUSED, int status EINA_
job->theme->state &= (~job->nand_mask);
if (status != 200)
ecore_file_remove(file);
if (job->progress->done_cb)
job->progress->done_cb();
job->progress->done_cb(job->progress->data);
}
static int
@ -364,7 +370,7 @@ _download_progress_cb(void *data EINA_UNUSED, const char *file EINA_UNUSED,
percent = ((double)(double)dlnow / (double)dltotal);
if (job->progress->progress_cb)
job->progress->progress_cb(percent);
job->progress->progress_cb(job->progress->data, percent);
return ECORE_FILE_PROGRESS_CONTINUE;
}
@ -467,22 +473,22 @@ extra_theme_download(Extra_Progress *progress, Extra_Theme *theme)
char *path, *urlstr = NULL;
Extra_Theme_Private *priv = ((Extra_Theme_Private*) theme);
if (theme)
{
if (priv->state & THEME_DOWNLOAD) return;
EINA_SAFETY_ON_NULL_RETURN(progress);
EINA_SAFETY_ON_NULL_RETURN(theme);
Extra_Download_Job *job = calloc(1, sizeof(Extra_Download_Job));
job->progress = progress;
job->theme = priv;
job->nand_mask = THEME_DOWNLOAD;
priv->state |= THEME_DOWNLOAD;
if (priv->state & THEME_DOWNLOAD) return;
urlstr = extra_theme_download_url_get(theme);
path = extra_theme_install_path_get(theme);
ecore_file_download(urlstr, path, _download_complete_cb, _download_progress_cb, job, NULL);
free(urlstr);
free(path);
}
Extra_Download_Job *job = calloc(1, sizeof(Extra_Download_Job));
job->progress = progress;
job->theme = priv;
job->nand_mask = THEME_DOWNLOAD;
priv->state |= THEME_DOWNLOAD;
urlstr = extra_theme_download_url_get(theme);
path = extra_theme_install_path_get(theme);
ecore_file_download(urlstr, path, _download_complete_cb, _download_progress_cb, job, NULL);
free(urlstr);
free(path);
}
void
@ -506,7 +512,7 @@ _extra_theme_cache_load()
{
eina_strbuf_append_length(buf, line->start, line->length);
}
eina_iterator_free(it);
eina_file_close(cache);
_fill_themes(buf);
eina_strbuf_free(buf);
@ -542,3 +548,57 @@ extra_theme_use(Extra_Theme *t)
ecore_timer_add(3, _enlightenment_restart, NULL);
}
EAPI Eina_Bool
extra_theme_default_get(Extra_Theme *t)
{
const char *theme_paths;
char *path, **split;
unsigned int items;
EINA_SAFETY_ON_NULL_RETURN_VAL(t, EINA_FALSE);
if (!extra_theme_installed(t)) return EINA_FALSE;
theme_paths = elm_theme_get(NULL);
path = extra_theme_install_path_get(t);
split = eina_str_split_full(theme_paths, path, -1, &items);
free(split[0]);
free(split);
return (items > 1);
}
EAPI Eina_Bool
extra_theme_installed_old(Extra_Theme *t)
{
Eina_List *n, *files;
const char *file;
Eina_Bool b = EINA_FALSE;
Eina_Strbuf *buf;
EINA_SAFETY_ON_NULL_RETURN_VAL(t, EINA_FALSE);
buf = eina_strbuf_new();
files = ecore_file_ls(elm_theme_user_dir_get());
GEN_FILE_NAME(buf, t);
EINA_LIST_FOREACH(files, n, file)
{
if (!strcmp(eina_strbuf_string_get(buf), file))
continue;
if (eina_str_has_prefix(file, t->id) &&
eina_str_has_extension(file, "edj"))
{
b = EINA_TRUE;
break;
}
}
eina_list_free(files);
eina_strbuf_free(buf);
return b;
}

View File

@ -38,6 +38,9 @@ extern "C" {
* @brief These routines are used for extra library interaction.
*/
typedef void (*Extra_Progress_Cb)(void *data, double progress);
typedef void (*Extra_Done_Cb)(void *data);
typedef struct _Extra_Theme
{
const char *id;
@ -49,8 +52,9 @@ typedef struct _Extra_Theme
typedef struct _Extra_Progress
{
void (*progress_cb)(double progress);
void (*done_cb)(void);
Extra_Progress_Cb progress_cb;
Extra_Done_Cb done_cb;
void *data;
} Extra_Progress;
/**
@ -156,7 +160,8 @@ EAPI void extra_theme_download(Extra_Progress *progress, Extra_Theme *theme);
* @ingroup Themes
*/
EAPI void extra_theme_use(Extra_Theme *t);
EAPI Eina_Bool extra_theme_default_get(Extra_Theme *t);
EAPI Eina_Bool extra_theme_installed_old(Extra_Theme *t);
/**
* @}
*/