* New E17 online wallpaper selector (no more ExchangeSmartObject).

* online theme selector disabled for a moment.

Please test and report problems/suggestions.


SVN revision: 50015
This commit is contained in:
Davide Andreoli 2010-07-03 22:33:17 +00:00
parent 83d649c897
commit 008cbed18f
2 changed files with 228 additions and 76 deletions

View File

@ -16,6 +16,7 @@ struct _Web
E_Dialog *dia;
};
#if 0
static void
_web_pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
{
@ -103,10 +104,12 @@ _web_apply(const char *path, void *data)
a = e_action_find("restart");
if ((a) && (a->func.go)) a->func.go(NULL, NULL);
}
#endif
E_Dialog *
e_int_config_theme_web(E_Config_Dialog *parent)
{
#if 0
E_Dialog *dia;
Web *web;
Evas_Object *ol, *exsm, *sf;
@ -136,14 +139,14 @@ e_int_config_theme_web(E_Config_Dialog *parent)
ol = e_widget_list_add(e_win_evas_get(dia->win), 0, 1);
/* The Exchange Smart Object*/
// The Exchange Smart Object
e_user_dir_concat_static(usr_dir, "themes");
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);
exchange_smart_object_apply_cb_set(exsm, _web_apply, NULL);
/* The Scroll Frame */
// 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);
@ -158,6 +161,8 @@ e_int_config_theme_web(E_Config_Dialog *parent)
exchange_smart_object_run(exsm);
return dia;
#endif
return NULL;
}
#endif

View File

