* Use the new Exchange Smart Object in the E17 theme dialog (if exchange is installed)

SVN revision: 38037
This commit is contained in:
Davide Andreoli 2008-12-09 02:25:48 +00:00
parent 926522f7d6
commit 696e9a7449
3 changed files with 121 additions and 599 deletions

View File

@ -260,6 +260,7 @@ _cb_import(void *data1, void *data2)
static void
_cb_web(void *data1, void *data2)
{
#ifdef HAVE_EXCHANGE
E_Config_Dialog_Data *cfdata;
cfdata = data1;
@ -267,6 +268,7 @@ _cb_web(void *data1, void *data2)
e_win_raise(cfdata->dia_web->win);
else
cfdata->dia_web = e_int_config_theme_web(cfdata->cfd);
#endif
}
static void
@ -394,12 +396,11 @@ _basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cf
o = e_widget_button_add(evas, _(" Import..."), "enlightenment/themes",
_cb_import, cfdata, NULL);
e_widget_list_object_append(il, o, 1, 0, 0.5);
if (ecore_file_download_protocol_available("http://"))
{
o = e_widget_button_add(evas, _(" Online..."), "enlightenment/website",
_cb_web, cfdata, NULL);
e_widget_list_object_append(il, o, 1, 0, 0.5);
}
#ifdef HAVE_EXCHANGE
o = e_widget_button_add(evas, _(" Online..."), "enlightenment/website",
_cb_web, cfdata, NULL);
e_widget_list_object_append(il, o, 1, 0, 0.5);
#endif
e_widget_list_object_append(of, il, 1, 0, 0.0);
{

View File

@ -6,613 +6,73 @@
#include "e_int_config_theme.h"
#include "e_int_config_theme_web.h"
#define MAGIC_WEB 0x425581cb
#define TEMPLATE "/tmp/themeXXXXXX"
#ifdef HAVE_EXCHANGE
#include <Exchange.h>
typedef struct _Web Web;
struct _Web
{
int magic;
E_Config_Dialog *parent;
E_Config_Dialog_Data *cfdata;
E_Dialog *dia;
};
struct _E_Config_Dialog_Data
static void
_web_pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
{
Evas_Object *ofm, *o, *osfm, *ol;
Ecore_List *thumbs, *names, *medias;
Ecore_Con_Url *ecu;
Ecore_Event_Handler *hdata, *hcomplete;
FILE *feed;
int ready_for_edj, pending_downloads, busy;
char *edj, *ol_val, *tmpdir;
const char *source;
};
Evas_Coord th, vh;
static void _web_ok_cb(void *data, E_Dialog *dia);
static void _web_close_cb(void *data, E_Dialog *dia);
static void _web_del_cb(void *obj);
static void _file_double_click_cb(void *data, Evas_Object *obj, void *ev_info);
static void _file_click_cb(void *data, Evas_Object *obj, void *ev_info);
static int _list_find(const char *str1, const char *str2);
static void _source_sel_cb(void *data);
static void _reset(void *data);
static void _get_feed(char *url, void *data);
static int _feed_complete(void *data, int type, void *event);
static int _feed_data(void *data, int type, void *event);
static void _parse_feed(void *data);
static void _get_thumb_complete(void *data, const char *file, int status);
static int _download_media_progress_cb(void *data, const char *file, long int dltotal, long int dlnow, long int ultotal, long int ulnow);
static void _download_media_complete_cb(void *data, const char *file, int status);
evas_object_smart_callback_call(obj, "changed", NULL);
evas_object_size_hint_min_get(obj, NULL, &th);
evas_object_geometry_get(obj, NULL, NULL, NULL, &vh);
EAPI E_Dialog *
e_int_config_theme_web(E_Config_Dialog *parent)
if (y < 0) y = 0;
if (y > th - vh) y = th - vh;
exchange_smart_object_offset_set(obj, 0, y);
}
static void
_web_pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
{
Evas *evas;
E_Dialog *dia;
Web *web;
E_Config_Dialog_Data *cfdata;
Evas_Object *o, *ol, *of, *ofm, *osfm;
Evas_Coord mw, mh;
E_Fm2_Config fmc;
web = E_NEW(Web, 1);
if (!web) return NULL;
if (!x || !y) return;
exchange_smart_object_offset_get(obj, x, y);
}
web->magic = MAGIC_WEB;
static void
_web_pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
{
Evas_Coord tw, th, vw, vh;
dia = e_dialog_new(parent->con, "E", "_theme_web_dialog");
if (!dia)
{
E_FREE(web);
return NULL;
}
evas_object_size_hint_min_get(obj, &tw, &th);
evas_object_geometry_get(obj, NULL, NULL, &vw, &vh);
dia->data = web;
e_object_del_attach_func_set(E_OBJECT(dia), _web_del_cb);
e_win_centered_set(dia->win, 1);
if (x) *x = tw - vw;
if (y) *y = th - vh;
}
evas = e_win_evas_get(dia->win);
cfdata = E_NEW(E_Config_Dialog_Data, 1);
static void
_web_pan_child_size_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
{
Evas_Coord tw, th, vw, vh;
cfdata->ecu = ecore_con_url_new("http://fake.url");
evas_object_size_hint_min_get(obj, &tw, &th);
evas_object_geometry_get(obj, NULL, NULL, &vw, &vh);
cfdata->ready_for_edj = 0;
cfdata->pending_downloads = 0;
cfdata->busy = 0;
web->cfdata = cfdata;
web->dia = dia;
web->parent = parent;
e_dialog_title_set(dia, _("Choose a website from list..."));
o = e_widget_list_add(evas, 0, 1);
cfdata->o = o;
cfdata->thumbs = ecore_list_new();
ecore_list_free_cb_set(cfdata->thumbs, free);
cfdata->names = ecore_list_new();
ecore_list_free_cb_set(cfdata->names, free);
cfdata->medias = ecore_list_new();
ecore_list_free_cb_set(cfdata->medias, free);
of = e_widget_framelist_add(evas, "Sources", 1);
ol = e_widget_ilist_add(evas, 24, 24, &cfdata->ol_val);
cfdata->ol = ol;
e_widget_ilist_append(ol, NULL, _("get-e.org"),
_source_sel_cb, web,
"http://get-e.org/Themes/E17/feed.xml");
e_widget_ilist_go(ol);
e_widget_min_size_get(ol, &mw, NULL);
e_widget_min_size_set(ol, mw, 320);
e_widget_framelist_object_append(of, ol);
e_widget_list_object_append(o, of, 1, 0, 0.5);
ofm = e_fm2_add(evas);
memset(&fmc, 0, sizeof(E_Fm2_Config));
cfdata->ofm = ofm;
fmc.view.mode = E_FM2_VIEW_MODE_GRID_ICONS;
fmc.view.open_dirs_in_place = 1;
fmc.view.selector = 1;
fmc.view.single_click = 0;
fmc.view.no_subdir_jump = 0;
fmc.icon.list.w = 48;
fmc.icon.list.h = 48;
fmc.icon.icon.w = 128;
fmc.icon.icon.h = 128;
fmc.icon.fixed.w = 0;
fmc.icon.fixed.h = 0;
fmc.icon.extension.show = 0;
fmc.icon.key_hint = NULL;
fmc.list.sort.no_case = 1;
fmc.list.sort.dirs.first = 0;
fmc.list.sort.dirs.last = 1;
fmc.selection.single = 1;
fmc.selection.windows_modifiers = 0;
e_fm2_config_set(ofm, &fmc);
e_fm2_icon_menu_flags_set(ofm, E_FM2_MENU_NO_SHOW_HIDDEN);
evas_object_smart_callback_add(ofm, "selected",
_file_double_click_cb, web);
evas_object_smart_callback_add(ofm, "selection_change",
_file_click_cb, web);
osfm = e_widget_scrollframe_pan_add(evas, ofm,
e_fm2_pan_set,
e_fm2_pan_get,
e_fm2_pan_max_get,
e_fm2_pan_child_size_get);
cfdata->osfm = osfm;
e_widget_list_object_append(cfdata->o, cfdata->osfm, 1, 1, 0.5);
e_widget_min_size_set(osfm, 320, 320);
// e_widget_min_size_set(o, 580, 370);
e_widget_min_size_get(o, NULL, &mh);
e_dialog_content_set(dia, o, 480, mh);
e_dialog_button_add(dia, _("OK"), NULL, _web_ok_cb, web);
e_dialog_button_add(dia, _("Cancel"), NULL, _web_close_cb, web);
e_dialog_button_disable_num_set(dia, 0, 1);
e_dialog_resizable_set(dia, 1);
e_dialog_show(dia);
e_dialog_border_icon_set(dia, "enlightenment/theme");
return dia;
if (x) *x = tw;
if (y) *y = th;
}
void
e_int_config_theme_web_del(E_Dialog *dia)
{
Web *web;
E_Config_Dialog_Data *cfdata;
web = dia->data;
cfdata = web->cfdata;
if (cfdata->pending_downloads == 1)
ecore_file_download_abort_all();
if (cfdata->ecu)
ecore_con_url_destroy(cfdata->ecu);
if (cfdata->hdata)
ecore_event_handler_del(cfdata->hdata);
if (cfdata->hcomplete)
ecore_event_handler_del(cfdata->hcomplete);
if (cfdata->tmpdir)
{
if (ecore_file_is_dir(cfdata->tmpdir))
{
ecore_file_recursive_rm(cfdata->tmpdir);
ecore_file_rmdir(cfdata->tmpdir);
}
free(cfdata->tmpdir);
}
ecore_list_destroy(cfdata->thumbs);
ecore_list_destroy(cfdata->names);
ecore_list_destroy(cfdata->medias);
e_int_config_theme_web_done(web->parent);
E_FREE(web->cfdata);
E_FREE(web);
e_object_unref(E_OBJECT(dia));
}
static int
_download_media_progress_cb(void *data, const char *file, long int dltotal,
long int dlnow, long int ultotal, long int ulnow)
{
Web *web;
double status;
char title[4096];
web = data;
if ((dlnow == 0) || (dltotal == 0)) return 0;
if (dlnow != dltotal)
{
status = (double) ((double) dlnow) / ((double) dltotal);
snprintf(title, sizeof(title), _("[%s] Downloading of edje file... %d%% done"),
web->cfdata->source, (int) (status * 100.0));
e_dialog_title_set(web->dia, title);
}
return 0;
}
static void
_download_media_complete_cb(void *data, const char *file, int status)
{
Web *web;
char dest[4096];
web = data;
web->cfdata->pending_downloads = 0;
snprintf(dest, sizeof(dest), "%s/.e/e/themes/%s",
e_user_homedir_get(), ecore_file_file_get(web->cfdata->edj));
e_int_config_theme_update(web->parent, dest);
e_int_config_theme_web_del(web->dia);
}
static void
_download_media(Web *web)
{
Web *i;
E_Config_Dialog_Data *cfdata;
const char *file;
char buf[4096], title[4096];
i = web;
cfdata = i->cfdata;
cfdata->pending_downloads = 1;
file = ecore_file_file_get(cfdata->edj);
snprintf(buf, sizeof(buf), "%s/.e/e/themes/%s",
e_user_homedir_get(), file);
snprintf(title, sizeof(title), _("[%s] Downloading of edje file..."),
cfdata->source);
e_dialog_title_set(i->dia, title);
ecore_file_download(cfdata->edj, buf,
_download_media_complete_cb,
_download_media_progress_cb, i);
}
static void
_get_thumb_complete(void *data, const char *file, int status)
{
Web *web;
E_Config_Dialog_Data *cfdata;
char title[4096], dst[4096];
static int got = 1;
web = data;
cfdata = web->cfdata;
if (got != ecore_list_count(cfdata->thumbs))
{
snprintf(title, sizeof(title), _("[%s] Download %d images of %d"),
cfdata->source, got, ecore_list_index(cfdata->thumbs));
e_dialog_title_set(web->dia, title);
cfdata->ready_for_edj = 0;
snprintf(dst, sizeof(dst), "%s/%s", cfdata->tmpdir,
ecore_file_file_get(file));
ecore_file_mv(file, dst);
got++;
}
else
{
got = 1;
cfdata->busy = 0;
cfdata->ready_for_edj = 1;
snprintf(title, sizeof(title), _("[%s] Choose an image from list"),
cfdata->source);
e_dialog_title_set(web->dia, title);
e_dialog_button_disable_num_set(web->dia, 0, 0);
cfdata->pending_downloads = 0;
}
}
static void
_get_thumbs(void *data)
{
Web *web;
E_Config_Dialog_Data *cfdata;
char *src, *name, *ext;
char dtmp[4096], dest[4096];
web = data;
cfdata = web->cfdata;
cfdata->pending_downloads = 1;
snprintf(dtmp, sizeof(dtmp), "%s/.tmp", cfdata->tmpdir);
ecore_file_mkdir(dtmp);
ecore_list_first_goto(cfdata->thumbs);
ecore_list_first_goto(cfdata->names);
while ((src = ecore_list_next(cfdata->thumbs)))
{
name = ecore_list_next(cfdata->names);
ext = strrchr(src, '.');
snprintf(dest, sizeof(dest), "%s/%s%s", dtmp, name, ext);
ecore_file_download(src, dest, _get_thumb_complete, NULL, web);
}
}
static void
_get_feed(char *url, void *data)
{
Web *web;
E_Config_Dialog_Data *cfdata;
extern int errno;
char title[4096];
web = data;
cfdata = web->cfdata;
cfdata->tmpdir = mkdtemp(strdup(TEMPLATE));
ecore_con_url_url_set(cfdata->ecu, url);
ecore_file_download_abort_all();
if (cfdata->hdata) ecore_event_handler_del(cfdata->hdata);
if (cfdata->hcomplete) ecore_event_handler_del(cfdata->hcomplete);
if (cfdata->feed) fclose(cfdata->feed);
cfdata->hdata =
ecore_event_handler_add(ECORE_CON_EVENT_URL_DATA, _feed_data, web);
cfdata->hcomplete =
ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE,
_feed_complete, web);
snprintf(title, sizeof(title), _("[%s] Getting feed..."), cfdata->source);
e_dialog_title_set(web->dia, title); //
cfdata->feed = fopen("/tmp/themefeed.xml", "w+");
ecore_con_url_send(cfdata->ecu, NULL, 0, NULL);
}
static void
_reset(void *data)
{
Web *web;
E_Config_Dialog_Data *cfdata;
web = data;
cfdata = web->cfdata;
// If there's pending downloads, stop it
if (cfdata->pending_downloads == 1)
{
ecore_file_download_abort_all();
//ecore_file_download_shutdown();
}
cfdata->pending_downloads = 0;
// Reset busy state
cfdata->busy = 0;
// Clean lists
if (!ecore_list_empty_is(cfdata->thumbs))
ecore_list_clear(cfdata->thumbs);
if (!ecore_list_empty_is(cfdata->names))
ecore_list_clear(cfdata->names);
if (!ecore_list_empty_is(cfdata->medias))
ecore_list_clear(cfdata->medias);
// Clean existing data
if (ecore_file_exists("/tmp/themefeed.xml")) ecore_file_unlink("/tmp/themefeed.xml");
// Remove temporary data
if (cfdata->tmpdir)
{
if (ecore_file_is_dir(cfdata->tmpdir))
{
ecore_file_recursive_rm(cfdata->tmpdir);
ecore_file_rmdir(cfdata->tmpdir);
}
}
// Disable OK button
e_dialog_button_disable_num_set(web->dia, 0, 1);
}
static void
_parse_feed(void *data)
{
Web *web;
E_Config_Dialog_Data *cfdata;
FILE *fh;
char instr[1024];
char *edj, *img, *name;
char title[4096];
int state = -1;
web = data;
cfdata = web->cfdata;
cfdata->pending_downloads = 0;
fh = fopen("/tmp/themefeed.xml", "r");
while (fgets(instr, sizeof(instr), fh) != NULL)
{
if (strstr(instr, "<rss version") != NULL) state = 0;
if ((strstr(instr, "<item>") != NULL) && (state == 0))
{
edj = NULL;
img = NULL;
state = 1;
}
if ((strstr(instr, "<title>") != NULL) && (state == 1))
{
char *p;
name = strchr(instr, '>');
name++;
p = strchr(name, '<');
*p = 0;
name = strdup(name);
state = 2;
}
if ((strstr(instr, "<link>") != NULL) && (state == 2))
{
char *p;
edj = strchr(instr, '>');
edj++;
p = strchr(edj, '<');
*p = 0;
p = strrchr(ecore_file_file_get(edj), '.');
if (p)
{
if (!strcmp(p, ".edj"))
{
edj = strdup(edj);
state = 3;
}
}
}
if ((strstr(instr, "<enclosure") != NULL) && (state == 3))
{
char *p;
img = strstr(instr, "url=");
img += 5;
p = strchr(img, '"');
*p = 0;
img = strdup(img);
state = 4;
}
if ((strstr(instr, "</item>") != NULL) && (state == 4))
{
ecore_list_append(cfdata->thumbs, img);
ecore_list_append(cfdata->names, name);
ecore_list_append(cfdata->medias, edj);
state = 0;
}
}
fclose(fh);
if (state == 0)
{
snprintf(title, sizeof(title), _("[%s] Parsing feed... DONE!"),
cfdata->source);
e_dialog_title_set(web->dia, title);
e_fm2_path_set(cfdata->ofm, cfdata->tmpdir, "/");
_get_thumbs(web);
}
else
{
snprintf(title, sizeof(title), _("[%s] Parsing feed... FAILED!"),
cfdata->source);
cfdata->busy = 0;
e_dialog_title_set(web->dia, title);
}
}
static int
_feed_complete(void *data, int type, void *event)
{
Ecore_Con_Event_Url_Complete *euc;
E_Config_Dialog_Data *cfdata;
Web *web;
char title[4096];
euc = (Ecore_Con_Event_Url_Complete *)event;
web = data;
if (web->magic != MAGIC_WEB) return 1;
cfdata = web->cfdata;
if (cfdata->ecu != euc->url_con) return 1;
fclose(cfdata->feed);
cfdata->feed = NULL;
ecore_event_handler_del(cfdata->hdata);
ecore_event_handler_del(cfdata->hcomplete);
cfdata->hdata = NULL;
cfdata->hcomplete = NULL;
if (euc->status == 200)
{
snprintf(title, sizeof(title), _("[%s] Getting feed... DONE!"),
cfdata->source);
e_dialog_title_set(web->dia, title);
_parse_feed(data);
return 0;
}
else
{
snprintf(title, sizeof(title), _("[%s] Getting feed... FAILED!"),
cfdata->source);
e_dialog_title_set(web->dia, title);
}
return 0;
}
static int
_feed_data(void *data, int type, void *event)
{
Ecore_Con_Event_Url_Data *eud;
E_Config_Dialog_Data *cfdata;
Web *web;
eud = (Ecore_Con_Event_Url_Data *)event;
web = data;
if (web->magic != MAGIC_WEB) return 1;
cfdata = web->cfdata;
if (cfdata->ecu != eud->url_con) return 1;
fwrite(eud->data, sizeof(unsigned char), eud->size, cfdata->feed);
return 0;
}
static void
_source_sel_cb(void *data)
{
Web *web;
E_Config_Dialog_Data *cfdata;
web = data;
cfdata = web->cfdata;
if ((cfdata->busy == 0) && (cfdata->pending_downloads == 0))
{
cfdata->source = e_widget_ilist_selected_label_get(cfdata->ol);
_reset(web);
cfdata->busy = 1;
_get_feed(cfdata->ol_val, web);
}
else
e_widget_ilist_unselect(cfdata->ol);
}
static int
_list_find(const char *str1, const char *str2)
{
return strcmp(str1, ecore_file_strip_ext(str2));
}
static void
_file_click_cb(void *data, Evas_Object *obj, void *ev_info)
{
Web *web;
E_Config_Dialog_Data *cfdata;
Eina_List *sels;
E_Fm2_Icon_Info *icon_info;
web = data;
cfdata = web->cfdata;
sels = e_fm2_selected_list_get(cfdata->ofm);
if (!sels) return;
//if (cfdata->ready_for_edj == 0) return;
icon_info = sels->data;
if (ecore_list_find(cfdata->names, ECORE_COMPARE_CB(_list_find), icon_info->file))
cfdata->edj = ecore_list_index_goto(cfdata->medias, ecore_list_index(cfdata->names));
}
static void
_file_double_click_cb(void *data, Evas_Object *obj, void *ev_info)
{
/*E_Config_Dialog_Data *cfdata;
Eina_List *sels;
E_Fm2_Icon_Info *icon_info;
cfdata = data;
sels = e_fm2_selected_list_get(cfdata->ofm);
if (!sels)
return;
icon_info = sels->data;
printf("[double click] %s\n", icon_info->file);*/
// Unused atm, interesting to simulate click on Ok button
}
static void
_web_del_cb(void *obj)
{
@ -621,24 +81,85 @@ _web_del_cb(void *obj)
e_int_config_theme_web_del(dia);
}
static void
_web_ok_cb(void *data, E_Dialog *dia)
{
Web *web;
E_Config_Dialog_Data *cfdata;
Eina_List *sels;
web = data;
cfdata = web->cfdata;
sels = e_fm2_selected_list_get(cfdata->ofm);
if (sels)
_download_media(web);
else
e_int_config_theme_web_del(dia);
}
static void
_web_close_cb(void *data, E_Dialog *dia)
{
e_int_config_theme_web_del(dia);
}
static void
_web_apply(const char *path, void *data)
{
E_Action *a;
E_Config_Theme *ct;
ct = e_theme_config_get("theme");
if ((ct) && (!strcmp(ct->file, path))) return;
e_theme_config_set("theme", path);
e_config_save_queue();
a = e_action_find("restart");
if ((a) && (a->func.go)) a->func.go(NULL, NULL);
}
EAPI E_Dialog *
e_int_config_theme_web(E_Config_Dialog *parent)
{
E_Dialog *dia;
Web *web;
Evas_Object *ol, *exsm, *sf;
Evas_Coord mw, mh;
E_Fm2_Config fmc;
char sys_dir[PATH_MAX];
char usr_dir[PATH_MAX];
dia = e_dialog_new(parent->con, "E", "_theme_web_dialog");
if (!dia) return NULL;
web = E_NEW(Web, 1);
if (!web) return NULL;
web->dia = dia;
web->parent = parent;
e_dialog_title_set(dia, _("Exchange themes"));
e_dialog_border_icon_set(dia, "enlightenment/theme");
e_dialog_resizable_set(dia, 1);
e_dialog_button_add(dia, _("Close"), NULL, _web_close_cb, web);
dia->data = web;
e_object_del_attach_func_set(E_OBJECT(dia), _web_del_cb);
e_win_centered_set(dia->win, 1);
ol = e_widget_list_add(e_win_evas_get(dia->win), 0, 1);
/* The Exchange Smart Object*/
snprintf(sys_dir, sizeof(sys_dir), "%s/data/themes", e_prefix_data_get());
snprintf(usr_dir, sizeof(usr_dir), "%s/.e/e/themes", e_user_homedir_get());
exsm = exchange_smart_object_add(e_win_evas_get(dia->win));
exchange_smart_object_remote_group_set(exsm, "Border");
exchange_smart_object_local_path_set(exsm, usr_dir, sys_dir);
exchange_smart_object_mode_set(exsm, EXCHANGE_SMART_SHOW_BOTH);
exchange_smart_object_apply_cb_set(exsm, _web_apply, NULL);
/* The Scroll Frame */
sf = e_scrollframe_add(e_win_evas_get(dia->win));
e_scrollframe_extern_pan_set(sf, exsm, _web_pan_set, _web_pan_get,
_web_pan_max_get, _web_pan_child_size_get);
e_scrollframe_policy_set(sf, E_SCROLLFRAME_POLICY_OFF,
E_SCROLLFRAME_POLICY_ON);
e_scrollframe_thumbscroll_force(sf, 1);
e_widget_list_object_append(ol, sf, 1, 1, 0.5);
e_dialog_content_set(dia, ol, 500, 400);
e_dialog_show(dia);
exchange_smart_object_run(exsm);
return dia;
}
#endif

View File

@ -5,6 +5,6 @@
EAPI E_Dialog *e_int_config_theme_web(E_Config_Dialog *parent);
EAPI void e_int_config_theme_web_del(E_Dialog *dia);
#endif
#endif