From a836591435736b1d72eced1e6f643341422a7d82 Mon Sep 17 00:00:00 2001 From: Richard Wilson Date: Thu, 13 Jul 2006 12:46:02 +0000 Subject: Add basic cookie viewer, make trees use textarea components for UTF8 editing, trim headers, fix tree redraw issues. svn path=/trunk/netsurf/; revision=2739 --- desktop/cookies.h | 21 ++++++++ desktop/options.h | 2 +- desktop/tree.c | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++--- desktop/tree.h | 19 +++++-- 4 files changed, 177 insertions(+), 10 deletions(-) create mode 100644 desktop/cookies.h (limited to 'desktop') diff --git a/desktop/cookies.h b/desktop/cookies.h new file mode 100644 index 000000000..94d74dd50 --- /dev/null +++ b/desktop/cookies.h @@ -0,0 +1,21 @@ +/* + * This file is part of NetSurf, http://netsurf.sourceforge.net/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2006 Richard Wilson + */ + +/** \file + * Cookies (interface). + */ + +#ifndef _NETSURF_DESKTOP_COOKIES_H_ +#define _NETSURF_DESKTOP_COOKIES_H_ + +#include + +struct cookie_data; + +bool cookies_update(const struct cookie_data *data); + +#endif diff --git a/desktop/options.h b/desktop/options.h index 35e1d62a9..fdfeb89d0 100644 --- a/desktop/options.h +++ b/desktop/options.h @@ -24,7 +24,7 @@ #ifndef _NETSURF_DESKTOP_OPTIONS_H_ #define _NETSURF_DESKTOP_OPTIONS_H_ -#include "netsurf/desktop/tree.h" +struct tree; enum { OPTION_HTTP_PROXY_AUTH_NONE = 0, OPTION_HTTP_PROXY_AUTH_BASIC = 1, OPTION_HTTP_PROXY_AUTH_NTLM = 2 }; diff --git a/desktop/tree.c b/desktop/tree.c index b278be8df..7d3625945 100644 --- a/desktop/tree.c +++ b/desktop/tree.c @@ -18,6 +18,7 @@ #include "netsurf/desktop/tree.h" #include "netsurf/desktop/options.h" #include "netsurf/utils/log.h" +#include "netsurf/utils/messages.h" #include "netsurf/utils/utils.h" static void tree_draw_node(struct tree *tree, struct node *node, int clip_x, @@ -33,6 +34,8 @@ static void tree_selected_to_processing(struct node *node); void tree_clear_processing(struct node *node); struct node *tree_move_processing_node(struct node *node, struct node *link, bool before, bool first); +struct node *tree_create_leaf_node(struct node *parent, const char *title); +struct node *tree_create_leaf_node_shared(struct node *parent, const char *title); static int tree_initialising = 0; @@ -726,6 +729,12 @@ void tree_draw_node(struct tree *tree, struct node *node, int clip_x, int clip_y tree_draw_line(node->box.x + (NODE_INSTEP / 2), node->data.box.y + node->data.box.height, 0, (40 / 2)); + if ((node->parent) && (node->parent != tree->root) && + (node->parent->child == node)) + tree_draw_line(node->parent->box.x + (NODE_INSTEP / 2), + node->parent->data.box.y + + node->parent->data.box.height, 0, + (40 / 2)); tree_draw_line(node->box.x - (NODE_INSTEP / 2), node->data.box.y + node->data.box.height - (40 / 2), @@ -895,13 +904,18 @@ void tree_delete_node(struct tree *tree, struct node *node, bool siblings) { if (e->text) { /* we don't free non-editable titles or URLs */ - if (node->editable) + if ((node->editable) || (node->folder)) free(e->text); else { if (e->data == TREE_ELEMENT_URL) { /* reset URL characteristics */ urldb_reset_url_visit_data(e->text); } + + /* if not already 'deleted' then delete cookie */ + if (!node->deleted) { + /* todo: delete cookie data */ + } if (e->data != TREE_ELEMENT_TITLE && e->data != TREE_ELEMENT_URL) @@ -974,6 +988,33 @@ struct node *tree_create_leaf_node(struct node *parent, const char *title) { node->data.type = NODE_ELEMENT_TEXT; node->data.text = squash_whitespace(title); node->data.data = TREE_ELEMENT_TITLE; + node->editable = true; + if (parent) + tree_link_node(parent, node, false); + return node; +} + + +/** + * Creates a leaf node with the specified title, and links it into the tree. + * + * \param parent the parent node, or NULL not to link + * \param title the node title + * \return the newly created node. + */ +struct node *tree_create_leaf_node_shared(struct node *parent, const char *title) { + struct node *node; + + assert(title); + + node = calloc(sizeof(struct node), 1); + if (!node) return NULL; + node->folder = false; + node->data.parent = node; + node->data.type = NODE_ELEMENT_TEXT; + node->data.text = title; + node->data.data = TREE_ELEMENT_TITLE; + node->editable = false; if (parent) tree_link_node(parent, node, false); return node; @@ -1009,7 +1050,6 @@ struct node *tree_create_URL_node(struct node *parent, node = tree_create_leaf_node(parent, title); if (!node) return NULL; - node->editable = true; element = tree_create_node_element(node, TREE_ELEMENT_THUMBNAIL); if (element) @@ -1050,12 +1090,9 @@ struct node *tree_create_URL_node_shared(struct node *parent, title = data->title; else title = url; - node = tree_create_leaf_node(parent, title); + node = tree_create_leaf_node_shared(parent, title); if (!node) return NULL; - free(node->data.text); - node->data.text = title; - node->editable = false; element = tree_create_node_element(node, TREE_ELEMENT_THUMBNAIL); if (element) @@ -1073,6 +1110,102 @@ struct node *tree_create_URL_node_shared(struct node *parent, } +/** + * Creates a tree entry for a cookie, and links it into the tree. + * + * All information is used directly from the url_data, and as such cannot be + * edited and should never be freed. + * + * \param parent the node to link to + * \param url the URL + * \param data the cookie data to use + * \return the node created, or NULL for failure + */ +struct node *tree_create_cookie_node(struct node *parent, + const struct cookie_data *data) { + struct node *node; + struct node_element *element; + char buffer[256]; + char buffer2[16]; + + node = tree_create_leaf_node(parent, data->name); + if (!node) + return NULL; + node->data.data = TREE_ELEMENT_NAME; + node->editable = false; + + + element = tree_create_node_element(node, TREE_ELEMENT_PERSISTENT); + if (element) { + snprintf(buffer, 256, messages_get("TreePersistent"), + data->no_destroy ? messages_get("Yes") : messages_get("No")); + element->text = strdup(buffer); + } + element = tree_create_node_element(node, TREE_ELEMENT_VERSION); + if (element) { + snprintf(buffer2, 16, "TreeVersion%i", data->version); + snprintf(buffer, 256, messages_get("TreeVersion"), messages_get(buffer2)); + element->text = strdup(buffer); + } + element = tree_create_node_element(node, TREE_ELEMENT_SECURE); + if (element) { + snprintf(buffer, 256, messages_get("TreeSecure"), + data->secure ? messages_get("Yes") : messages_get("No")); + element->text = strdup(buffer); + } + element = tree_create_node_element(node, TREE_ELEMENT_LAST_USED); + if (element) { + snprintf(buffer, 256, messages_get("TreeLastUsed"), + (data->last_used > 0) ? + ctime(&data->last_used) : messages_get("TreeUnknown")); + if (data->last_used > 0) + buffer[strlen(buffer) - 1] = '\0'; + element->text = strdup(buffer); + } + element = tree_create_node_element(node, TREE_ELEMENT_EXPIRES); + if (element) { + snprintf(buffer, 256, messages_get("TreeExpires"), + (data->expires > 0) ? + ctime(&data->expires) : messages_get("TreeUnknown")); + if (data->expires > 0) + buffer[strlen(buffer) - 1] = '\0'; + element->text = strdup(buffer); + } + element = tree_create_node_element(node, TREE_ELEMENT_PATH); + if (element) { + snprintf(buffer, 256, messages_get("TreePath"), data->path, + data->path_from_set ? messages_get("TreeHeaders") : ""); + element->text = strdup(buffer); + } + element = tree_create_node_element(node, TREE_ELEMENT_DOMAIN); + if (element) { + snprintf(buffer, 256, messages_get("TreeDomain"), data->domain, + data->domain_from_set ? messages_get("TreeHeaders") : ""); + element->text = strdup(buffer); + } + if ((data->comment) && (strcmp(data->comment, ""))) { + LOG(("Comment: '%s'", data->comment)); + element = tree_create_node_element(node, TREE_ELEMENT_COMMENT); + if (element) { + snprintf(buffer, 256, messages_get("TreeComment"), data->comment); + element->text = strdup(buffer); + } + } + element = tree_create_node_element(node, TREE_ELEMENT_VALUE); + if (element) { + snprintf(buffer, 256, messages_get("TreeValue"), + data->value ? data->value : messages_get("TreeUnused")); + element->text = strdup(buffer); + } + + /* add version, last_used, expires, + * path, domain, comment, value */ + tree_set_node_sprite(node, "small_xxx", "small_xxx"); + tree_recalculate_node(node, false); + return node; +} + + /** * Creates an empty text node element and links it to a node. * diff --git a/desktop/tree.h b/desktop/tree.h index 0e9bf96ad..8990119d0 100644 --- a/desktop/tree.h +++ b/desktop/tree.h @@ -13,8 +13,10 @@ #define _NETSURF_DESKTOP_TREE_H_ #include +#include struct url_data; +struct cookie_data; typedef enum { TREE_ELEMENT_URL, @@ -23,7 +25,17 @@ typedef enum { TREE_ELEMENT_VISITS, TREE_ELEMENT_VISITED, TREE_ELEMENT_THUMBNAIL, - TREE_ELEMENT_TITLE + TREE_ELEMENT_TITLE, + TREE_ELEMENT_NAME, + TREE_ELEMENT_VALUE, + TREE_ELEMENT_COMMENT, + TREE_ELEMENT_DOMAIN, + TREE_ELEMENT_PATH, + TREE_ELEMENT_EXPIRES, + TREE_ELEMENT_LAST_USED, + TREE_ELEMENT_SECURE, + TREE_ELEMENT_VERSION, + TREE_ELEMENT_PERSISTENT } node_element_data; #define NODE_INSTEP 40 @@ -85,9 +97,9 @@ struct tree { int window_width; /* <-- Tree window width */ int window_height; /* <-- Tree window height */ int edit_handle; /* <-- Handle for editing information */ + uintptr_t textarea_handle; /* <-- Handle for UTF-8 textarea */ bool movable; /* <-- Whether nodes can be moved */ struct node_element *editing; /* <-- Node element being edited */ - char edit_buffer[256]; /* <-- Editing buffer */ struct node *temp_selection; /* <-- Temporarily selected node */ struct toolbar *toolbar; /* <-- Tree toolbar */ }; @@ -114,7 +126,6 @@ void tree_draw(struct tree *tree, int clip_x, int clip_y, int clip_width, void tree_link_node(struct node *link, struct node *node, bool before); void tree_delink_node(struct node *node); struct node *tree_create_folder_node(struct node *parent, const char *title); -struct node *tree_create_leaf_node(struct node *parent, const char *title); void tree_set_node_sprite(struct node *node, const char *sprite, const char *expanded); struct node *tree_create_URL_node(struct node *parent, @@ -122,6 +133,8 @@ struct node *tree_create_URL_node(struct node *parent, const char *title); struct node *tree_create_URL_node_shared(struct node *parent, const char *url, const struct url_data *data); +struct node *tree_create_cookie_node(struct node *parent, + const struct cookie_data *data); void tree_set_node_expanded(struct node *node, bool expanded); void tree_set_node_selected(struct tree *tree, struct node *node, bool selected); -- cgit v1.2.3