summaryrefslogtreecommitdiff
path: root/desktop/options.c
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2010-10-05 19:14:46 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2010-10-05 19:14:46 +0000
commit6173bb0e6c3bf51cd463f7bc4f725429d9087b2b (patch)
treede3e013699742960b97ee4a5eda240908d0ea8e6 /desktop/options.c
parent195c1ea3193f169c6825eca1fc6207e138126e98 (diff)
downloadnetsurf-6173bb0e6c3bf51cd463f7bc4f725429d9087b2b.tar.gz
netsurf-6173bb0e6c3bf51cd463f7bc4f725429d9087b2b.tar.bz2
Merge treeview-redux to trunk
svn path=/trunk/netsurf/; revision=10865
Diffstat (limited to 'desktop/options.c')
-rw-r--r--desktop/options.c363
1 files changed, 2 insertions, 361 deletions
diff --git a/desktop/options.c b/desktop/options.c
index 9ed8b192c..47b42dc3b 100644
--- a/desktop/options.c
+++ b/desktop/options.c
@@ -31,16 +31,10 @@
#include <stdio.h>
#include <string.h>
#include <strings.h>
-#include <libxml/HTMLparser.h>
-#include <libxml/HTMLtree.h>
-#include "content/urldb.h"
#include "css/css.h"
#include "desktop/options.h"
#include "desktop/plot_style.h"
-#include "desktop/tree.h"
#include "utils/log.h"
-#include "utils/messages.h"
-#include "utils/url.h"
#include "utils/utils.h"
#if defined(riscos)
@@ -145,6 +139,7 @@ unsigned int option_min_reflow_period = 100; /* time in cs */
#else
unsigned int option_min_reflow_period = 25; /* time in cs */
#endif
+char *option_tree_icons_dir = NULL;
bool option_core_select_menu = false;
/** top margin of exported page*/
int option_margin_top = DEFAULT_MARGIN_TOP_MM;
@@ -247,6 +242,7 @@ struct {
{ "scale", OPTION_INTEGER, &option_scale },
{ "incremental_reflow", OPTION_BOOL, &option_incremental_reflow },
{ "min_reflow_period", OPTION_INTEGER, &option_min_reflow_period },
+ { "tree_icons_dir", OPTION_STRING, &option_tree_icons_dir },
{ "core_select_menu", OPTION_BOOL, &option_core_select_menu },
/* Fetcher options */
{ "max_fetchers", OPTION_INTEGER, &option_max_fetchers },
@@ -276,13 +272,6 @@ struct {
#define option_table_entries (sizeof option_table / sizeof option_table[0])
-static void options_load_tree_directory(xmlNode *ul, struct node *directory);
-static void options_load_tree_entry(xmlNode *li, struct node *directory);
-xmlNode *options_find_tree_element(xmlNode *node, const char *name);
-bool options_save_tree_directory(struct node *directory, xmlNode *node);
-bool options_save_tree_entry(struct node *entry, xmlNode *node);
-
-
/**
* Read options from a file.
*
@@ -429,351 +418,3 @@ void options_dump(void)
fprintf(stderr, "\n");
}
}
-
-/**
- * Loads a hotlist as a tree from a specified file.
- *
- * \param filename name of file to read
- * \return the hotlist file represented as a tree, or NULL on failure
- */
-struct tree *options_load_tree(const char *filename) {
- xmlDoc *doc;
- xmlNode *html, *body, *ul;
- struct tree *tree;
-
- doc = htmlParseFile(filename, "iso-8859-1");
- if (!doc) {
- warn_user("HotlistLoadError", messages_get("ParsingFail"));
- return NULL;
- }
-
- html = options_find_tree_element((xmlNode *) doc, "html");
- body = options_find_tree_element(html, "body");
- ul = options_find_tree_element(body, "ul");
- if (!ul) {
- xmlFreeDoc(doc);
- warn_user("HotlistLoadError",
- "(<html>...<body>...<ul> not found.)");
- return NULL;
- }
-
- tree = calloc(sizeof(struct tree), 1);
- if (!tree) {
- xmlFreeDoc(doc);
- warn_user("NoMemory", 0);
- return NULL;
- }
- tree->root = tree_create_folder_node(NULL, "Root");
- if (!tree->root) {
- free(tree);
- xmlFreeDoc(doc);
-
- return NULL;
- }
-
- options_load_tree_directory(ul, tree->root);
- tree->root->expanded = true;
- tree_initialise(tree);
-
- xmlFreeDoc(doc);
- return tree;
-}
-
-
-/**
- * Parse a directory represented as a ul.
- *
- * \param ul xmlNode for parsed ul
- * \param directory directory to add this directory to
- */
-void options_load_tree_directory(xmlNode *ul, struct node *directory) {
- char *title;
- struct node *dir;
- xmlNode *n;
-
- assert(ul);
- assert(directory);
-
- for (n = ul->children; n; n = n->next) {
- /* The ul may contain entries as a li, or directories as
- * an h4 followed by a ul. Non-element nodes may be present
- * (eg. text, comments), and are ignored. */
-
- if (n->type != XML_ELEMENT_NODE)
- continue;
-
- if (strcmp((const char *) n->name, "li") == 0) {
- /* entry */
- options_load_tree_entry(n, directory);
-
- } else if (strcmp((const char *) n->name, "h4") == 0) {
- /* directory */
- title = (char *) xmlNodeGetContent(n);
- if (!title) {
- warn_user("HotlistLoadError", "(Empty <h4> "
- "or memory exhausted.)");
- return;
- }
-
- for (n = n->next;
- n && n->type != XML_ELEMENT_NODE;
- n = n->next)
- ;
- if (!n || strcmp((const char *) n->name, "ul") != 0) {
- /* next element isn't expected ul */
- free(title);
- warn_user("HotlistLoadError", "(Expected "
- "<ul> not present.)");
- return;
- }
-
- dir = tree_create_folder_node(directory, title);
- if (!dir) {
- free(title);
-
- return;
- }
- options_load_tree_directory(n, dir);
- }
- }
-}
-
-
-/**
- * Parse an entry represented as a li.
- *
- * \param li xmlNode for parsed li
- * \param directory directory to add this entry to
- */
-void options_load_tree_entry(xmlNode *li, struct node *directory) {
- char *url = NULL, *url1 = NULL;
- char *title = NULL;
- struct node *entry;
- xmlNode *n;
- const struct url_data *data;
- url_func_result res;
-
- for (n = li->children; n; n = n->next) {
- /* The li must contain an "a" element */
- if (n->type == XML_ELEMENT_NODE &&
- strcmp((const char *) n->name, "a") == 0) {
- url1 = (char *) xmlGetProp(n, (const xmlChar *) "href");
- title = (char *) xmlNodeGetContent(n);
- }
- }
-
- if (!url1 || !title) {
- warn_user("HotlistLoadError", "(Missing <a> in <li> or "
- "memory exhausted.)");
- return;
- }
-
- /* We're loading external input.
- * This may be garbage, so attempt to normalise
- */
- res = url_normalize(url1, &url);
- if (res != URL_FUNC_OK) {
- LOG(("Failed normalising '%s'", url1));
-
- if (res == URL_FUNC_NOMEM)
- warn_user("NoMemory", NULL);
-
- xmlFree(url1);
- xmlFree(title);
-
- return;
- }
-
- /* No longer need this */
- xmlFree(url1);
-
- data = urldb_get_url_data(url);
- if (!data) {
- /* No entry in database, so add one */
- urldb_add_url(url);
- /* now attempt to get url data */
- data = urldb_get_url_data(url);
- }
- if (!data) {
- xmlFree(title);
- free(url);
-
- return;
- }
-
- /* Make this URL persistent */
- urldb_set_url_persistence(url, true);
-
- if (!data->title)
- urldb_set_url_title(url, title);
-
- entry = tree_create_URL_node(directory, url, data, title);
- if (entry == NULL) {
- /** \todo why isn't this fatal? */
- warn_user("NoMemory", 0);
- }
-
- xmlFree(title);
- free(url);
-}
-
-
-/**
- * Search the children of an xmlNode for an element.
- *
- * \param node xmlNode to search children of, or 0
- * \param name name of element to find
- * \return first child of node which is an element and matches name, or
- * 0 if not found or parameter node is 0
- */
-xmlNode *options_find_tree_element(xmlNode *node, const char *name) {
- xmlNode *n;
- if (!node)
- return 0;
- for (n = node->children;
- n && !(n->type == XML_ELEMENT_NODE &&
- strcmp((const char *) n->name, name) == 0);
- n = n->next)
- ;
- return n;
-}
-
-
-/**
- * Perform a save to a specified file
- *
- * /param filename the file to save to
- */
-bool options_save_tree(struct tree *tree, const char *filename, const char *page_title) {
- int res;
- xmlDoc *doc;
- xmlNode *html, *head, *title, *body;
-
- /* Unfortunately the Browse Hotlist format is invalid HTML,
- * so this is a lie. */
- doc = htmlNewDoc(
- (const xmlChar *) "http://www.w3.org/TR/html4/strict.dtd",
- (const xmlChar *) "-//W3C//DTD HTML 4.01//EN");
- if (!doc) {
- warn_user("NoMemory", 0);
- return false;
- }
-
- html = xmlNewNode(NULL, (const xmlChar *) "html");
- if (!html) {
- warn_user("NoMemory", 0);
- xmlFreeDoc(doc);
- return false;
- }
- xmlDocSetRootElement(doc, html);
-
- head = xmlNewChild(html, NULL, (const xmlChar *) "head", NULL);
- if (!head) {
- warn_user("NoMemory", 0);
- xmlFreeDoc(doc);
- return false;
- }
-
- title = xmlNewTextChild(head, NULL, (const xmlChar *) "title",
- (const xmlChar *) page_title);
- if (!title) {
- warn_user("NoMemory", 0);
- xmlFreeDoc(doc);
- return false;
- }
-
- body = xmlNewChild(html, NULL, (const xmlChar *) "body", NULL);
- if (!body) {
- warn_user("NoMemory", 0);
- xmlFreeDoc(doc);
- return false;
- }
-
- if (!options_save_tree_directory(tree->root, body)) {
- warn_user("NoMemory", 0);
- xmlFreeDoc(doc);
- return false;
- }
-
- doc->charset = XML_CHAR_ENCODING_UTF8;
- res = htmlSaveFileEnc(filename, doc, "iso-8859-1");
- if (res == -1) {
- warn_user("HotlistSaveError", 0);
- xmlFreeDoc(doc);
- return false;
- }
-
- xmlFreeDoc(doc);
- return true;
-}
-
-
-/**
- * Add a directory to the HTML tree for saving.
- *
- * \param directory hotlist directory to add
- * \param node node to add ul to
- * \return true on success, false on memory exhaustion
- */
-bool options_save_tree_directory(struct node *directory, xmlNode *node) {
- struct node *child;
- xmlNode *ul, *h4;
-
- ul = xmlNewChild(node, NULL, (const xmlChar *) "ul", NULL);
- if (!ul)
- return false;
-
- for (child = directory->child; child; child = child->next) {
- if (!child->folder) {
- /* entry */
- if (!options_save_tree_entry(child, ul))
- return false;
- } else {
- /* directory */
- /* invalid HTML */
- h4 = xmlNewTextChild(ul, NULL,
- (const xmlChar *) "h4",
- (const xmlChar *) child->data.text);
- if (!h4)
- return false;
-
- if (!options_save_tree_directory(child, ul))
- return false;
- } }
-
- return true;
-}
-
-
-/**
- * Add an entry to the HTML tree for saving.
- *
- * The node must contain a sequence of node_elements in the following order:
- *
- * \param entry hotlist entry to add
- * \param node node to add li to
- * \return true on success, false on memory exhaustion
- */
-bool options_save_tree_entry(struct node *entry, xmlNode *node) {
- xmlNode *li, *a;
- xmlAttr *href;
- struct node_element *element;
-
- li = xmlNewChild(node, NULL, (const xmlChar *) "li", NULL);
- if (!li)
- return false;
-
- a = xmlNewTextChild(li, NULL, (const xmlChar *) "a",
- (const xmlChar *) entry->data.text);
- if (!a)
- return false;
-
- element = tree_find_element(entry, TREE_ELEMENT_URL);
- if (!element)
- return false;
- href = xmlNewProp(a, (const xmlChar *) "href",
- (const xmlChar *) element->text);
- if (!href)
- return false;
- return true;
-}