enlightenment/src/bin/e_update.c

290 lines
6.9 KiB
C
Raw Normal View History

#include "e.h"
static Ecore_Con_Url *url_up = NULL;
static Eina_List *handlers = NULL;
static Ecore_Timer *update_timer = NULL;
static E_Dialog *dialog = NULL;
static char *machid = NULL;
static void
_update_done(void)
{
if (url_up)
{
ecore_con_url_free(url_up);
url_up = NULL;
}
}
static void
_delete_cb(void *obj EINA_UNUSED)
{
dialog = NULL;
}
static void
_ok_cb(void *data EINA_UNUSED, E_Dialog *dia EINA_UNUSED)
{
e_object_del(E_OBJECT(dialog));
if (e_config->update.later > 0)
{
e_config->update.later = 0;
e_config_save_queue();
}
}
static void
_bother_me_later_cb(void *data EINA_UNUSED, E_Dialog *dia EINA_UNUSED)
{
e_object_del(E_OBJECT(dialog));
// 5 * 5 * 1hr === about 1 day limit, so bother-me later will wait
// a day in between botherings. botherings reset on e start or restart
if (e_config->update.later < 5)
{
e_config->update.later++;
e_config_save_queue();
}
}
static void
_never_tell_me_cb(void *data EINA_UNUSED, E_Dialog *dia EINA_UNUSED)
{
if (update_timer) ecore_timer_del(update_timer);
update_timer = NULL;
e_object_del(E_OBJECT(dialog));
e_config->update.check = 0;
e_config->update.later = 0;
e_config_save_queue();
}
static void
_new_version(const char *ver)
{
char text[2048];
2012-06-20 23:19:43 -07:00
if (dialog) return;
2012-06-20 23:19:43 -07:00
compositor rewrite / charlie-foxtrot situation huge fustercluck commit because there wasn't really a way to separate out the changes. better to just rip it all out at once. * compositor and window management completely rewritten. this was the goal for E19, but it pretty much required everything existing to be scrapped since it wasn't optimized, streamlined, or sensible. now instead of having the compositor strapped to the window manager like an outboard motor, it's housed more like an automobile engine. ** various comp structs have been merged into other places (eg. E_Comp_Zone is now just part of E_Zone where applicable), leading to a large deduplication of attributes ** awful E_Comp_Win is totally dead, having been replaced with e_comp_object smart objects which work just like normal canvas objects ** protocol-specific window management and compositor functionality is now kept exclusively in backend files ** e_pixmap api provides generic client finding and rendering api ** screen/xinerama screens are now provided directly by compositor on startup and re-set on change ** e_comp_render_update finally replaced with eina_tiler ** wayland compositor no longer creates X windows ** compositor e_layout removed entirely * e_container is gone. this was made unnecessary in E18, but I kept it to avoid having too much code churn in one release. its sole purpose was to catch some events and handle window stacking, both of which are now just done by the compositor infra * e_manager is just for screensaver and keybind stuff now, possibly remove later? * e_border is gone along with a lot of its api. e_client has replaced it, and e_client has been rewritten completely; some parts may be similar, but the design now relies upon having a functional compositor ** window configuration/focus functions are all removed. all windows are now managed solely with evas_object_X functions on the "frame" member of a client, just as any other canvas object can be managed. *** do NOT set interceptors on a client's comp_object. seriously. * startup order rewritten: compositor now starts much earlier, other things just use attrs and members of the compositor * ecore_x_pointer_xy_get usage replaced with ecore_evas_pointer_xy_get * e_popup is totally gone, existing usage replaced by e_comp_object_util_add where applicable, otherwise just placed normally on the canvas * deskmirror is (more) broken for now * illume is totally fucked * Ecore_X_Window replaced with Ecore_Window in most cases * edge binding XWindows replaced with regular canvas objects * some E_Win functionality has changed such that delete callbacks are now correctly called in ALL cases. various dialogs have been updated to not crash as a result comp files and descriptions: e_comp.c - overall compositor functions, rendering/update loop, shape cutting e_comp_x.c - X window management and compositor functionality e_comp_wl.c - Wayland surface management and compositor functionality e_comp_canvas.c - general compositor canvas functions and utilities e_comp_object.c - E_Client->frame member for managing clients as Evas_Objects, utility functions for adding objects to the compositor rendering systems additional authors: ivan.briano@intel.com feature: new compositor removal: e_border, e_container, e_popup
2014-01-14 17:19:12 -08:00
dialog = e_dialog_new(NULL, "E", "_update_available");
2012-06-20 23:19:43 -07:00
e_object_del_attach_func_set(E_OBJECT(dialog), _delete_cb);
e_dialog_button_add(dialog, _("OK"), NULL,
_ok_cb, NULL);
e_dialog_button_add(dialog, _("Bother me later"), NULL,
_bother_me_later_cb, NULL);
e_dialog_button_add(dialog, _("Never tell me"), NULL,
_never_tell_me_cb, NULL);
e_dialog_button_focus_num(dialog, 1);
e_dialog_title_set(dialog, _("Update Notice"));
e_dialog_icon_set(dialog, "dialog-warning", 64);
2012-06-20 23:19:43 -07:00
snprintf(text, sizeof(text),
2017-08-21 07:16:30 -07:00
_("Your enlightenment version is<ps/>"
"not the current latest release.<ps/>"
"The latest version is:<ps/>"
"<ps/>"
"%s<ps/>"
"<ps/>"
"Please visit www.enlightenment.org<ps/>"
"or update your system packages<ps/>"
"to get a new version."), ver);
e_dialog_text_set(dialog, text);
elm_win_center(dialog->win, 1, 1);
e_dialog_show(dialog);
}
static Eina_Bool
_upload_data_cb(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *event)
{
Ecore_Con_Event_Url_Data *ev = event;
if (ev->url_con != url_up) return EINA_TRUE;
if (ev->size > 0)
{
char *txt = alloca(ev->size + 1);
memcpy(txt, ev->data, ev->size);
txt[ev->size] = 0;
if (!strncmp(txt, "OK", 2))
{
}
else if (!strncmp(txt, "OLD", 3))
{
char *ver = strchr(txt, ' ');
if (ver)
{
ver++;
_new_version(ver);
}
}
}
return EINA_FALSE;
}
static Eina_Bool
_upload_progress_cb(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *event)
{
Ecore_Con_Event_Url_Progress *ev = event;
if (ev->url_con != url_up) return EINA_TRUE;
return EINA_FALSE;
}
static Eina_Bool
_upload_complete_cb(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *event)
{
Ecore_Con_Event_Url_Complete *ev = event;
if (ev->url_con != url_up) return EINA_TRUE;
if (ev->status != 200)
{
_update_done();
return EINA_FALSE;
}
_update_done();
return EINA_FALSE;
}
static void
_update_machid_get(void)
{
FILE *f;
char buf[4096], *c;
size_t len;
2012-06-20 23:19:43 -07:00
f = fopen("/etc/machine-id", "r");
if (!f) f = fopen("/var/lib/dbus/machine-id", "r");
if (!f)
{
e_user_dir_concat_static(buf, ".machid");
f = fopen(buf, "r");
}
if (f)
{
len = fread(buf, 1, sizeof(buf) - 1, f);
if (len > 10)
{
buf[len] = 0;
for (c = buf; *c; c++)
{
if (!isalnum(*c))
{
*c = 0;
break;
}
}
machid = strdup(buf);
fclose(f);
return;
}
fclose(f);
}
2012-06-20 23:19:43 -07:00
// generate ID
e_user_dir_concat_static(buf, ".machid");
f = fopen(buf, "w");
if (f)
{
double t;
fwrite("GEN-", 4, 1, f);
t = ecore_time_unix_get();
fprintf(f, "%1.16f-%i-%i\n", t, rand(), rand());
fclose(f);
_update_machid_get();
return;
}
// this just is all a wash - just use this
machid = strdup("NOIDEAWHATTHEIDOFTHISMACHINEIS");
}
static void
_update_post_generate(char *buf, int size)
{
if (!machid) _update_machid_get();
if (!machid) return;
2012-06-20 23:19:43 -07:00
snprintf(buf, size,
"CLIENT %s\n"
"UPDATE enlightenment %s",
machid, VERSION);
}
static void
_update_check(void)
{
char buf[1024];
if (url_up) _update_done();
url_up = ecore_con_url_new("http://www.enlightenment.org/update.php");
if (url_up)
{
_update_post_generate(buf, sizeof(buf));
ecore_con_url_http_version_set(url_up, ECORE_CON_URL_HTTP_VERSION_1_0);
ecore_con_url_post(url_up, buf, strlen(buf), "text/plain");
}
else
_update_done();
}
static Eina_Bool
_update_timeout_cb(void *data)
{
double t = 3600.0; // base minimum betwene checks -> 1hr min
int later = e_config->update.later;
2012-06-20 23:19:43 -07:00
if (e_config->update.check) _update_check();
if (update_timer) ecore_timer_del(update_timer);
if (later > 0)
{
later++;
t *= (later * later);
}
update_timer = ecore_timer_loop_add(t, _update_timeout_cb, data);
return EINA_FALSE;
}
EINTERN int
e_update_init(void)
{
if (ecore_con_url_init())
{
handlers = eina_list_append
(handlers, ecore_event_handler_add
(ECORE_CON_EVENT_URL_DATA, _upload_data_cb, NULL));
handlers = eina_list_append
(handlers, ecore_event_handler_add
(ECORE_CON_EVENT_URL_PROGRESS, _upload_progress_cb, NULL));
handlers = eina_list_append
(handlers, ecore_event_handler_add
(ECORE_CON_EVENT_URL_COMPLETE, _upload_complete_cb, NULL));
if (e_config->update.check)
{
e_config->update.check = 0;
_update_timeout_cb(NULL);
e_config->update.check = 1;
}
}
return 1;
}
EINTERN int
e_update_shutdown(void)
{
if (handlers)
{
_update_done();
ecore_con_url_shutdown();
}
if (update_timer)
{
ecore_timer_del(update_timer);
update_timer = NULL;
}
if (dialog) e_object_del(E_OBJECT(dialog));
dialog = NULL;
_update_done();
if (machid)
{
free(machid);
machid = NULL;
}
return 1;
}