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 | |
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.
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | configure.ac | 3 | ||||
-rw-r--r-- | data/Makefile.am | 4 | ||||
-rw-r--r-- | data/epiphany-bookmarks-html.xsl | 77 | ||||
-rw-r--r-- | data/ui/epiphany-bookmark-editor-ui.xml | 1 | ||||
-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 | ||||
-rw-r--r-- | src/ephy-main.c | 1 |
9 files changed, 310 insertions, 25 deletions
@@ -1,3 +1,18 @@ +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. + 2004-12-04 Christian Persch <chpe@cvs.gnome.org> * embed/mozilla/Makefile.am: diff --git a/configure.ac b/configure.ac index efd499dda..c42bb17ca 100644 --- a/configure.ac +++ b/configure.ac @@ -46,6 +46,7 @@ GLIB_REQUIRED=2.5.6 PANGO_REQUIRED=1.6.0 GTK_REQUIRED=2.5.5 LIBXML_REQUIRED=2.6.12 +LIBXSLT_REQUIRED=1.1.7 LIBGNOMEVFS_REQUIRED=2.3.1 LIBGLADE_REQUIRED=2.3.1 LIBGNOMEUI_REQUIRED=2.6.0 @@ -54,6 +55,7 @@ AC_SUBST([GLIB_REQUIRED]) AC_SUBST([PANGO_REQUIRED]) AC_SUBST([GTK_REQUIRED]) AC_SUBST([LIBXML_REQUIRED]) +AC_SUBST([LIBXSLT_REQUIRED]) AC_SUBST([LIBGNOMEVFS_REQUIRED]) AC_SUBST([LIBGLADE_REQUIRED]) AC_SUBST([LIBGNOMEUI_REQUIRED]) @@ -86,6 +88,7 @@ PKG_CHECK_MODULES([EPIPHANY_DEPENDENCY], [\ pango >= $PANGO_REQUIRED \ gtk+-2.0 >= $GTK_REQUIRED \ libxml-2.0 >= $LIBXML_REQUIRED \ + libxslt >= $LIBXSLT_REQUIRED \ libgnomeui-2.0 >= $LIBGNOMEUI_REQUIRED \ libglade-2.0 >= $LIBGLADE_REQUIRED \ bonobo-activation-2.0 \ diff --git a/data/Makefile.am b/data/Makefile.am index a25c35847..556406e22 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -3,6 +3,7 @@ SUBDIRS = ui art glade @INTLTOOL_SERVER_RULE@ @INTLTOOL_DESKTOP_RULE@ @INTLTOOL_SCHEMAS_RULE@ +@INTLTOOL_XML_RULE@ default_prefs_in_FILES = \ default-prefs-common.js \ @@ -44,6 +45,9 @@ mimepermission_DATA = mime-types-permissions.xml pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = epiphany-1.6.pc +xsldir = $(pkgdatadir) +xsl_DATA = epiphany-bookmarks-html.xsl + install-data-local: if GCONF_SCHEMAS_INSTALL if test -z "$(DESTDIR)" ; then \ diff --git a/data/epiphany-bookmarks-html.xsl b/data/epiphany-bookmarks-html.xsl new file mode 100644 index 000000000..8caac7d38 --- /dev/null +++ b/data/epiphany-bookmarks-html.xsl @@ -0,0 +1,77 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xsl:stylesheet version="1.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:purl="http://purl.org/rss/1.0/" + xmlns:dc="http://purl.org/dc/elements/1.1/" + exclude-result-prefixes="dc purl rdf"> +<!-- +Copyright (C) 2004 Stefan Rotsch + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +$Id$ +--> +<xsl:output method="html" encoding="UTF-8" indent="yes" /> + +<!-- Create a key assigning an item's topic to each item --> +<xsl:key name="topics" match="purl:item" use="dc:subject" /> + +<xsl:template match="rdf:RDF"> + + <!-- Generate DTD --> + <xsl:text disable-output-escaping="yes"><![CDATA[<!DOCTYPE NETSCAPE-Bookmark-file-1>]]> +</xsl:text> + + <!-- Page header and title --> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <title>Bookmarks</title> + <h1>Bookmarks</h1> + <dl> + + <!-- Items with Topics assigned will be processed first --> + <xsl:for-each select="purl:item[count(. | key('topics', dc:subject)[1]) = 1]"> + <xsl:sort select="dc:subject" /> + + <!-- Test if a topic is assigned --> + <xsl:if test="dc:subject"> + + <dt><h3><xsl:value-of select="dc:subject" /></h3><dl> + <xsl:for-each select="key('topics', dc:subject)"> + <xsl:sort select="purl:title" /> + <dt><a href="{./purl:link}"><xsl:value-of select="./purl:title" /></a></dt> + </xsl:for-each> + + <!-- Force a linebreak; otherwise thinks will break for Topics with only 1 item --> + <xsl:text> + </xsl:text> + </dl></dt> + </xsl:if> + </xsl:for-each> + + <!-- Now Bookmarks without topics will be added at the bottom of the output file --> + <xsl:for-each select="purl:item"> + <xsl:sort select="./purl:title" /> + <xsl:if test="not(dc:subject)"> + <dt><a href="{./purl:link}"><xsl:value-of select="./purl:title" /></a></dt> + </xsl:if> + </xsl:for-each> + + <!-- Closing tag of outer dl --> + </dl> + +</xsl:template> + +</xsl:stylesheet> diff --git a/data/ui/epiphany-bookmark-editor-ui.xml b/data/ui/epiphany-bookmark-editor-ui.xml index 15a48f544..9002767bf 100644 --- a/data/ui/epiphany-bookmark-editor-ui.xml +++ b/data/ui/epiphany-bookmark-editor-ui.xml @@ -14,6 +14,7 @@ <menuitem name="FileProperties" action="Properties"/> <separator name="FileSep4"/> <menuitem name="FileImport" action="Import"/> + <menuitem name="FileExport" action="Export"/> <separator name="FileSep5"/> <menuitem name="FileClose" action="Close"/> </menu> 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 diff --git a/src/ephy-main.c b/src/ephy-main.c index da9907fad..3bb38481e 100644 --- a/src/ephy-main.c +++ b/src/ephy-main.c @@ -196,6 +196,7 @@ main (int argc, char *argv[]) ephy_state_save (); ephy_file_helpers_shutdown (); gnome_vfs_shutdown (); + xmlCleanupParser (); poptFreeContext (context); return 0; |