From: Enlightenment S. <no-...@en...> - 2010-09-15 16:31:50
|
Log: [Eve] Implement session saving/restoring. Author: acidx Date: 2010-09-15 09:31:42 -0700 (Wed, 15 Sep 2010) New Revision: 52307 Modified: trunk/eve/TODO trunk/eve/src/bin/chrome.c trunk/eve/src/bin/main.c trunk/eve/src/bin/prefs.c trunk/eve/src/bin/prefs.h Modified: trunk/eve/TODO =================================================================== --- trunk/eve/TODO 2010-09-15 16:25:21 UTC (rev 52306) +++ trunk/eve/TODO 2010-09-15 16:31:42 UTC (rev 52307) @@ -14,7 +14,6 @@ Preferences / State ------------------- - * save state: opened pages, etc. restore on restart * preferences (runtime, save at eet): - toggle: use start page (otherwise home page) - string: proxy Modified: trunk/eve/src/bin/chrome.c =================================================================== --- trunk/eve/src/bin/chrome.c 2010-09-15 16:25:21 UTC (rev 52306) +++ trunk/eve/src/bin/chrome.c 2010-09-15 16:31:42 UTC (rev 52307) @@ -75,6 +75,7 @@ EVE_PREF_AUTO_LOAD_IMAGES, EVE_PREF_AUTO_SHRINK_IMAGES, EVE_PREF_POPUP_ALLOW, + EVE_PREF_RESTORE_STATE, EVE_PREF_LAST } Eve_Preference; @@ -155,6 +156,13 @@ .pref_get = prefs_enable_private_mode_get, .pref_set = prefs_enable_private_mode_set, }}, NULL, ITEM_FLAG_NONE }, + { ITEM_TYPE_PREFERENCE, "Save and restore session", + (More_Menu_Preference[]) {{ + .type = PREF_TYPE_CHECKBOX, + .pref = EVE_PREF_RESTORE_STATE, + .pref_get = prefs_restore_state_get, + .pref_set = prefs_restore_state_set, + }}, NULL, ITEM_FLAG_NONE }, { ITEM_TYPE_SEPARATOR, NULL, NULL, NULL, ITEM_FLAG_NONE }, { ITEM_TYPE_STATIC_FOLDER, "Home page", (More_Menu_Item[]) { Modified: trunk/eve/src/bin/main.c =================================================================== --- trunk/eve/src/bin/main.c 2010-09-15 16:25:21 UTC (rev 52306) +++ trunk/eve/src/bin/main.c 2010-09-15 16:31:42 UTC (rev 52307) @@ -419,6 +419,27 @@ free(response); } +static void +state_save(void) +{ + Browser_Window *win; + Eina_List *win_iter; + + if (!prefs_restore_state_get(prefs)) return; + prefs_state_list_clear(prefs); + + EINA_LIST_FOREACH(app.windows, win_iter, win) + { + Evas_Object *chrome; + Eina_List *chrome_iter; + EINA_LIST_FOREACH(win->chromes, chrome_iter, chrome) + { + Evas_Object *view = evas_object_data_get(chrome, "view"); + prefs_state_add(prefs, prefs_opened_tab_new(ewk_view_uri_get(view))); + } + } +} + EAPI int elm_main(int argc, char **argv) { @@ -567,7 +588,7 @@ enable_plugins, EINA_TRUE, user_agent_str, DEFAULT_URL, NULL, EINA_FALSE, EINA_TRUE, EINA_FALSE, - EINA_TRUE); + EINA_TRUE, EINA_FALSE, NULL); prefs_save(prefs, path); } @@ -615,14 +636,33 @@ e_dbus_request_name(conn, "mobi.profusion.eve", 0, _cb_dbus_request_name, response); } - if (!add_win(&app, url)) + if (prefs_restore_state_get(prefs) && prefs_state_count(prefs) > 0) { + Eina_List *previous_state = prefs_state_list_get(prefs); + Eina_List *state_iter; + Prefs_Opened_Tab *tab = eina_list_data_get(previous_state); + Browser_Window *win; + + if (!add_win(&app, prefs_opened_tab_address_get(tab))) + { + r = -1; + goto end; + } + + win = eina_list_data_get(app.windows); + EINA_LIST_FOREACH(previous_state->next, state_iter, tab) + tab_add(win, prefs_opened_tab_address_get(tab)); + } + else if (!add_win(&app, url)) + { r = -1; goto end; } elm_run(); end: + state_save(); + fav_save(fav, NULL); fav_free(fav); Modified: trunk/eve/src/bin/prefs.c =================================================================== --- trunk/eve/src/bin/prefs.c 2010-09-15 16:25:21 UTC (rev 52306) +++ trunk/eve/src/bin/prefs.c 2010-09-15 16:31:42 UTC (rev 52307) @@ -9,6 +9,10 @@ #include "prefs.h" +struct _Prefs_Opened_Tab { + const char * address; +}; + struct _Prefs { char enable_mouse_cursor; char enable_touch_interface; @@ -21,14 +25,77 @@ char enable_auto_load_images; char enable_auto_shrink_images; char allow_popup; + char restore_state; + Eina_List * state; const char *__eet_filename; }; +static const char PREFS_OPENED_TAB_ENTRY[] = "prefs_opened_tab"; static const char PREFS_ENTRY[] = "prefs"; +static Eet_Data_Descriptor *_prefs_opened_tab_descriptor = NULL; static Eet_Data_Descriptor *_prefs_descriptor = NULL; static inline void +_prefs_opened_tab_init(void) +{ + Eet_Data_Descriptor_Class eddc; + + if (_prefs_opened_tab_descriptor) return; + + EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Prefs_Opened_Tab); + _prefs_opened_tab_descriptor = eet_data_descriptor_stream_new(&eddc); + + EET_DATA_DESCRIPTOR_ADD_BASIC(_prefs_opened_tab_descriptor, Prefs_Opened_Tab, "address", address, EET_T_STRING); +} + +static inline void +_prefs_opened_tab_shutdown(void) +{ + if (!_prefs_opened_tab_descriptor) return; + eet_data_descriptor_free(_prefs_opened_tab_descriptor); + _prefs_opened_tab_descriptor = NULL; +} + +Prefs_Opened_Tab * +prefs_opened_tab_new(const char * address) +{ + Prefs_Opened_Tab *prefs_opened_tab = calloc(1, sizeof(Prefs_Opened_Tab)); + + if (!prefs_opened_tab) + { + fprintf(stderr, "ERROR: could not calloc Prefs_Opened_Tab\n"); + return NULL; + } + + prefs_opened_tab->address = eina_stringshare_add(address); + + return prefs_opened_tab; +} + +void +prefs_opened_tab_free(Prefs_Opened_Tab *prefs_opened_tab) +{ + eina_stringshare_del(prefs_opened_tab->address); + free(prefs_opened_tab); +} + +inline const char * +prefs_opened_tab_address_get(const Prefs_Opened_Tab *prefs_opened_tab) +{ + return prefs_opened_tab->address; +} + +inline void +prefs_opened_tab_address_set(Prefs_Opened_Tab *prefs_opened_tab, const char *address) +{ + EINA_SAFETY_ON_NULL_RETURN(prefs_opened_tab); + eina_stringshare_del(prefs_opened_tab->address); + prefs_opened_tab->address = eina_stringshare_add(address); +} + + +static inline void _prefs_init(void) { Eet_Data_Descriptor_Class eddc; @@ -49,6 +116,8 @@ EET_DATA_DESCRIPTOR_ADD_BASIC(_prefs_descriptor, Prefs, "enable_auto_load_images", enable_auto_load_images, EET_T_CHAR); EET_DATA_DESCRIPTOR_ADD_BASIC(_prefs_descriptor, Prefs, "enable_auto_shrink_images", enable_auto_shrink_images, EET_T_CHAR); EET_DATA_DESCRIPTOR_ADD_BASIC(_prefs_descriptor, Prefs, "allow_popup", allow_popup, EET_T_CHAR); + EET_DATA_DESCRIPTOR_ADD_BASIC(_prefs_descriptor, Prefs, "restore_state", restore_state, EET_T_CHAR); + EET_DATA_DESCRIPTOR_ADD_LIST(_prefs_descriptor, Prefs, "state", state, _prefs_opened_tab_descriptor); } static inline void @@ -60,7 +129,7 @@ } Prefs * -prefs_new(char enable_mouse_cursor, char enable_touch_interface, char enable_plugins, char enable_javascript, const char * user_agent, const char * home_page, const char * proxy, char enable_private_mode, char enable_auto_load_images, char enable_auto_shrink_images, char allow_popup) +prefs_new(char enable_mouse_cursor, char enable_touch_interface, char enable_plugins, char enable_javascript, const char * user_agent, const char * home_page, const char * proxy, char enable_private_mode, char enable_auto_load_images, char enable_auto_shrink_images, char allow_popup, char restore_state, Eina_List * state) { Prefs *prefs = calloc(1, sizeof(Prefs)); @@ -81,6 +150,8 @@ prefs->enable_auto_load_images = enable_auto_load_images; prefs->enable_auto_shrink_images = enable_auto_shrink_images; prefs->allow_popup = allow_popup; + prefs->restore_state = restore_state; + prefs->state = state; return prefs; } @@ -91,6 +162,12 @@ eina_stringshare_del(prefs->user_agent); eina_stringshare_del(prefs->home_page); eina_stringshare_del(prefs->proxy); + if (prefs->state) + { + Prefs_Opened_Tab *state_elem; + EINA_LIST_FREE(prefs->state, state_elem) + prefs_opened_tab_free(state_elem); + } free(prefs); } @@ -240,6 +317,69 @@ prefs->allow_popup = allow_popup; } +inline char +prefs_restore_state_get(const Prefs *prefs) +{ + return prefs->restore_state; +} + +inline void +prefs_restore_state_set(Prefs *prefs, char restore_state) +{ + EINA_SAFETY_ON_NULL_RETURN(prefs); + prefs->restore_state = restore_state; +} + +inline void +prefs_state_add(Prefs *prefs, Prefs_Opened_Tab *prefs_opened_tab) +{ + EINA_SAFETY_ON_NULL_RETURN(prefs); + prefs->state = eina_list_append(prefs->state, prefs_opened_tab); +} + +inline void +prefs_state_del(Prefs *prefs, Prefs_Opened_Tab *prefs_opened_tab) +{ + EINA_SAFETY_ON_NULL_RETURN(prefs); + prefs->state = eina_list_remove(prefs->state, prefs_opened_tab); +} + +inline Prefs_Opened_Tab * +prefs_state_get(const Prefs *prefs, unsigned int nth) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(prefs, NULL); + return eina_list_nth(prefs->state, nth); +} + +inline unsigned int +prefs_state_count(const Prefs *prefs) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(prefs, 0); + return eina_list_count(prefs->state); +} + +void +prefs_state_list_clear(Prefs *prefs) +{ + EINA_SAFETY_ON_NULL_RETURN(prefs); + Prefs_Opened_Tab *data; + EINA_LIST_FREE(prefs->state, data) prefs_opened_tab_free(data); +} + +inline Eina_List * +prefs_state_list_get(const Prefs *prefs) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(prefs, NULL); + return prefs->state; +} + +inline void +prefs_state_list_set(Prefs *prefs, Eina_List *list) +{ + EINA_SAFETY_ON_NULL_RETURN(prefs); + prefs->state = list; +} + Prefs * prefs_load(const char *filename) { @@ -308,12 +448,14 @@ void preferences_init(void) { + _prefs_opened_tab_init(); _prefs_init(); } void preferences_shutdown(void) { + _prefs_opened_tab_shutdown(); _prefs_shutdown(); } Modified: trunk/eve/src/bin/prefs.h =================================================================== --- trunk/eve/src/bin/prefs.h 2010-09-15 16:25:21 UTC (rev 52306) +++ trunk/eve/src/bin/prefs.h 2010-09-15 16:31:42 UTC (rev 52307) @@ -7,10 +7,18 @@ #include <Eina.h> #include <Eet.h> +typedef struct _Prefs_Opened_Tab Prefs_Opened_Tab; typedef struct _Prefs Prefs; +/* Prefs_Opened_Tab */ +Prefs_Opened_Tab *prefs_opened_tab_new(const char * address); +void prefs_opened_tab_free(Prefs_Opened_Tab *prefs_opened_tab); + +void prefs_opened_tab_address_set(Prefs_Opened_Tab *prefs_opened_tab, const char * address); +const char * prefs_opened_tab_address_get(const Prefs_Opened_Tab *prefs_opened_tab); + /* Prefs */ -Prefs *prefs_new(char enable_mouse_cursor, char enable_touch_interface, char enable_plugins, char enable_javascript, const char * user_agent, const char * home_page, const char * proxy, char enable_private_mode, char enable_auto_load_images, char enable_auto_shrink_images, char allow_popup); +Prefs *prefs_new(char enable_mouse_cursor, char enable_touch_interface, char enable_plugins, char enable_javascript, const char * user_agent, const char * home_page, const char * proxy, char enable_private_mode, char enable_auto_load_images, char enable_auto_shrink_images, char allow_popup, char restore_state, Eina_List * state); void prefs_free(Prefs *prefs); void prefs_enable_mouse_cursor_set(Prefs *prefs, char enable_mouse_cursor); @@ -35,6 +43,15 @@ char prefs_enable_auto_shrink_images_get(const Prefs *prefs); void prefs_allow_popup_set(Prefs *prefs, char allow_popup); char prefs_allow_popup_get(const Prefs *prefs); +void prefs_restore_state_set(Prefs *prefs, char restore_state); +char prefs_restore_state_get(const Prefs *prefs); +void prefs_state_add(Prefs *prefs, Prefs_Opened_Tab *prefs_opened_tab); +void prefs_state_del(Prefs *prefs, Prefs_Opened_Tab *prefs_opened_tab); +Prefs_Opened_Tab *prefs_state_get(const Prefs *prefs, unsigned int nth); +unsigned int prefs_state_count(const Prefs *prefs); +Eina_List *prefs_state_list_get(const Prefs *prefs); +void prefs_state_list_clear(Prefs *prefs); +void prefs_state_list_set(Prefs *prefs, Eina_List *list); Prefs *prefs_load(const char *filename); Eina_Bool prefs_save(Prefs *prefs, const char *filename); |