install: Basic theme downloader working
A few rough edges still to work out but it works
This commit is contained in:
parent
6716e80364
commit
34deff51f9
|
@ -18,8 +18,11 @@
|
|||
#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 Evas_Object *_win, *_popup, *_theme_list, *_install_button;
|
||||
static Evas_Object *_theme_name, *_theme_preview, *_theme_author;
|
||||
|
||||
static Extra_Theme *_theme;
|
||||
static Extra_Progress _sync_progress, _install_progress;
|
||||
|
||||
static void
|
||||
_extra_win_del(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
||||
|
@ -40,11 +43,19 @@ _theme_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *source EIN
|
|||
static void
|
||||
_theme_select(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
||||
{
|
||||
Extra_Theme *theme;
|
||||
const char *name_format = "<b>%s</b>";
|
||||
char *name;
|
||||
|
||||
theme = (Extra_Theme *)data;
|
||||
_theme = (Extra_Theme *)data;
|
||||
|
||||
printf("SELECTED %s\n", theme->id);
|
||||
name = malloc((strlen(name_format) + strlen(_theme->name) - 1) * sizeof(char));
|
||||
sprintf(name, name_format, _theme->name);
|
||||
elm_object_text_set(_theme_name, name);
|
||||
free(name);
|
||||
|
||||
elm_object_text_set(_theme_author, _theme->author);
|
||||
|
||||
elm_object_disabled_set(_install_button, extra_theme_installed(_theme));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -67,14 +78,21 @@ _extra_win_theme_list_refresh()
|
|||
static void
|
||||
_extra_win_sync_done_cb()
|
||||
{
|
||||
Extra_Theme *first;
|
||||
|
||||
ecore_thread_main_loop_begin();
|
||||
|
||||
elm_genlist_clear(_theme_list);
|
||||
|
||||
evas_object_hide(_sync_popup);
|
||||
_sync_popup = NULL;
|
||||
evas_object_hide(_popup);
|
||||
_popup = NULL;
|
||||
_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);
|
||||
|
||||
ecore_thread_main_loop_end();
|
||||
}
|
||||
|
||||
|
@ -86,23 +104,73 @@ extra_win_sync(Evas_Object *win)
|
|||
// _sync_progress.progress_cb = _extra_win_sync_progress_cb;
|
||||
_sync_progress.done_cb = _extra_win_sync_done_cb;
|
||||
|
||||
_sync_popup = elm_popup_add(win);
|
||||
_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);
|
||||
elm_object_part_text_set(_popup, "title,text", "Downloading themes");
|
||||
elm_object_content_set(_popup, progress);
|
||||
evas_object_show(_popup);
|
||||
|
||||
extra_sync(&_sync_progress);
|
||||
}
|
||||
|
||||
static void
|
||||
_extra_win_progress_cb(double progress EINA_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
_extra_win_done_cb()
|
||||
{
|
||||
ecore_thread_main_loop_begin();
|
||||
|
||||
evas_object_hide(_popup);
|
||||
_popup = NULL;
|
||||
_theme_select(_theme, NULL, NULL);
|
||||
|
||||
ecore_thread_main_loop_end();
|
||||
}
|
||||
|
||||
static void
|
||||
_extra_win_install_execute()
|
||||
{
|
||||
Evas_Object *progress;
|
||||
|
||||
_install_progress.id = _theme->id;
|
||||
_install_progress.is_theme = EINA_TRUE;
|
||||
|
||||
_install_progress.progress_cb = _extra_win_progress_cb;
|
||||
_install_progress.done_cb = _extra_win_done_cb;
|
||||
|
||||
_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(_popup, "title,text", "Processing...");
|
||||
elm_object_content_set(_popup, progress);
|
||||
evas_object_show(_popup);
|
||||
|
||||
extra_theme_install(&_install_progress);
|
||||
}
|
||||
|
||||
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 Evas_Object *
|
||||
extra_win_setup(void)
|
||||
{
|
||||
Evas_Object *win, *list, *pane, *box, *frame;
|
||||
Evas_Object *win, *list, *pane, *box, *frame, *table;
|
||||
Evas_Object *label, *preview, *install;
|
||||
|
||||
win = elm_win_util_standard_add("main", "Extra!");
|
||||
if (!win) return NULL;
|
||||
|
@ -138,6 +206,54 @@ extra_win_setup(void)
|
|||
evas_object_show(frame);
|
||||
elm_object_part_content_set(pane, "right", frame);
|
||||
|
||||
box = elm_box_add(frame);
|
||||
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_content_set(frame, box);
|
||||
|
||||
table = elm_table_add(pane);
|
||||
elm_table_homogeneous_set(table, EINA_TRUE);
|
||||
evas_object_size_hint_weight_set(table, EVAS_HINT_EXPAND, 0.25);
|
||||
evas_object_size_hint_align_set(table, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
evas_object_show(table);
|
||||
elm_box_pack_end(box, table);
|
||||
|
||||
preview = elm_icon_add(table);
|
||||
evas_object_size_hint_weight_set(preview, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(preview, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
evas_object_show(preview);
|
||||
elm_table_pack(table, preview, 3, 0, 1, 3);
|
||||
_theme_preview = preview;
|
||||
|
||||
label = elm_label_add(table);
|
||||
elm_object_text_set(label, "name");
|
||||
evas_object_show(label);
|
||||
elm_table_pack(table, label, 0, 0, 3, 1);
|
||||
_theme_name = label;
|
||||
|
||||
label = elm_label_add(table);
|
||||
elm_object_text_set(label, "Author: ");
|
||||
evas_object_show(label);
|
||||
elm_table_pack(table, label, 0, 1, 1, 1);
|
||||
|
||||
label = elm_label_add(table);
|
||||
elm_object_text_set(label, "author");
|
||||
evas_object_show(label);
|
||||
elm_table_pack(table, label, 1, 1, 2, 1);
|
||||
_theme_author = label;
|
||||
|
||||
install = elm_button_add(table);
|
||||
elm_object_text_set(install, "Install");
|
||||
elm_object_disabled_set(install, EINA_TRUE);
|
||||
evas_object_size_hint_weight_set(install, EVAS_HINT_EXPAND, 0.15);
|
||||
evas_object_size_hint_align_set(install, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
evas_object_show(install);
|
||||
elm_box_pack_end(box, install);
|
||||
|
||||
evas_object_smart_callback_add(install, "clicked", _extra_win_install_click_cb, NULL);
|
||||
_install_button = install;
|
||||
|
||||
evas_object_resize(win, 360 * elm_config_scale_get(),
|
||||
240 * elm_config_scale_get());
|
||||
|
||||
|
@ -145,6 +261,7 @@ extra_win_setup(void)
|
|||
_theme_class.func.text_get = _theme_text_get;
|
||||
evas_object_show(win);
|
||||
|
||||
_win = win;
|
||||
return win;
|
||||
}
|
||||
|
||||
|
|
128
src/lib/extra.c
128
src/lib/extra.c
|
@ -2,6 +2,9 @@
|
|||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "extra.h"
|
||||
|
||||
#include "extra_private.h"
|
||||
|
@ -81,10 +84,10 @@ _url_data_line_cb(char *buf, int len)
|
|||
if (buf[0] == '"')
|
||||
{
|
||||
buf[len-1] = '\0';
|
||||
_extra_theme_add(buf+1, buf+1, "", 0);
|
||||
_extra_theme_add(buf+1, buf+1, "", 1);
|
||||
}
|
||||
else
|
||||
_extra_theme_add(buf, buf, "", 0);
|
||||
_extra_theme_add(buf, buf, "", 1);
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
|
@ -147,3 +150,124 @@ extra_themes_list(void)
|
|||
return _theme_list;
|
||||
}
|
||||
|
||||
EAPI Extra_Theme *extra_theme_get(const char *id)
|
||||
{
|
||||
Extra_Theme *theme;
|
||||
Eina_List *item;
|
||||
|
||||
EINA_LIST_FOREACH(extra_themes_list(), item, theme)
|
||||
if (!strcmp(id, theme->id))
|
||||
return theme;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
EAPI Eina_Bool
|
||||
extra_theme_installed(Extra_Theme *theme)
|
||||
{
|
||||
char *path;
|
||||
Eina_Bool exists;
|
||||
|
||||
path = extra_theme_install_path_get(theme);
|
||||
exists = ecore_file_exists(path);
|
||||
free(path);
|
||||
|
||||
return exists;
|
||||
}
|
||||
|
||||
EAPI char *
|
||||
extra_theme_install_path_get(Extra_Theme *theme)
|
||||
{
|
||||
char *path;
|
||||
|
||||
path = malloc(PATH_MAX * sizeof(char));
|
||||
sprintf(path, "%s/.elementary/themes/%s.edj", eina_environment_home_get(), theme->id);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
EAPI char *
|
||||
extra_theme_preview_url_get(Extra_Theme *theme)
|
||||
{
|
||||
const char *pattern = "http://" HOSTNAME "/v1/themes/preview/%s.jpg";
|
||||
char *url;
|
||||
|
||||
if (!theme)
|
||||
return NULL;
|
||||
|
||||
url = malloc((strlen(pattern) + strlen(theme->id) - 1) * sizeof(char));
|
||||
sprintf(url, pattern, theme->id);
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
EAPI char *
|
||||
extra_theme_download_url_get(Extra_Theme *theme)
|
||||
{
|
||||
const char *pattern = "http://" HOSTNAME "/themes/%s-%d.edj";
|
||||
char *url;
|
||||
|
||||
if (!theme)
|
||||
return NULL;
|
||||
|
||||
url = malloc((strlen(pattern) + strlen(theme->id) - 1) * sizeof(char));
|
||||
sprintf(url, pattern, theme->id, theme->version);
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_install_complete_cb(void *data, int type EINA_UNUSED, void *event_info EINA_UNUSED)
|
||||
{
|
||||
Extra_Progress *progress = data;
|
||||
char *cmd = "enlightenment_remote -restart";
|
||||
|
||||
if (progress->done_cb)
|
||||
progress->done_cb();
|
||||
|
||||
if (progress->is_theme)
|
||||
{
|
||||
elm_theme_set(NULL, progress->id);
|
||||
elm_config_all_flush();
|
||||
elm_config_save();
|
||||
|
||||
sleep(5);
|
||||
ecore_exe_run(cmd, NULL);
|
||||
}
|
||||
|
||||
ecore_con_url_free(progress->url);
|
||||
|
||||
progress->done_cb();
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
EAPI void
|
||||
extra_theme_install(Extra_Progress *progress)
|
||||
{
|
||||
Extra_Theme *theme = NULL;
|
||||
char *path, *urlstr = NULL;
|
||||
Ecore_Con_Url *url;
|
||||
int fd;
|
||||
|
||||
if (progress->is_theme)
|
||||
theme = extra_theme_get(progress->id);
|
||||
|
||||
if (theme)
|
||||
urlstr = extra_theme_download_url_get(theme);
|
||||
|
||||
if (urlstr)
|
||||
{
|
||||
url = ecore_con_url_custom_new(urlstr, "GET");
|
||||
ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, _install_complete_cb, progress);
|
||||
path = extra_theme_install_path_get(theme);
|
||||
fd = creat(path, 0644);
|
||||
|
||||
ecore_con_url_fd_set(url, fd);
|
||||
progress->url = url;
|
||||
ecore_con_url_get(url);
|
||||
|
||||
free(path);
|
||||
free(urlstr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,6 +49,8 @@ typedef struct _Extra_Theme
|
|||
typedef struct _Extra_Progress
|
||||
{
|
||||
Ecore_Con_Url *url;
|
||||
const char *id;
|
||||
Eina_Bool is_theme;
|
||||
|
||||
void (*progress_cb)(double progress);
|
||||
void (*done_cb)(void);
|
||||
|
@ -133,6 +135,23 @@ EAPI void extra_sync(Extra_Progress *progress);
|
|||
*/
|
||||
EAPI Eina_List *extra_themes_list(void);
|
||||
|
||||
EAPI Extra_Theme *extra_theme_get(const char *id);
|
||||
|
||||
EAPI Eina_Bool extra_theme_installed(Extra_Theme *theme);
|
||||
|
||||
EAPI char *extra_theme_install_path_get(Extra_Theme *theme);
|
||||
|
||||
EAPI char *extra_theme_preview_url_get(Extra_Theme *theme);
|
||||
|
||||
EAPI char *extra_theme_download_url_get(Extra_Theme *theme);
|
||||
|
||||
/**
|
||||
* @brief Install the specified theme.
|
||||
*
|
||||
* @ingroup Themes
|
||||
*/
|
||||
EAPI void extra_theme_install(Extra_Progress *progress);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue