From fbfe5ab17ba41187bcbba5e759dd8e2e98a1b3e7 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Wed, 28 Aug 2013 11:43:34 +0100 Subject: Function for global history export. --- desktop/global_history.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++ desktop/global_history.h | 9 +++++ 2 files changed, 112 insertions(+) diff --git a/desktop/global_history.c b/desktop/global_history.c index 7432be284..6713fcab5 100644 --- a/desktop/global_history.c +++ b/desktop/global_history.c @@ -25,6 +25,8 @@ #include "desktop/treeview.h" #include "utils/messages.h" #include "utils/utils.h" +#include "utils/utf8.h" +#include "utils/libdom.h" #include "utils/log.h" #define N_DAYS 28 @@ -825,6 +827,107 @@ nserror global_history_add(nsurl *url) } +struct treeview_export_walk_ctx { + FILE *fp; +}; +/** Callback for treeview_walk node entering */ +static nserror global_history_export_enter_cb(void *ctx, void *node_data, + enum treeview_node_type type, bool *abort) +{ + struct treeview_export_walk_ctx *tw = ctx; + + if (type == TREE_NODE_ENTRY) { + struct global_history_entry *e = node_data; + utf8_convert_ret ret; + char *t_text; + char *u_text; + + ret = utf8_to_html(e->data[GH_TITLE].value, "iso-8859-1", + e->data[GH_TITLE].value_len, &t_text); + if (ret != UTF8_CONVERT_OK) + return NSERROR_SAVE_FAILED; + + ret = utf8_to_html(e->data[GH_URL].value, "iso-8859-1", + e->data[GH_URL].value_len, &u_text); + if (ret != UTF8_CONVERT_OK) { + free(t_text); + return NSERROR_SAVE_FAILED; + } + + fprintf(tw->fp, "
  • %s
  • \n", + u_text, t_text); + + free(t_text); + free(u_text); + + } else if (type == TREE_NODE_FOLDER) { + struct global_history_folder *f = node_data; + utf8_convert_ret ret; + char *f_text; + + ret = utf8_to_html(f->data.value, "iso-8859-1", + f->data.value_len, &f_text); + if (ret != UTF8_CONVERT_OK) + return NSERROR_SAVE_FAILED; + + fprintf(tw->fp, "
  • %s

    \n
  • \n", tw->fp); + } + + return NSERROR_OK; +} +/* Exported interface, documented in global_history.h */ +nserror global_history_export(const char *path, const char *title) +{ + struct treeview_export_walk_ctx tw; + nserror err; + FILE *fp; + + fp = fopen(path, "w"); + if (fp == NULL) + return NSERROR_SAVE_FAILED; + + if (title == NULL) + title = "NetSurf Browsing History"; + + fputs("\n", fp); + fputs("\n\n", fp); + fputs("\n", fp); + fprintf(fp, "%s\n", title); + fputs("\n\n\n\n\n", fp); + + fclose(fp); + + return NSERROR_OK; +} + + /* Exported interface, documented in global_history.h */ void global_history_redraw(int x, int y, struct rect *clip, const struct redraw_context *ctx) diff --git a/desktop/global_history.h b/desktop/global_history.h index 3863e8151..9d1dc4523 100644 --- a/desktop/global_history.h +++ b/desktop/global_history.h @@ -61,6 +61,15 @@ nserror global_history_fini(void); */ nserror global_history_add(nsurl *url); +/* + * Save global history to file (html) + * + * \param path The path to save history to + * \param title The title to give the document, or NULL for default + * \return NSERROR_OK on success, or appropriate error otherwise + */ +nserror global_history_export(const char *path, const char *title); + /** * Redraw the global history. * -- cgit v1.2.3