summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2006-04-09 23:21:13 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2006-04-09 23:21:13 +0000
commitc09eb457df1962f5b014214874b2beffd69141a4 (patch)
treea7c30e8b57b1d8bdeb87127c8f1ba16e91bf3971 /desktop
parente5e1b982d55636b409b194cf0488ebafe9c6d519 (diff)
downloadnetsurf-c09eb457df1962f5b014214874b2beffd69141a4.tar.gz
netsurf-c09eb457df1962f5b014214874b2beffd69141a4.tar.bz2
Unify information databases
svn path=/trunk/netsurf/; revision=2519
Diffstat (limited to 'desktop')
-rw-r--r--desktop/browser.c33
-rw-r--r--desktop/browser.h7
-rw-r--r--desktop/history_core.c6
-rw-r--r--desktop/options.c16
-rw-r--r--desktop/tree.c126
-rw-r--r--desktop/tree.h12
6 files changed, 104 insertions, 96 deletions
diff --git a/desktop/browser.c b/desktop/browser.c
index da6514e3d..7948ca9fa 100644
--- a/desktop/browser.c
+++ b/desktop/browser.c
@@ -23,7 +23,7 @@
#include "netsurf/utils/config.h"
#include "netsurf/content/fetch.h"
#include "netsurf/content/fetchcache.h"
-#include "netsurf/content/url_store.h"
+#include "netsurf/content/urldb.h"
#include "netsurf/css/css.h"
#ifdef WITH_AUTH
#include "netsurf/desktop/401login.h"
@@ -262,11 +262,9 @@ void browser_window_go_post(struct browser_window *bw, const char *url,
void browser_window_callback(content_msg msg, struct content *c,
intptr_t p1, intptr_t p2, union content_msg_data data)
{
- struct url_content *url_content;
struct browser_window *bw = (struct browser_window *) p1;
char status[40];
char url[256];
- char *title;
switch (msg) {
case CONTENT_MSG_LOADING:
@@ -327,21 +325,14 @@ void browser_window_callback(content_msg msg, struct content *c,
browser_window_set_status(bw, c->status_message);
if (bw->history_add) {
history_add(bw->history, c, bw->frag_id);
- url_content = url_store_find(c->url);
- if (url_content) {
- if (c->title)
- title = strdup(c->title);
- else
- title = strdup(c->url);
- if (title) {
- free(url_content->title);
- url_content->title = title;
- }
- url_content->visits++;
- url_content->last_visit = time(NULL);
- url_content->type = c->type;
- global_history_add(url_content);
- }
+ if (!urldb_add_url(c->url))
+ LOG(("urldb_add_url failed"));
+
+ urldb_set_url_title(c->url,
+ c->title ? c->title : c->url);
+ urldb_update_url_visit_data(c->url);
+ urldb_set_url_content_type(c->url, c->type);
+ global_history_add(c->url);
}
switch (c->type) {
case CONTENT_HTML:
@@ -846,11 +837,11 @@ void browser_window_mouse_action_html(struct browser_window *bw,
* box with scrollbars */
box = c->data.html.layout;
-
+
/* Consider the margins of the html page now */
box_x = box->margin[LEFT];
box_y = box->margin[TOP];
-
+
while ((next_box = box_at_point(box, x, y, &box_x, &box_y, &content)) !=
NULL) {
box = next_box;
@@ -2027,7 +2018,7 @@ struct box *browser_window_pick_text_box(struct browser_window *bw,
int box_x = 0, box_y = 0;
struct content *content;
struct box *next_box;
-
+
/* Consider the margins of the html page now */
box_x = box->margin[LEFT];
box_y = box->margin[TOP];
diff --git a/desktop/browser.h b/desktop/browser.h
index 1d1239cb0..8edc699a6 100644
--- a/desktop/browser.h
+++ b/desktop/browser.h
@@ -16,7 +16,6 @@
#include <stdbool.h>
#include <stddef.h>
#include <time.h>
-#include "netsurf/content/url_store.h"
struct box;
struct content;
@@ -27,6 +26,8 @@ struct gui_window;
struct history;
struct selection;
struct browser_window;
+struct url_data;
+struct bitmap;
typedef void (*browser_caret_callback)(struct browser_window *bw,
@@ -95,7 +96,7 @@ struct browser_window {
/** Current fetch is download */
bool download;
-
+
/** Refresh interval (-1 if undefined) */
int refresh_interval;
};
@@ -154,7 +155,7 @@ void browser_window_redraw_rect(struct browser_window *bw, int x, int y,
void hotlist_visited(struct content *content);
/* In platform specific global_history.c. */
-void global_history_add(struct url_content *data);
+void global_history_add(const char *url);
void global_history_add_recent(const char *url);
char **global_history_get_recent(int *count);
diff --git a/desktop/history_core.c b/desktop/history_core.c
index 67cee27ae..d851423f1 100644
--- a/desktop/history_core.c
+++ b/desktop/history_core.c
@@ -16,7 +16,7 @@
#include <string.h>
#include <time.h>
#include "netsurf/content/content.h"
-#include "netsurf/content/url_store.h"
+#include "netsurf/content/urldb.h"
#include "netsurf/css/css.h"
#include "netsurf/desktop/gui.h"
#include "netsurf/desktop/history_core.h"
@@ -115,7 +115,7 @@ void history_add(struct history *history, struct content *content,
struct history_entry *entry;
char *url;
char *title;
- struct bitmap *bitmap;
+ const struct bitmap *bitmap;
assert(history);
assert(content);
@@ -159,7 +159,7 @@ void history_add(struct history *history, struct content *content,
/* if we have a thumbnail, don't update until the page has finished
* loading */
- bitmap = url_store_get_thumbnail(url);
+ bitmap = urldb_get_thumbnail(url);
if (!bitmap) {
bitmap = bitmap_create(WIDTH, HEIGHT,
BITMAP_NEW | BITMAP_CLEAR_MEMORY |
diff --git a/desktop/options.c b/desktop/options.c
index 448bb78f7..58637f61e 100644
--- a/desktop/options.c
+++ b/desktop/options.c
@@ -21,6 +21,7 @@
#include <string.h>
#include "libxml/HTMLparser.h"
#include "libxml/HTMLtree.h"
+#include "netsurf/content/urldb.h"
#include "netsurf/css/css.h"
#include "netsurf/desktop/options.h"
#include "netsurf/desktop/tree.h"
@@ -92,7 +93,7 @@ char *option_homepage_url = 0;
/** Maximum simultaneous active fetchers */
int option_max_fetchers = 24;
/** Maximum simultaneous active fetchers per host.
- * (<=option_max_fetchers else it makes no sense
+ * (<=option_max_fetchers else it makes no sense
*/
int option_max_fetchers_per_host = 5;
/** Maximum number of inactive fetchers cached.
@@ -413,7 +414,7 @@ void options_load_tree_entry(xmlNode *li, struct node *directory) {
char *title = 0;
struct node *entry;
xmlNode *n;
- struct url_content *data;
+ const struct url_data *data;
for (n = li->children; n; n = n->next) {
/* The li must contain an "a" element */
@@ -430,12 +431,17 @@ void options_load_tree_entry(xmlNode *li, struct node *directory) {
return;
}
- data = url_store_find(url);
+ data = urldb_get_url_data(url);
+ if (!data)
+ /* No entry in database, so add one */
+ urldb_add_url(url);
+
+ data = urldb_get_url_data(url);
if (!data)
return;
if (!data->title)
- data->title = strdup(title);
- entry = tree_create_URL_node(directory, data, title);
+ urldb_set_url_title(url, title);
+ entry = tree_create_URL_node(directory, url, data, title);
xmlFree(url);
xmlFree(title);
}
diff --git a/desktop/tree.c b/desktop/tree.c
index 921ed8042..ae4821e3c 100644
--- a/desktop/tree.c
+++ b/desktop/tree.c
@@ -14,23 +14,25 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "netsurf/content/url_store.h"
+#include "netsurf/content/urldb.h"
#include "netsurf/desktop/tree.h"
#include "netsurf/desktop/options.h"
#include "netsurf/utils/log.h"
#include "netsurf/utils/utils.h"
-static void tree_draw_node(struct tree *tree, struct node *node, int clip_x, int clip_y,
- int clip_width, int clip_height);
-static struct node_element *tree_create_node_element(struct node *parent, node_element_data data);
+static void tree_draw_node(struct tree *tree, struct node *node, int clip_x,
+ int clip_y, int clip_width, int clip_height);
+static struct node_element *tree_create_node_element(struct node *parent,
+ node_element_data data);
static int tree_get_node_width(struct node *node);
static int tree_get_node_height(struct node *node);
-static void tree_handle_selection_area_node(struct tree *tree, struct node *node, int x, int y,
- int width, int height, bool invert);
+static void tree_handle_selection_area_node(struct tree *tree,
+ struct node *node, int x, int y, int width, int height,
+ bool invert);
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_move_processing_node(struct node *node, struct node *link,
+ bool before, bool first);
static int tree_initialising = 0;
@@ -873,55 +875,51 @@ void tree_delete_selected_nodes(struct tree *tree, struct node *node) {
void tree_delete_node(struct tree *tree, struct node *node, bool siblings) {
struct node *next;
struct node *parent;
- struct node_element *element;
- struct url_content *data;
+ struct node_element *e, *f;
assert(node);
- while (node) {
- if (tree->temp_selection == node)
- tree->temp_selection = NULL;
-
- next = node->next;
- if (node->child)
- tree_delete_node(tree, node->child, true);
- node->child = NULL;
- parent = node->parent;
- tree_delink_node(node);
- if (!node->retain_in_memory) {
- for (element = &node->data; element; element = element->next) {
- if (element->text) {
- /* we don't free non-editable titles or URLs */
- if ((node->editable) ||
- ((node->data.data != TREE_ELEMENT_TITLE) &&
- (node->data.data != TREE_ELEMENT_URL)))
- free(element->text);
- else if (node->data.data != TREE_ELEMENT_URL) {
+ if (tree->temp_selection == node)
+ tree->temp_selection = NULL;
+
+ next = node->next;
+ if (node->child)
+ tree_delete_node(tree, node->child, true);
+ node->child = NULL;
+ parent = node->parent;
+ tree_delink_node(node);
+
+ if (!node->retain_in_memory) {
+ for (e = &node->data; e; e = f) {
+ f = e->next;
+
+ if (e->text) {
+ /* we don't free non-editable titles */
+ if (node->editable)
+ free(e->text);
+ else {
+ if (e->data == TREE_ELEMENT_URL) {
/* reset URL characteristics */
- data = url_store_find(element->text);
- if (data) {
- data->last_visit = 0;
- data->visits = 0;
- }
+ urldb_reset_url_visit_data(e->text);
}
+
+ if (e->data != TREE_ELEMENT_TITLE)
+ free(e->text);
}
- if (element->sprite)
- free(element->sprite); /* \todo platform specific bits */
- }
- while (node->data.next) {
- element = node->data.next->next;
- free(node->data.next);
- node->data.next = element;
}
- free(node);
- } else {
- node->deleted = true;
+ if (e->sprite)
+ free(e->sprite); /* \todo platform specific bits */
+
+ if (e != &node->data)
+ free(e);
}
- if (!siblings)
- node = NULL;
- else
- node = next;
+ free(node);
+ } else {
+ node->deleted = true;
}
+ if (siblings)
+ tree_delete_node(tree, next, true);
+
tree_recalculate_node_positions(tree->root);
tree_redraw_area(tree, 0, 0, 16384, 16384); /* \todo correct area */
tree_recalculate_size(tree);
@@ -986,11 +984,13 @@ struct node *tree_create_leaf_node(struct node *parent, const char *title) {
*
*
* \param parent the node to link to
+ * \param url the URL (copied)
* \param data the URL data to use
* \param title the custom title to use
* \return the node created, or NULL for failure
*/
-struct node *tree_create_URL_node(struct node *parent, struct url_content *data,
+struct node *tree_create_URL_node(struct node *parent,
+ const char *url, const struct url_data *data,
const char *title) {
struct node *node;
struct node_element *element;
@@ -998,10 +998,10 @@ struct node *tree_create_URL_node(struct node *parent, struct url_content *data,
assert(data);
if (!title) {
- if (data->title)
- title = strdup(data->title);
- else
- title = strdup(data->url);
+ if (data->title)
+ title = strdup(data->title);
+ else
+ title = strdup(url);
if (!title)
return NULL;
}
@@ -1017,9 +1017,9 @@ struct node *tree_create_URL_node(struct node *parent, struct url_content *data,
tree_create_node_element(node, TREE_ELEMENT_LAST_VISIT);
element = tree_create_node_element(node, TREE_ELEMENT_URL);
if (element)
- element->text = strdup(data->url);
+ element->text = strdup(url);
- tree_update_URL_node(node, NULL);
+ tree_update_URL_node(node, url, NULL);
tree_recalculate_node(node, false);
return node;
@@ -1029,24 +1029,30 @@ struct node *tree_create_URL_node(struct node *parent, struct url_content *data,
/**
* Creates a tree entry for a URL, and links it into the tree.
*
- * All information is used directly from the url_content, and as such cannot be
+ * 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 (copied)
* \param data the URL data to use
* \return the node created, or NULL for failure
*/
-struct node *tree_create_URL_node_shared(struct node *parent, struct url_content *data) {
+struct node *tree_create_URL_node_shared(struct node *parent,
+ const char *url, const struct url_data *data) {
struct node *node;
struct node_element *element;
char *title;
assert(data);
+ /* If title isn't set, set it to the URL */
+ if (!data->title)
+ urldb_set_url_title(url, url);
+
if (data->title)
title = data->title;
else
- title = data->url;
+ return NULL;
node = tree_create_leaf_node(parent, title);
if (!node)
return NULL;
@@ -1061,9 +1067,9 @@ struct node *tree_create_URL_node_shared(struct node *parent, struct url_content
tree_create_node_element(node, TREE_ELEMENT_LAST_VISIT);
element = tree_create_node_element(node, TREE_ELEMENT_URL);
if (element)
- element->text = data->url;
+ element->text = strdup(url);
- tree_update_URL_node(node, data);
+ tree_update_URL_node(node, url, data);
tree_recalculate_node(node, false);
return node;
diff --git a/desktop/tree.h b/desktop/tree.h
index b5a73089d..ddfd5f6d3 100644
--- a/desktop/tree.h
+++ b/desktop/tree.h
@@ -13,7 +13,8 @@
#define _NETSURF_DESKTOP_TREE_H_
#include <stdbool.h>
-#include "netsurf/content/url_store.h"
+
+struct url_data;
typedef enum {
TREE_ELEMENT_URL,
@@ -117,9 +118,11 @@ 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, struct url_content *data,
+struct node *tree_create_URL_node(struct node *parent,
+ const char *url, const struct url_data *data,
const char *title);
-struct node *tree_create_URL_node_shared(struct node *parent, struct url_content *data);
+struct node *tree_create_URL_node_shared(struct node *parent,
+ const char *url, const struct url_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);
@@ -142,7 +145,8 @@ void tree_draw_line(int x, int y, int width, int height);
void tree_draw_node_element(struct tree *tree, struct node_element *element);
void tree_draw_node_expansion(struct tree *tree, struct node *node);
void tree_recalculate_node_element(struct node_element *element);
-void tree_update_URL_node(struct node *node, struct url_content *data);
+void tree_update_URL_node(struct node *node, const char *url,
+ const struct url_data *data);
void tree_resized(struct tree *tree);
void tree_set_node_sprite_folder(struct node *node);