diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2004-12-07 07:00:08 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2004-12-07 07:00:08 +0800 |
commit | 258fa23beaa5c6096dcd2081ccc5f3fa1e6e6f1e (patch) | |
tree | 0501dae900c657a595512dcfbaeeb452f55fb020 /src/bookmarks | |
parent | 7d41f0ac49c67d18ff6852f92f730c0929852790 (diff) | |
download | gsoc2013-epiphany-258fa23beaa5c6096dcd2081ccc5f3fa1e6e6f1e.tar gsoc2013-epiphany-258fa23beaa5c6096dcd2081ccc5f3fa1e6e6f1e.tar.gz gsoc2013-epiphany-258fa23beaa5c6096dcd2081ccc5f3fa1e6e6f1e.tar.bz2 gsoc2013-epiphany-258fa23beaa5c6096dcd2081ccc5f3fa1e6e6f1e.tar.lz gsoc2013-epiphany-258fa23beaa5c6096dcd2081ccc5f3fa1e6e6f1e.tar.xz gsoc2013-epiphany-258fa23beaa5c6096dcd2081ccc5f3fa1e6e6f1e.tar.zst gsoc2013-epiphany-258fa23beaa5c6096dcd2081ccc5f3fa1e6e6f1e.zip |
A data/epiphany-bookmarks-html.xsl:
2004-12-06 Christian Persch <chpe@cvs.gnome.org>
* configure.ac:
* data/Makefile.am:
A data/epiphany-bookmarks-html.xsl:
* data/ui/epiphany-bookmark-editor-ui.xml:
* src/bookmarks/ephy-bookmarks-editor.c: (cmd_bookmarks_export),
(ephy_bookmarks_editor_construct):
* src/bookmarks/ephy-bookmarks-export.c: (write_rdf),
(ephy_bookmarks_export_rdf), (ephy_bookmarks_export_mozilla):
* src/bookmarks/ephy-bookmarks-export.h:
* src/ephy-main.c: (main):
Add bookmarks export to bookmarks editor. Fixes bug #157745.
Diffstat (limited to 'src/bookmarks')
-rw-r--r-- | src/bookmarks/ephy-bookmarks-editor.c | 98 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks-export.c | 133 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks-export.h | 3 |
3 files changed, 209 insertions, 25 deletions
diff --git a/src/bookmarks/ephy-bookmarks-editor.c b/src/bookmarks/ephy-bookmarks-editor.c index babb883e7..556984c5a 100644 --- a/src/bookmarks/ephy-bookmarks-editor.c +++ b/src/bookmarks/ephy-bookmarks-editor.c @@ -47,6 +47,7 @@ #include "ephy-bookmarks-editor.h" #include "ephy-bookmarks-import.h" +#include "ephy-bookmarks-export.h" #include "ephy-node-common.h" #include "ephy-node-view.h" #include "ephy-window.h" @@ -113,6 +114,8 @@ static void cmd_bookmark_properties (GtkAction *action, EphyBookmarksEditor *editor); static void cmd_bookmarks_import (GtkAction *action, EphyBookmarksEditor *editor); +static void cmd_bookmarks_export (GtkAction *action, + EphyBookmarksEditor *editor); static void cmd_add_topic (GtkAction *action, EphyBookmarksEditor *editor); static void cmd_rename (GtkAction *action, @@ -189,6 +192,9 @@ static GtkActionEntry ephy_bookmark_popup_entries [] = { { "Import", NULL, N_("_Import Bookmarks..."), NULL, N_("Import bookmarks from another browser or a bookmarks file"), G_CALLBACK (cmd_bookmarks_import) }, + { "Export", NULL, N_("_Export Bookmarks..."), NULL, + N_("Export bookmarks to a file"), + G_CALLBACK (cmd_bookmarks_export) }, { "Close", GTK_STOCK_CLOSE, N_("_Close"), "<control>W", N_("Close the bookmarks window"), G_CALLBACK (cmd_close) }, @@ -661,6 +667,88 @@ import_dialog_response_cb (GtkDialog *dialog, gint response, } static void +cmd_bookmarks_export (GtkAction *action, + EphyBookmarksEditor *editor) +{ + GtkWidget *dialog, *hbox, *label, *combo; + char *filename = NULL; + int response, format; + + dialog = GTK_WIDGET (ephy_file_chooser_new (_("Export Bookmarks"), + GTK_WIDGET (editor), + GTK_FILE_CHOOSER_ACTION_SAVE, + NULL, + EPHY_FILE_FILTER_NONE)); + + gtk_file_chooser_set_current_folder + (GTK_FILE_CHOOSER (dialog), g_get_home_dir ()); + + gtk_file_chooser_set_current_name + (GTK_FILE_CHOOSER (dialog), _("Bookmarks")); + + /* Make a format selection combo & label */ + label = gtk_label_new (_("File format:")); + + combo = gtk_combo_box_new_text (); + gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Epiphany (RDF)")); + gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Mozilla (HTML)")); + gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 1); + + hbox = gtk_hbox_new (FALSE, 12); + gtk_box_pack_end (GTK_BOX (hbox), combo, TRUE, TRUE, 0); + gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0); + gtk_widget_show_all (hbox); + + gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog), hbox); + + gtk_window_group_add_window (GTK_WINDOW (editor)->group, GTK_WINDOW (dialog)); + + do + { + char *basename, *strtmp; + + g_free (filename); + + response = gtk_dialog_run (GTK_DIALOG (dialog)); + + format = gtk_combo_box_get_active (GTK_COMBO_BOX (combo)); + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); + basename = g_path_get_basename (filename); + if (basename != NULL && strchr (basename, '.') == NULL) + { + strtmp = filename; + if (format == 0) + { + filename = g_strconcat (filename, ".rdf", NULL); + } + else if (format == 1) + { + filename = g_strconcat (filename, ".html", NULL); + } + g_free (strtmp); + } + g_free (basename); + } + while (response == GTK_RESPONSE_ACCEPT + && !ephy_gui_confirm_overwrite_file (GTK_WIDGET (dialog), filename)); + + gtk_widget_destroy (dialog); + + /* 0 for ephy RDF format, 1 for mozilla HTML format */ + + if (format == 0) + { + ephy_bookmarks_export_rdf (editor->priv->bookmarks, filename); + } + else if (format == 1) + { + ephy_bookmarks_export_mozilla (editor->priv->bookmarks, filename); + } + + g_free (filename); +} + +static void cmd_bookmarks_import (GtkAction *action, EphyBookmarksEditor *editor) { @@ -1454,8 +1542,18 @@ ephy_bookmarks_editor_construct (EphyBookmarksEditor *editor) EphyNode *node; GtkUIManager *ui_merge; GtkActionGroup *action_group; + GtkWindowGroup *group; int col_id, details_value; + /* ensure window group */ + group = GTK_WINDOW (editor)->group; + if (group == NULL) + { + group = gtk_window_group_new (); + gtk_window_group_add_window (group, GTK_WINDOW (editor)); + g_object_unref (group); + } + gtk_window_set_title (GTK_WINDOW (editor), _("Bookmarks")); gtk_window_set_icon_name (GTK_WINDOW (editor), EPHY_STOCK_BOOKMARKS); diff --git a/src/bookmarks/ephy-bookmarks-export.c b/src/bookmarks/ephy-bookmarks-export.c index 72f5f05ae..4ff9e50e9 100644 --- a/src/bookmarks/ephy-bookmarks-export.c +++ b/src/bookmarks/ephy-bookmarks-export.c @@ -26,8 +26,12 @@ #include "ephy-file-helpers.h" #include "ephy-debug.h" +#include <libxml/globals.h> #include <libxml/tree.h> #include <libxml/xmlwriter.h> +#include <libxslt/xslt.h> +#include <libxslt/transform.h> +#include <libxslt/xsltutils.h> #include <libgnomevfs/gnome-vfs-uri.h> #include <libgnomevfs/gnome-vfs-utils.h> @@ -81,37 +85,18 @@ write_topics_list (EphyNode *topics, return ret >= 0 ? 0 : -1; } -void -ephy_bookmarks_export_rdf (EphyBookmarks *bookmarks, - const char *filename) +static int +write_rdf (EphyBookmarks *bookmarks, + const char *filename, + xmlTextWriterPtr writer) { EphyNode *bmks, *topics, *smart_bmks; - xmlTextWriterPtr writer; - char *tmp_file; GPtrArray *children; char *file_uri; int i, ret; - LOG ("Exporting as RDF to %s", filename) - - START_PROFILER ("Exporting as RDF") + START_PROFILER ("Writing RDF") - tmp_file = g_strconcat (filename, ".tmp", NULL); - - /* FIXME: do we want to turn on compression here? */ - writer = xmlNewTextWriterFilename (tmp_file, 0); - if (writer == NULL) - { - g_free (tmp_file); - return; - } - - ret = xmlTextWriterSetIndent (writer, 1); - if (ret < 0) goto out; - - ret = xmlTextWriterSetIndentString (writer, (xmlChar *) " "); - if (ret < 0) goto out; - ret = xmlTextWriterStartDocument (writer, "1.0", NULL, NULL); if (ret < 0) goto out; @@ -331,8 +316,44 @@ ephy_bookmarks_export_rdf (EphyBookmarks *bookmarks, ret = xmlTextWriterEndDocument (writer); out: - xmlFreeTextWriter (writer); + STOP_PROFILER ("Writing RDF") + + return ret; +} + +void +ephy_bookmarks_export_rdf (EphyBookmarks *bookmarks, + const char *filename) +{ + xmlTextWriterPtr writer; + char *tmp_file; + int ret; + + LOG ("Exporting as RDF to %s", filename) + START_PROFILER ("Exporting as RDF") + + tmp_file = g_strconcat (filename, ".tmp", NULL); + + /* FIXME: do we want to turn on compression here? */ + writer = xmlNewTextWriterFilename (tmp_file, 0); + if (writer == NULL) + { + g_free (tmp_file); + return; + } + + ret = xmlTextWriterSetIndent (writer, 1); + if (ret < 0) goto out; + + ret = xmlTextWriterSetIndentString (writer, (xmlChar *) " "); + if (ret < 0) goto out; + + ret = write_rdf (bookmarks, filename, writer); + if (ret < 0) goto out; + + xmlFreeTextWriter (writer); +out: if (ret >= 0) { if (ephy_file_switch_temp_file (filename, tmp_file) == FALSE) @@ -347,3 +368,65 @@ out: LOG ("Exporting as RDF %s.", ret >= 0 ? "succeeded" : "FAILED") } + +void +ephy_bookmarks_export_mozilla (EphyBookmarks *bookmarks, + const char *filename) +{ + xsltStylesheetPtr cur = NULL; + xmlTextWriterPtr writer; + xmlDocPtr doc = NULL, res; + char *tmp_file, *template; + int ret = -1; + + LOG ("Exporting as Mozilla to %s", filename) + + template = g_build_filename (g_get_tmp_dir (), + "export-bookmarks-XXXXXX", NULL); + tmp_file = ephy_file_tmp_filename (template, "rdf"); + g_free (template); + if (tmp_file == NULL) return; + + writer = xmlNewTextWriterDoc (&doc, 0); + if (writer == NULL || doc == NULL) + { + g_free (tmp_file); + return; + } + + START_PROFILER ("Exporting as Mozilla") + + ret = write_rdf (bookmarks, tmp_file, writer); + if (ret < 0) goto out; + + /* Set up libxml stuff */ + xmlLoadExtDtdDefaultValue = 1; + xmlSubstituteEntitiesDefault (1); + + cur = xsltParseStylesheetFile ((const xmlChar *) ephy_file ("epiphany-bookmarks-html.xsl")); + if (cur == NULL) goto out; + + res = xsltApplyStylesheet (cur, doc, NULL); + if (res == NULL) + { + xsltFreeStylesheet (cur); + goto out; + } + + ret = xsltSaveResultToFilename (filename, res, cur, FALSE); + + xsltFreeStylesheet (cur); + xmlFreeDoc (res); + + /* Clean up libxslt stuff */ + xsltCleanupGlobals (); + +out: + xmlFreeTextWriter (writer); + xmlFreeDoc (doc); + g_free (tmp_file); + + STOP_PROFILER ("Exporting as Mozilla") + + LOG ("Exporting as Mozilla %s.", ret >= 0 ? "succeeded" : "FAILED") +} diff --git a/src/bookmarks/ephy-bookmarks-export.h b/src/bookmarks/ephy-bookmarks-export.h index b0ee4a01a..9d41cbcbb 100644 --- a/src/bookmarks/ephy-bookmarks-export.h +++ b/src/bookmarks/ephy-bookmarks-export.h @@ -28,6 +28,9 @@ G_BEGIN_DECLS void ephy_bookmarks_export_rdf (EphyBookmarks *bookmarks, const char *filename); +void ephy_bookmarks_export_mozilla (EphyBookmarks *bookmarks, + const char *filename); + G_END_DECLS #endif |