From 258fa23beaa5c6096dcd2081ccc5f3fa1e6e6f1e Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Mon, 6 Dec 2004 23:00:08 +0000 Subject: A data/epiphany-bookmarks-html.xsl: 2004-12-06 Christian Persch * 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. --- ChangeLog | 15 ++++ configure.ac | 3 + data/Makefile.am | 4 + data/epiphany-bookmarks-html.xsl | 77 ++++++++++++++++++ data/ui/epiphany-bookmark-editor-ui.xml | 1 + src/bookmarks/ephy-bookmarks-editor.c | 98 +++++++++++++++++++++++ src/bookmarks/ephy-bookmarks-export.c | 133 ++++++++++++++++++++++++++------ src/bookmarks/ephy-bookmarks-export.h | 3 + src/ephy-main.c | 1 + 9 files changed, 310 insertions(+), 25 deletions(-) create mode 100644 data/epiphany-bookmarks-html.xsl diff --git a/ChangeLog b/ChangeLog index 6b5e56d21..3b6b18493 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2004-12-06 Christian Persch + + * 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 * 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 @@ + + + + + + + + + + + + ]]> + + + + + Bookmarks +

Bookmarks

+
+ + + + + + + + +

+ + +
+
+ + + + +
+
+
+ + + + + +
+
+
+ + +
+ +
+ +
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 @@ + 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"), "W", N_("Close the bookmarks window"), G_CALLBACK (cmd_close) }, @@ -660,6 +666,88 @@ import_dialog_response_cb (GtkDialog *dialog, gint response, gtk_widget_destroy (GTK_WIDGET (dialog)); } +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 #include #include +#include +#include +#include #include #include @@ -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; -- cgit