@ -14,85 +14,202 @@ struct _Web
{
E_Config_Dialog *parent;
E_Dialog *dia;
Evas_Object *list;
Evas_Object *textblock;
Evas_Object *image;
Eina_List *jobs;
Eina_List *objs;
};
static void
_web_pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
{
Evas_Coord th, vh;
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);
if (y < 0) y = 0;
if (y > vh - th) 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)
{
if ((!x) || (!y)) return;
exchange_smart_object_offset_get(obj, x, y);
}
static void
_web_pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
{
Evas_Coord tw, th, vw, vh;
evas_object_size_hint_min_get(obj, &tw, &th);
evas_object_geometry_get(obj, NULL, NULL, &vw, &vh);
if (x) *x = tw - vw;
if (y) *y = th - vh;
}
static void
_web_pan_child_size_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
{
Evas_Coord tw, th;
evas_object_size_hint_min_get(obj, &tw, &th);
if (x) *x = tw;
if (y) *y = th;
}
enum {
BTN_DOWNLOAD,
BTN_APPLY,
BTN_CLOSE
};
void
e_int_config_wallpaper_web_del(E_Dialog *dia)
{
Web *web;
Ecore_File_Download_Job *job;
Exchange_Object *wp;
Eina_List *l;
web = dia->data;
e_int_config_wallpaper_web_done(web->parent);
EINA_LIST_FOREACH(web->jobs, l, job)
ecore_file_download_abort(job);
EINA_LIST_FREE(web->objs, wp)
exchange_object_free(wp);
evas_object_del(web->list);
evas_object_del(web->textblock);
evas_object_del(web->image);
E_FREE(web);
e_object_unref(E_OBJECT(dia));
exchange_shutdown();
}
static void
_web_del_cb(void *obj)
_web_del_cb(void *data)
{
E_Dialog *dia;
dia = obj;
dia = data;
e_int_config_wallpaper_web_del(dia);
}
static void
_web_close_cb(void *data, E_Dialog *dia)
_web_download_complete_cb(Exchange_Object *obj, const char *file, void *data)
{
Exchange_Object *wp = data;
Web *web = exchange_obj_data_get(wp);
if (wp == e_widget_ilist_selected_data_get(web->list))
{
e_dialog_button_disable_num_set(web->dia, BTN_APPLY, 0);
e_dialog_button_disable_num_set(web->dia, BTN_DOWNLOAD, 1);
}
}
static void
_web_download_btn_cb(void *data, E_Dialog *dia)
{
Web *web = data;
Exchange_Object *wp;
char buf[PATH_MAX];
wp = e_widget_ilist_selected_data_get(web->list);
if (!wp) return;
e_user_dir_concat(buf, sizeof(buf), "backgrounds");
exchange_obj_download(wp, buf, _web_download_complete_cb, wp);
e_dialog_button_disable_num_set(web->dia, BTN_DOWNLOAD, 1);
}
static void
_web_apply_btn_cb(void *data, E_Dialog *dia)
{
Web *web = data;
Exchange_Object *wp;
char buf[PATH_MAX];
wp = e_widget_ilist_selected_data_get(web->list);
if (!wp) return;
e_user_dir_snprintf(buf, sizeof(buf), "backgrounds/%s",
exchange_obj_file_name_get(wp));
if (!ecore_file_exists(buf)) return;
e_bg_default_set(buf);
e_bg_update();
e_config_save_queue();
}
static void
_web_close_btn_cb(void *data, E_Dialog *dia)
{
e_int_config_wallpaper_web_del(dia);
}
static void
_web_apply(const char *path, void *data)
static void
_screenshot_get_cb(Exchange_Object *obj, const char *file, void *data)
{
E_Action *a;
E_Config_Theme *ct;
Web *web = data;
e_bg_default_set((char*)path);
e_bg_update();
e_config_save_queue();
if (obj == e_widget_ilist_selected_data_get(web->list))
e_widget_image_file_set(web->image, file);
}
static void
_list_selection_changed(void *data, Evas_Object *obj)
{
char buf[PATH_MAX];
Web *web = data;
Exchange_Object *wp;
Eina_Strbuf *sbuf;
wp = e_widget_ilist_selected_data_get(obj);
exchange_obj_screenshot_get(wp, _screenshot_get_cb, web);
// TODO inform the user that the download has started (spinner somewhere)
// enable download button ?
e_user_dir_concat(buf, sizeof(buf), "backgrounds");
if (exchange_obj_update_available(wp, buf))
e_dialog_button_disable_num_set(web->dia, BTN_DOWNLOAD, 0);
else
e_dialog_button_disable_num_set(web->dia, BTN_DOWNLOAD, 1);
// enable apply button ?
e_user_dir_snprintf(buf, sizeof(buf), "backgrounds/%s",
exchange_obj_file_name_get(wp));
if (ecore_file_exists(buf))
e_dialog_button_disable_num_set(web->dia, BTN_APPLY, 0);
else
e_dialog_button_disable_num_set(web->dia, BTN_APPLY, 1);
// update textblock
sbuf = eina_strbuf_new();
e_widget_textblock_plain_set(web->textblock, "");
if (exchange_obj_name_get(wp))
eina_strbuf_append_printf(sbuf,"<b>%s</b>", exchange_obj_name_get(wp));
if (exchange_obj_version_get(wp))
eina_strbuf_append_printf(sbuf, " v %s", exchange_obj_version_get(wp));
eina_strbuf_append(sbuf, "<br>");
if (exchange_obj_author_get(wp))
eina_strbuf_append_printf(sbuf, "%s %s<br>", _("By"),
exchange_obj_author_get(wp));
if (exchange_obj_description_get(wp))
{
printf("\n%s\n",exchange_obj_description_get(wp)); // TODO Fix '&' markup error
eina_strbuf_append_printf(sbuf, "<br>%s<br>", exchange_obj_description_get(wp));
}
e_widget_textblock_markup_set(web->textblock, eina_strbuf_string_get(sbuf));
eina_strbuf_free(sbuf);
}
static void
_thumbnail_download_cb(Exchange_Object *obj, const char *file, void *data)
{
Web *web = data;
Evas_Object *ic;
ic = e_widget_image_add_from_file(evas_object_evas_get(web->list),
file, 0, 0);
e_widget_ilist_append(web->list, ic, exchange_obj_name_get(obj),
NULL, obj, NULL);
}
static void
_exchange_query_cb(Eina_List *results, void *data)
{
Web *web = data;
Exchange_Object *wp;
Eina_List *l;
eina_list_free(web->jobs);
web->jobs = NULL;
e_widget_ilist_clear(web->list);
if (!results)
{
e_widget_ilist_append(web->list, NULL, _("Error getting data !"),
NULL, NULL, NULL);
return;
}
EINA_LIST_FOREACH(results, l, wp)
{
exchange_obj_thumbnail_get(wp, _thumbnail_download_cb, web);
exchange_obj_data_set(wp, web);
}
web->objs = results;
}
E_Dialog *
@ -100,11 +217,14 @@ e_int_config_wallpaper_web(E_Config_Dialog *parent)
{
E_Dialog *dia;
Web *web;
Evas_Object *ol, *exsm, *sf;
Evas_Coord mw, mh;
E_Fm2_Config fmc;
char usr_dir[PATH_MAX];
Evas_Object *o, *ot, *ot2;
Evas *evas;
Ecore_File_Download_Job *job;
if (!exchange_init())
return NULL;
// e_dialog
dia = e_dialog_new(parent->con, "E", "_wallpaper_web_dialog");
if (!dia) return NULL;
@ -115,36 +235,63 @@ e_int_config_wallpaper_web(E_Config_Dialog *parent)
web->parent = parent;
e_dialog_title_set(dia, _("Exchange wallpapers"));
e_dialog_border_icon_set(dia, "network-website");
e_dialog_resizable_set(dia, 1);
e_dialog_button_add(dia, _("Close"), NULL, _web_close_cb, web);
e_dialog_button_add(dia, _("Download"), NULL, _web_download_btn_cb, web);
e_dialog_button_add(dia, _("Apply"), NULL, _web_apply_btn_cb, web);
e_dialog_button_add(dia, _("Close"), NULL, _web_close_btn_cb, web);
e_dialog_button_disable_num_set(dia, BTN_DOWNLOAD, 1);
e_dialog_button_disable_num_set(dia, BTN_APPLY, 1);
dia->data = web;
e_object_del_attach_func_set(E_OBJECT(dia), _web_del_cb);
e_win_centered_set(dia->win, 1);
evas = e_win_evas_get(dia->win);
ol = e_widget_list_add(e_win_evas_get(dia->win), 0, 1);
// main table
ot = e_widget_table_add(evas, 0);
/* The Exchange Smart Object*/
e_user_dir_concat_static(usr_dir, "backgrounds");
exsm = exchange_smart_object_add(e_win_evas_get(dia->win));
exchange_smart_object_remote_group_set(exsm, "Wallpaper");
exchange_smart_object_local_path_set(exsm, usr_dir);
exchange_smart_object_apply_cb_set(exsm, _web_apply, NULL);
// themes list
o = e_widget_ilist_add(evas, 50, 50, NULL);
e_widget_size_min_set(o, 200, 200);
e_widget_ilist_multi_select_set(o, 0);
e_widget_on_change_hook_set(o, _list_selection_changed, web);
e_widget_ilist_append(o, NULL, _("Getting data, please wait..."),
NULL, NULL, NULL);
e_widget_table_object_append(ot, o, 0, 0, 1, 1, 0, 1, 0, 1);
web->list = o;
/* 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);
// second table
ot2 = e_widget_table_add(evas, 0);
e_widget_table_object_append(ot, ot2, 1, 0, 1, 1, 1, 1, 1, 1);
e_widget_list_object_append(ol, sf, 1, 1, 0.5);
e_dialog_content_set(dia, ol, 500, 400);
// textblock
o = e_widget_textblock_add(evas);
e_widget_size_min_set(o, 100, 100);
e_widget_textblock_plain_set(o, _("Select a background from the list."));
e_widget_table_object_append(ot2, o, 0, 0, 1, 1, 1, 1, 1, 0);
web->textblock = o;
// preview image
o = e_widget_image_add_from_file(evas, NULL, 100, 100);
e_widget_table_object_append(ot2, o, 0, 1, 1, 1, 1, 1, 1, 1);
web->image = o;
// request list from exchange
job = exchange_query(NULL, "e/desktop/background", 0, 0, 0, NULL, 0, 0,
_exchange_query_cb, web);
if (!job)
{
e_widget_ilist_clear(web->list);
e_widget_ilist_append(web->list, NULL, _("Error: can't start the request."),
NULL, NULL, NULL);
e_widget_textblock_plain_set(web->textblock, "");
}
else web->jobs = eina_list_append(web->jobs, job);
// show the dialog
e_dialog_content_set(dia, ot, 300, 220);
e_dialog_show(dia);
exchange_smart_object_run(exsm);
e_dialog_border_icon_set(dia, "network-website");
return dia;
}