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.

This commit is contained in:
Michael Drake 2013-07-26 14:48:26 +01:00
parent bb870de150
commit 2bd587add5
7 changed files with 127 additions and 48 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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,11 +269,22 @@ 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)

View File

@ -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