From 2bd587add5912c02db71746e83eda47b66fb80af Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Fri, 26 Jul 2013 14:48:26 +0100 Subject: Make the parasitic hack of the old tree code more robust. Now if the temp_treeview_test option is set, the global history and cookie manager will be replaced with their respective new implementations. --- content/urldb.c | 59 +++++++++++++++++++----- desktop/cookies_old.c | 2 +- desktop/history_global_core.c | 2 +- desktop/hotlist.c | 2 +- desktop/sslcert.c | 2 +- desktop/tree.c | 103 ++++++++++++++++++++++++++++-------------- desktop/tree.h | 5 ++ 7 files changed, 127 insertions(+), 48 deletions(-) diff --git a/content/urldb.c b/content/urldb.c index f2f9c0a24..feb7c6f81 100644 --- a/content/urldb.c +++ b/content/urldb.c @@ -101,6 +101,7 @@ #include "content/content.h" #include "content/urldb.h" #include "desktop/cookies_old.h" +#include "desktop/cookie_manager.h" #include "utils/nsoption.h" #include "utils/log.h" #include "utils/corestrings.h" @@ -2540,7 +2541,13 @@ char *urldb_get_cookie(nsurl *url, bool include_http_only) version = c->version; c->last_used = now; - cookies_schedule_update((struct cookie_data *)c); + + if (nsoption_bool(temp_treeview_test) == false) + cookies_schedule_update( + (struct cookie_data *)c); + else + cookie_manager_add( + (struct cookie_data *)c); } } } @@ -2575,7 +2582,13 @@ char *urldb_get_cookie(nsurl *url, bool include_http_only) version = c->version; c->last_used = now; - cookies_schedule_update((struct cookie_data *)c); + + if (nsoption_bool(temp_treeview_test) == false) + cookies_schedule_update( + (struct cookie_data *)c); + else + cookie_manager_add( + (struct cookie_data *)c); } } @@ -2618,7 +2631,12 @@ char *urldb_get_cookie(nsurl *url, bool include_http_only) version = c->version; c->last_used = now; - cookies_schedule_update((struct cookie_data *)c); + + if (nsoption_bool(temp_treeview_test) == false) + cookies_schedule_update( + (struct cookie_data *)c); + else + cookie_manager_add((struct cookie_data *)c); } } @@ -2651,7 +2669,12 @@ char *urldb_get_cookie(nsurl *url, bool include_http_only) version = c->version; c->last_used = now; - cookies_schedule_update((struct cookie_data *)c); + + if (nsoption_bool(temp_treeview_test) == false) + cookies_schedule_update( + (struct cookie_data *)c); + else + cookie_manager_add((struct cookie_data *)c); } } @@ -3405,8 +3428,12 @@ bool urldb_insert_cookie(struct cookie_internal_data *c, lwc_string *scheme, d->prev->next = d->next; else p->cookies = d->next; - - cookies_remove((struct cookie_data *)d); + + if (nsoption_bool(temp_treeview_test) == false) + cookies_remove((struct cookie_data *)d); + else + cookie_manager_remove((struct cookie_data *)d); + urldb_free_cookie(d); urldb_free_cookie(c); } else { @@ -3421,11 +3448,18 @@ bool urldb_insert_cookie(struct cookie_internal_data *c, lwc_string *scheme, c->prev->next = c; else p->cookies = c; - - cookies_remove((struct cookie_data *)d); + + if (nsoption_bool(temp_treeview_test) == false) + cookies_remove((struct cookie_data *)d); + else + cookie_manager_remove((struct cookie_data *)d); urldb_free_cookie(d); - - cookies_schedule_update((struct cookie_data *)c); + + if (nsoption_bool(temp_treeview_test) == false) + cookies_schedule_update( + (struct cookie_data *)c); + else + cookie_manager_add((struct cookie_data *)c); } } else { c->prev = p->cookies_end; @@ -3436,7 +3470,10 @@ bool urldb_insert_cookie(struct cookie_internal_data *c, lwc_string *scheme, p->cookies = c; p->cookies_end = c; - cookies_schedule_update((struct cookie_data *)c); + if (nsoption_bool(temp_treeview_test) == false) + cookies_schedule_update((struct cookie_data *)c); + else + cookie_manager_add((struct cookie_data *)c); } return true; diff --git a/desktop/cookies_old.c b/desktop/cookies_old.c index 864fef65d..0aaf61f80 100644 --- a/desktop/cookies_old.c +++ b/desktop/cookies_old.c @@ -392,7 +392,7 @@ bool cookies_initialise(struct tree *tree, const char* folder_icon_name, const c */ unsigned int cookies_get_tree_flags(void) { - return TREE_DELETE_EMPTY_DIRS; + return TREE_DELETE_EMPTY_DIRS | TREE_COOKIES; } diff --git a/desktop/history_global_core.c b/desktop/history_global_core.c index ce438302f..b03485acb 100644 --- a/desktop/history_global_core.c +++ b/desktop/history_global_core.c @@ -297,7 +297,7 @@ bool history_global_initialise(struct tree *tree, const char* folder_icon_name) */ unsigned int history_global_get_tree_flags(void) { - return TREE_NO_FLAGS; + return TREE_NO_FLAGS | TREE_HISTORY; } diff --git a/desktop/hotlist.c b/desktop/hotlist.c index 055de3af8..adc9e5f8f 100644 --- a/desktop/hotlist.c +++ b/desktop/hotlist.c @@ -189,7 +189,7 @@ bool hotlist_initialise(struct tree *tree, const char *hotlist_path, */ unsigned int hotlist_get_tree_flags(void) { - return TREE_MOVABLE; + return TREE_MOVABLE | TREE_HOTLIST; } diff --git a/desktop/sslcert.c b/desktop/sslcert.c index 2b4d726e0..d5e7f6f55 100644 --- a/desktop/sslcert.c +++ b/desktop/sslcert.c @@ -73,7 +73,7 @@ void sslcert_init(const char* icon_name) */ unsigned int sslcert_get_tree_flags(void) { - return TREE_NO_DRAGS | TREE_NO_SELECT; + return TREE_NO_DRAGS | TREE_NO_SELECT | TREE_SSLCERT; } diff --git a/desktop/tree.c b/desktop/tree.c index 46910e7de..7cac1cbda 100644 --- a/desktop/tree.c +++ b/desktop/tree.c @@ -177,8 +177,11 @@ struct tree { #include "desktop/treeview.h" +#include "desktop/cookie_manager.h" #include "desktop/global_history.h" +int treeview_inits; + static void treeview_test_redraw_request(struct core_window *cw, struct rect r) { struct tree *tree = (struct tree *)cw; @@ -238,10 +241,22 @@ static bool treeview_test_init(struct tree *tree) if (nsoption_bool(temp_treeview_test) == false) return false; - treeview_init(); - err = global_history_init(&cw_t, (struct core_window *)tree); - if (err != NSERROR_OK) { - warn_user("Duffed it.", 0); + treeview_inits++; + + if (treeview_inits == 1) + treeview_init(); + + if (tree->flags & TREE_COOKIES) { + err = cookie_manager_init(&cw_t, (struct core_window *)tree); + if (err != NSERROR_OK) { + warn_user("Couldn't init new cookie manager.", 0); + } + } + if (tree->flags & TREE_HISTORY) { + err = global_history_init(&cw_t, (struct core_window *)tree); + if (err != NSERROR_OK) { + warn_user("Couldn't init new global history.", 0); + } } return true; @@ -254,12 +269,23 @@ static bool treeview_test_fini(struct tree *tree) if (nsoption_bool(temp_treeview_test) == false) return false; - err = global_history_fini(); - treeview_fini(); - if (err != NSERROR_OK) { - warn_user("Duffed it.", 0); + if (tree->flags & TREE_COOKIES) { + err = cookie_manager_fini(); + if (err != NSERROR_OK) { + warn_user("Couldn't finalise cookie manager.", 0); + } + } + if (tree->flags & TREE_HISTORY) { + err = global_history_fini(); + if (err != NSERROR_OK) { + warn_user("Couldn't finalise cookie manager.", 0); + } } + if (treeview_inits == 1) + treeview_fini(); + treeview_inits--; + return true; } @@ -277,9 +303,16 @@ static bool treeview_test_redraw(struct tree *tree, int x, int y, clip.x1 = clip_x + clip_width; clip.y1 = clip_y + clip_height; - global_history_redraw(x, y, &clip, ctx); + if (tree->flags & TREE_COOKIES) { + cookie_manager_redraw(x, y, &clip, ctx); + return true; + } + if (tree->flags & TREE_HISTORY) { + global_history_redraw(x, y, &clip, ctx); + return true; + } - return true; + return false; } static bool treeview_test_mouse_action(struct tree *tree, @@ -288,9 +321,16 @@ static bool treeview_test_mouse_action(struct tree *tree, if (nsoption_bool(temp_treeview_test) == false) return false; - global_history_mouse_action(mouse, x, y); + if (tree->flags & TREE_COOKIES) { + cookie_manager_mouse_action(mouse, x, y); + return true; + } + if (tree->flags & TREE_HISTORY) { + global_history_mouse_action(mouse, x, y); + return true; + } - return true; + return false; } static bool treeview_test_keypress(struct tree *tree, uint32_t key) @@ -298,9 +338,16 @@ static bool treeview_test_keypress(struct tree *tree, uint32_t key) if (nsoption_bool(temp_treeview_test) == false) return false; - global_history_keypress(key); + if (tree->flags & TREE_COOKIES) { + cookie_manager_keypress(key); + return true; + } + if (tree->flags & TREE_HISTORY) { + global_history_keypress(key); + return true; + } - return true; + return false; } @@ -420,9 +467,7 @@ struct tree *tree_create(unsigned int flags, tree_setup_colours(); - if (flags == TREE_MOVABLE) { - treeview_test_init(tree); - } + treeview_test_init(tree); return tree; } @@ -1267,9 +1312,7 @@ void tree_delete(struct tree *tree) { tree->redraw = false; - if (tree->flags == TREE_MOVABLE) { - treeview_test_fini(tree); - } + treeview_test_fini(tree); if (tree->root->child != NULL) tree_delete_node_internal(tree, tree->root->child, true); @@ -2196,11 +2239,9 @@ void tree_draw(struct tree *tree, int x, int y, assert(tree != NULL); assert(tree->root != NULL); - if (tree->flags == TREE_MOVABLE) { - if (treeview_test_redraw(tree, x, y, clip_x, clip_y, - clip_width, clip_height, ctx)) { - return; - } + if (treeview_test_redraw(tree, x, y, clip_x, clip_y, + clip_width, clip_height, ctx)) { + return; } /* Start knockout rendering if it's available for this plotter */ @@ -2567,10 +2608,8 @@ bool tree_mouse_action(struct tree *tree, browser_mouse_state mouse, int x, assert(tree != NULL); assert(tree->root != NULL); - if (tree->flags == TREE_MOVABLE) { - if (treeview_test_mouse_action(tree, mouse, x, y)) { - return true; - } + if (treeview_test_mouse_action(tree, mouse, x, y)) { + return true; } if (tree->root->child == NULL) @@ -3026,10 +3065,8 @@ void tree_drag_end(struct tree *tree, browser_mouse_state mouse, int x0, int y0, */ bool tree_keypress(struct tree *tree, uint32_t key) { - if (tree->flags == TREE_MOVABLE) { - if (treeview_test_keypress(tree, key)) { - return true; - } + if (treeview_test_keypress(tree, key)) { + return true; } if (tree->editing != NULL) diff --git a/desktop/tree.h b/desktop/tree.h index 20ade30c0..7074f6090 100644 --- a/desktop/tree.h +++ b/desktop/tree.h @@ -45,6 +45,11 @@ enum tree_flags { * directory will be deleted * too. */ + /* The following are to aid transition to new treeviews */ + TREE_HISTORY = 64, + TREE_COOKIES = 128, + TREE_SSLCERT = 256, + TREE_HOTLIST = 512 }; /** A "flag" value to indicate the element data contains title -- cgit v1.2.3