Re: Yelp Lovin'



Here's yelp-print.patch.

Some of the other bits overlap.  Once this is in, I'll make a shortened
patch based on what's left.

The Print Document crashes on ff 1.0 and mozila 1.7.8, but probably
won't on ff 1.1.  Print page should work just fine on any mozilla.  If
anyone can figure out why this is happening, that'd be awesome.

Thanks,
   Chris

On Mon, 2005-07-11 at 02:09 -0500, Shaun McCance wrote:
> Attached is a patch I got from the venerable Chris Lahey.
> It implements search using Beagle, printing, and some weird
> collapsing TOC thing I haven't played with yet.
> 
> It's been sitting in my Inbox for over a week now.  You guys
> should play with it, then get back to me with three seperate
> patches that I can review individually.
> 
> If it happens REAL soon, one or more of these might have a
> chance of making it in before feature freeze.
> 
> --
> Shaun
> 
> 
> 
> _______________________________________________
> gnome-doc-devel-list mailing list
> gnome-doc-devel-list gnome org
> http://mail.gnome.org/mailman/listinfo/gnome-doc-devel-list
? yelp-print.patch
Index: data/ui/yelp-ui.xml
===================================================================
RCS file: /cvs/gnome/yelp/data/ui/yelp-ui.xml,v
retrieving revision 1.8
diff -u -p -p -u -r1.8 yelp-ui.xml
--- data/ui/yelp-ui.xml	2 Jan 2005 13:14:10 -0000	1.8
+++ data/ui/yelp-ui.xml	12 Jul 2005 02:16:39 -0000
@@ -6,6 +6,9 @@
       <separator/>
       <menuitem action="AboutDocument"/>
       <separator/>
+      <menuitem action="PrintPage"/>
+      <menuitem action="PrintDocument"/>
+      <separator/>
       <menuitem action="CloseWindow"/>
     </menu>
     <menu action="EditMenu">
Index: src/Makefile.am
===================================================================
RCS file: /cvs/gnome/yelp/src/Makefile.am,v
retrieving revision 1.83
diff -u -p -p -u -r1.83 Makefile.am
--- src/Makefile.am	16 May 2005 21:02:33 -0000	1.83
+++ src/Makefile.am	12 Jul 2005 02:16:39 -0000
@@ -7,6 +7,7 @@ yelp_SOURCES =							\
 	yelp-bookmarks.c 	yelp-bookmarks.h		\
 	yelp-cache.c		yelp-cache.h			\
 	yelp-db-pager.c		yelp-db-pager.h			\
+	yelp-db-print-pager.c	yelp-db-print-pager.h		\
 	yelp-error.c		yelp-error.h			\
 	yelp-gecko-utils.cpp	yelp-gecko-utils.h		\
 	yelp-html.cpp		yelp-html.h			\
@@ -101,6 +102,7 @@ test_man_parser_LDADD = $(YELP_LIBS) $(Z
 
 test_pager_SOURCES =						\
 	yelp-db-pager.c		yelp-db-pager.h			\
+	yelp-db-print-pager.c	yelp-db-print-pager.h		\
 	yelp-error.c		yelp-error.h			\
 	yelp-io-channel.c	yelp-io-channel.h		\
 	yelp-man-pager.c	yelp-man-pager.h		\
Index: src/yelp-db-print-pager.c
===================================================================
RCS file: src/yelp-db-print-pager.c
diff -N src/yelp-db-print-pager.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/yelp-db-print-pager.c	12 Jul 2005 02:16:39 -0000
@@ -0,0 +1,298 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2003 Shaun McCance  <shaunm gnome org>
+ *
+ * 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 of the
+ * License, 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.
+ *
+ * Author: Shaun McCance  <shaunm gnome org>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <libxml/parser.h>
+#include <libxml/parserInternals.h>
+#include <libxml/xinclude.h>
+#include <libxslt/xslt.h>
+#include <libxslt/templates.h>
+#include <libxslt/transform.h>
+#include <libxslt/extensions.h>
+#include <libxslt/xsltInternals.h>
+#include <libxslt/xsltutils.h>
+
+#include "yelp-error.h"
+#include "yelp-db-print-pager.h"
+#include "yelp-toc-pager.h"
+#include "yelp-settings.h"
+
+#ifdef YELP_DEBUG
+#define d(x) x
+#else
+#define d(x)
+#endif
+
+#define STYLESHEET_PATH DATADIR"/yelp/xslt/"
+#define DB_STYLESHEET   STYLESHEET_PATH"db2html.xsl"
+#define DB_TITLE        STYLESHEET_PATH"db-title.xsl"
+
+#define BOOK_CHUNK_DEPTH 2
+#define ARTICLE_CHUNK_DEPTH 1
+
+#define EVENTS_PENDING while (yelp_pager_get_state (pager) <= YELP_PAGER_STATE_RUNNING && gtk_events_pending ()) gtk_main_iteration ();
+#define CANCEL_CHECK if (!main_running || yelp_pager_get_state (pager) >= YELP_PAGER_STATE_ERROR) goto done;
+
+extern gboolean main_running;
+
+#define YELP_DB_PRINT_PAGER_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), YELP_TYPE_DB_PRINT_PAGER, YelpDBPrintPagerPriv))
+
+struct _YelpDBPrintPagerPriv {
+    gchar          *root_id;
+};
+
+static void           db_print_pager_class_init   (YelpDBPrintPagerClass *klass);
+static void           db_print_pager_init         (YelpDBPrintPager      *pager);
+static void           db_print_pager_dispose      (GObject          *gobject);
+
+static void           db_print_pager_cancel       (YelpPager        *pager);
+static xmlDocPtr      db_print_pager_parse        (YelpPager        *pager);
+static gchar **       db_print_pager_params       (YelpPager        *pager);
+
+static const gchar *  db_print_pager_resolve_frag (YelpPager        *pager,
+					     const gchar      *frag_id);
+static GtkTreeModel * db_print_pager_get_sections (YelpPager        *pager);
+
+static YelpPagerClass *parent_class;
+
+GType
+yelp_db_print_pager_get_type (void)
+{
+    static GType type = 0;
+
+    if (!type) {
+	static const GTypeInfo info = {
+	    sizeof (YelpDBPrintPagerClass),
+	    NULL,
+	    NULL,
+	    (GClassInitFunc) db_print_pager_class_init,
+	    NULL,
+	    NULL,
+	    sizeof (YelpDBPrintPager),
+	    0,
+	    (GInstanceInitFunc) db_print_pager_init,
+	};
+	type = g_type_register_static (YELP_TYPE_XSLT_PAGER,
+				       "YelpDBPrintPager", 
+				       &info, 0);
+    }
+    return type;
+}
+
+static void
+db_print_pager_class_init (YelpDBPrintPagerClass *klass)
+{
+    GObjectClass   *object_class = G_OBJECT_CLASS (klass);
+    YelpPagerClass *pager_class  = YELP_PAGER_CLASS (klass);
+    YelpXsltPagerClass *xslt_class = YELP_XSLT_PAGER_CLASS (klass);
+
+    parent_class = g_type_class_peek_parent (klass);
+
+    object_class->dispose = db_print_pager_dispose;
+
+    pager_class->cancel   = db_print_pager_cancel;
+
+    pager_class->resolve_frag = db_print_pager_resolve_frag;
+
+    xslt_class->parse  = db_print_pager_parse;
+    xslt_class->params = db_print_pager_params;
+
+    xslt_class->stylesheet = DB_STYLESHEET;
+
+    g_type_class_add_private (klass, sizeof (YelpDBPrintPagerPriv));
+}
+
+static void
+db_print_pager_init (YelpDBPrintPager *pager)
+{
+    YelpDBPrintPagerPriv *priv;
+
+    pager->priv = priv = YELP_DB_PRINT_PAGER_GET_PRIVATE (pager);
+
+    pager->priv->root_id = NULL;
+}
+
+static void
+db_print_pager_dispose (GObject *object)
+{
+    YelpDBPrintPager *pager = YELP_DB_PRINT_PAGER (object);
+
+    g_free (pager->priv->root_id);
+    g_free (pager->priv);
+
+    G_OBJECT_CLASS (parent_class)->dispose (object);
+}
+
+/******************************************************************************/
+
+YelpPager *
+yelp_db_print_pager_new (YelpDocInfo *doc_info)
+{
+    YelpDBPrintPager *pager;
+
+    g_return_val_if_fail (doc_info != NULL, NULL);
+
+    pager = (YelpDBPrintPager *) g_object_new (YELP_TYPE_DB_PRINT_PAGER,
+					  "document-info", doc_info,
+					  NULL);
+
+    return (YelpPager *) pager;
+}
+
+static xmlDocPtr
+db_print_pager_parse (YelpPager *pager)
+{
+    YelpDBPrintPagerPriv *priv;
+    YelpDocInfo     *doc_info;
+    gchar           *filename = NULL;
+
+    xmlParserCtxtPtr parserCtxt = NULL;
+    xmlDocPtr doc = NULL;
+
+    xmlChar     *id;
+    GError      *error = NULL;
+
+    d (g_print ("db_print_pager_parse\n"));
+
+    doc_info = yelp_pager_get_doc_info (pager);
+
+    g_return_val_if_fail (pager != NULL, NULL);
+    g_return_val_if_fail (YELP_IS_DB_PRINT_PAGER (pager), NULL);
+    priv = YELP_DB_PRINT_PAGER (pager)->priv;
+
+    g_object_ref (pager);
+
+    if (yelp_pager_get_state (pager) >= YELP_PAGER_STATE_ERROR)
+	goto done;
+
+    filename = yelp_doc_info_get_filename (doc_info);
+
+    parserCtxt = xmlNewParserCtxt ();
+    doc = xmlCtxtReadFile (parserCtxt,
+			   (const char *) filename, NULL,
+			   XML_PARSE_DTDLOAD | XML_PARSE_NOCDATA |
+			   XML_PARSE_NOENT   | XML_PARSE_NONET   );
+    if (doc == NULL) {
+	g_set_error (&error, YELP_ERROR, YELP_ERROR_NO_DOC,
+		     _("The file ‘%s’ could not be parsed. Either the file "
+		       "does not exist, or it is not well-formed XML."),
+		     filename);
+	yelp_pager_error (pager, error);
+	goto done;
+    }
+
+    xmlXIncludeProcessFlags (doc,
+			     XML_PARSE_DTDLOAD | XML_PARSE_NOCDATA |
+			     XML_PARSE_NOENT   | XML_PARSE_NONET   );
+
+
+    priv->root_id = g_strdup ("index");
+
+    EVENTS_PENDING;
+    CANCEL_CHECK;
+
+ done:
+    g_free (filename);
+
+    if (parserCtxt)
+	xmlFreeParserCtxt (parserCtxt);
+
+    g_object_unref (pager);
+
+    return doc;
+}
+
+static gchar **
+db_print_pager_params (YelpPager *pager)
+{
+    YelpDBPrintPagerPriv *priv;
+    YelpDocInfo     *doc_info;
+    gchar **params;
+    gint params_i = 0;
+    gint params_max = 20;
+
+    d (g_print ("db_print_pager_process\n"));
+
+    doc_info = yelp_pager_get_doc_info (pager);
+
+    g_return_val_if_fail (pager != NULL, FALSE);
+    g_return_val_if_fail (YELP_IS_DB_PRINT_PAGER (pager), FALSE);
+    priv = YELP_DB_PRINT_PAGER (pager)->priv;
+
+    if (yelp_pager_get_state (pager) >= YELP_PAGER_STATE_ERROR)
+	return NULL;
+
+    params = g_new0 (gchar *, params_max);
+
+    yelp_settings_params (&params, &params_i, &params_max);
+
+    if ((params_i + 10) >= params_max - 1) {
+	params_max += 20;
+	params = g_renew (gchar *, params, params_max);
+    }
+    params[params_i++] = "db.chunk.extension";
+    params[params_i++] = g_strdup ("\"\"");
+    params[params_i++] = "db.chunk.info_basename";
+    params[params_i++] = g_strdup ("\"x-yelp-titlepage\"");
+    params[params_i++] = "db.chunk.max_depth";
+    params[params_i++] = g_strdup_printf ("0");
+    params[params_i++] = "yelp.javascript";
+    params[params_i++] = g_strdup_printf ("\"%s\"", DATADIR "/yelp/yelp.js");
+
+    params[params_i] = NULL;
+
+    return params;
+}
+
+static void
+db_print_pager_cancel (YelpPager *pager)
+{
+    YelpDBPrintPagerPriv *priv = YELP_DB_PRINT_PAGER (pager)->priv;
+
+    d (g_print ("db_print_pager_cancel\n"));
+
+    yelp_pager_set_state (pager, YELP_PAGER_STATE_INVALID);
+
+    g_free (priv->root_id);
+    priv->root_id = NULL;
+
+    YELP_PAGER_CLASS (parent_class)->cancel (pager);
+}
+
+static const gchar *
+db_print_pager_resolve_frag (YelpPager *pager, const gchar *frag_id)
+{
+    YelpDBPrintPager  *db_print_pager;
+
+    g_return_val_if_fail (pager != NULL, NULL);
+    g_return_val_if_fail (YELP_IS_DB_PRINT_PAGER (pager), NULL);
+
+    db_print_pager = YELP_DB_PRINT_PAGER (pager);
+
+    return db_print_pager->priv->root_id;
+}
+
Index: src/yelp-db-print-pager.h
===================================================================
RCS file: src/yelp-db-print-pager.h
diff -N src/yelp-db-print-pager.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/yelp-db-print-pager.h	12 Jul 2005 02:16:39 -0000
@@ -0,0 +1,55 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2003 Shaun McCance  <shaunm gnome org>
+ *
+ * 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 of the
+ * License, 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.
+ *
+ * Author: Shaun McCance  <shaunm gnome org>
+ */
+
+#ifndef __YELP_DB_PRINT_PAGER_H__
+#define __YELP_DB_PRINT_PAGER_H__
+
+#include <glib-object.h>
+
+#include "yelp-pager.h"
+#include "yelp-xslt-pager.h"
+
+#define YELP_TYPE_DB_PRINT_PAGER         (yelp_db_print_pager_get_type ())
+#define YELP_DB_PRINT_PAGER(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), YELP_TYPE_DB_PRINT_PAGER, YelpDBPrintPager))
+#define YELP_DB_PRINT_PAGER_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST ((k), YELP_TYPE_DB_PRINT_PAGER, YelpDBPrintPagerClass))
+#define YELP_IS_DB_PRINT_PAGER(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), YELP_TYPE_DB_PRINT_PAGER))
+#define YELP_IS_DB_PRINT_PAGER_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), YELP_TYPE_DB_PRINT_PAGER))
+#define YELP_DB_PRINT_PAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), YELP_TYPE_DB_PRINT_PAGER, YelpDBPrintPagerClass))
+
+typedef struct _YelpDBPrintPager      YelpDBPrintPager;
+typedef struct _YelpDBPrintPagerClass YelpDBPrintPagerClass;
+typedef struct _YelpDBPrintPagerPriv  YelpDBPrintPagerPriv;
+
+struct _YelpDBPrintPager {
+    YelpXsltPager    parent;
+
+    YelpDBPrintPagerPriv *priv;
+};
+
+struct _YelpDBPrintPagerClass {
+    YelpXsltPagerClass   parent_class;
+};
+
+GType           yelp_db_print_pager_get_type     (void);
+YelpPager *     yelp_db_print_pager_new          (YelpDocInfo *doc_info);
+
+#endif /* __YELP_DB_PRINT_PAGER_H__ */
Index: src/yelp-html.cpp
===================================================================
RCS file: /cvs/gnome/yelp/src/yelp-html.cpp,v
retrieving revision 1.1
diff -u -p -p -u -r1.1 yelp-html.cpp
--- src/yelp-html.cpp	16 May 2005 21:02:33 -0000	1.1
+++ src/yelp-html.cpp	12 Jul 2005 02:16:39 -0000
@@ -34,6 +34,12 @@
 
 #include "Yelper.h"
 
+#include "gtkmozembed_internal.h"
+#include "nsIWebBrowserPrint.h"
+#include "nsIInterfaceRequestorUtils.h"
+
+#include <libgnome/gnome-init.h>
+
 #ifdef GNOME_ENABLE_DEBUG
 #define d(x) x
 #else
@@ -42,6 +48,9 @@
 
 #define YELP_HTML_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), YELP_TYPE_HTML, YelpHtmlPriv))
 
+#define MOZILLA_PROFILE_DIR  "/mozilla"
+#define MOZILLA_PROFILE_NAME "yelp"
+
 struct _YelpHtmlPriv {
     Yelper      *yelper;
     gchar       *base_uri;
@@ -51,6 +60,7 @@ struct _YelpHtmlPriv {
 static void      html_set_fonts          (void);
 static void      html_set_colors         (void);
 static void      html_set_a11y           (void);
+static void      open_new_window (GtkMozEmbed **newEmbed, guint chrome_mask);
 
 enum {
     URI_SELECTED,
@@ -120,6 +130,14 @@ html_realize (GtkWidget *widget)
 }
 
 static void
+html_new_window (GtkMozEmbed *embed,
+		 GtkMozEmbed **newEmbed,
+		 guint chrome_mask)
+{
+    open_new_window (newEmbed, chrome_mask);
+}
+
+static void
 html_init (YelpHtml *html)
 {
     YelpHtmlPriv  *priv;
@@ -197,6 +215,7 @@ html_class_init (YelpHtmlClass *klass)
     moz_embed_class->title = html_title;
     moz_embed_class->dom_mouse_down = html_dom_mouse_down;
     moz_embed_class->open_uri = html_open_uri;
+    moz_embed_class->new_window = html_new_window;
 
     klass->font_handler = 0;
 
@@ -305,7 +324,7 @@ yelp_html_write (YelpHtml *html, const g
      if (len == -1) len = strlen (data);
 
     d (g_print ("yelp_html_write\n"));
-    d (g_print ("  data = %i bytes\n", strlen (data)));
+    d (g_print ("  data = %*s\n", len, data));
     d (g_print ("  len  = %i\n", len));
 
     gtk_moz_embed_append_data (GTK_MOZ_EMBED (html),
@@ -385,6 +404,24 @@ yelp_html_select_all (YelpHtml *html)
     html->priv->yelper->DoCommand ("cmd_selectAll");
 }
 
+void
+yelp_html_print (YelpHtml *html)
+{
+    nsCOMPtr<nsIWebBrowser> webBrowser;
+
+    gtk_moz_embed_get_nsIWebBrowser  (GTK_MOZ_EMBED (html), getter_AddRefs(webBrowser));
+
+    if (webBrowser) {
+
+	nsCOMPtr<nsIWebBrowserPrint> print(do_GetInterface(webBrowser));
+
+	if (print) {
+	    /* FIXME: Deal with retval. */
+	    print->Print (nsnull, nsnull);
+	}
+    }
+}
+
 static void
 html_set_fonts (void)
 {
@@ -421,4 +458,123 @@ html_set_a11y (void)
 
     caret = yelp_settings_get_caret ();
     yelp_gecko_set_caret (caret);
+}
+
+static void
+new_window_orphan_cb (GtkMozEmbedSingle *moz_single,
+		      GtkMozEmbed **newEmbed,
+		      guint chrome_mask,
+		      gpointer user_data)
+{
+    open_new_window (newEmbed, chrome_mask);
+}
+
+void
+yelp_html_initialize (void)
+{
+    static gboolean initialized = FALSE;
+    GtkMozEmbedSingle *single;
+    char *profile_path;
+
+    if (initialized)
+	return;
+    initialized = TRUE;
+
+    /* get single */
+    single = gtk_moz_embed_single_get ();
+    if (single == NULL) {
+	g_warning ("Failed to get singleton embed object!\n");
+    }
+
+    /* allow creation of orphan windows */
+    g_signal_connect (G_OBJECT (single), "new_window_orphan",
+		      G_CALLBACK (new_window_orphan_cb),
+		      NULL);
+
+    profile_path = g_build_filename (g_get_home_dir (),
+				     GNOME_DOT_GNOME,
+				     "yelp.d",
+				     MOZILLA_PROFILE_DIR, 
+				     NULL);
+    gtk_moz_embed_set_profile_path (profile_path, MOZILLA_PROFILE_NAME);
+    g_free (profile_path);
+}
+
+static GtkMozEmbed *new_xul_dialog (void);
+
+static void
+xul_visibility_cb (GtkWidget *embed, gboolean visibility, GtkWidget *window)
+{
+    if (visibility) {
+	gtk_widget_show (window);
+    } else {
+	gtk_widget_hide (window);
+    }
+}
+
+static void
+xul_size_to_cb (GtkWidget *embed, gint width, gint height, gpointer dummy)
+{
+        gtk_widget_set_size_request (embed, width, height);
+}
+
+static void
+xul_new_window_cb (GtkMozEmbed *embed,
+                   GtkMozEmbed **retval,
+                   guint chrome_mask,
+                   gpointer dummy)
+{
+    g_assert (chrome_mask & GTK_MOZ_EMBED_FLAG_OPENASCHROME);
+
+    *retval = new_xul_dialog ();
+}
+
+static void
+xul_title_cb (GtkMozEmbed *embed,
+              GtkWindow *window)
+{
+    char *title;
+
+    title = gtk_moz_embed_get_title (embed);
+    gtk_window_set_title (window, title);
+    g_free (title);
+}
+
+static GtkMozEmbed *
+new_xul_dialog (void)
+{
+    GtkWidget *window, *embed;
+
+    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+    embed = gtk_moz_embed_new ();
+    gtk_widget_show (embed);
+    gtk_container_add (GTK_CONTAINER (window), embed);
+
+    g_signal_connect_object (embed, "destroy_browser",
+			     G_CALLBACK (gtk_widget_destroy),
+			     window, G_CONNECT_SWAPPED);
+    g_signal_connect_object (embed, "visibility",
+			     G_CALLBACK (xul_visibility_cb),
+			     window, (GConnectFlags) 0);
+    g_signal_connect_object (embed, "size_to",
+			     G_CALLBACK (xul_size_to_cb),
+			     NULL, (GConnectFlags) 0);
+    g_signal_connect_object (embed, "new_window",
+			     G_CALLBACK (xul_new_window_cb),
+			     NULL, (GConnectFlags) 0);
+    g_signal_connect_object (embed, "title",
+			     G_CALLBACK (xul_title_cb),
+			     window, (GConnectFlags) 0);
+
+    return GTK_MOZ_EMBED (embed);
+}
+
+static void
+open_new_window (GtkMozEmbed **newEmbed,
+		 guint chrome_mask)
+{
+    if (chrome_mask & GTK_MOZ_EMBED_FLAG_OPENASCHROME) {
+	*newEmbed = new_xul_dialog ();
+	return;
+    }
 }
Index: src/yelp-html.h
===================================================================
RCS file: /cvs/gnome/yelp/src/yelp-html.h,v
retrieving revision 1.30
diff -u -p -p -u -r1.30 yelp-html.h
--- src/yelp-html.h	16 May 2005 21:02:33 -0000	1.30
+++ src/yelp-html.h	12 Jul 2005 02:16:39 -0000
@@ -98,6 +98,10 @@ void            yelp_html_copy_selection
 
 void            yelp_html_select_all     (YelpHtml    *html);
 
+void            yelp_html_print          (YelpHtml    *html);
+
+void            yelp_html_initialize     (void);
+
 G_END_DECLS
 
 #endif /* __YELP_HTML_H__ */
Index: src/yelp-main.c
===================================================================
RCS file: /cvs/gnome/yelp/src/yelp-main.c,v
retrieving revision 1.38
diff -u -p -p -u -r1.38 yelp-main.c
--- src/yelp-main.c	6 Mar 2005 20:07:11 -0000	1.38
+++ src/yelp-main.c	12 Jul 2005 02:16:39 -0000
@@ -42,6 +42,7 @@
 #include "GNOME_Yelp.h"
 #include "yelp-window.h"
 #include "yelp-base.h"
+#include "yelp-html.h"
 
 #define YELP_FACTORY_OAFIID "OAFIID:GNOME_Yelp_Factory"
 
@@ -365,6 +366,8 @@ main (int argc, char **argv) 
 	if (!factory) { /* Not started, start now */ 
 		BonoboGenericFactory *factory;
 		char                 *registration_id;
+
+		yelp_html_initialize ();
 
 		registration_id = bonobo_activation_make_registration_id (
 					YELP_FACTORY_OAFIID,
Index: src/yelp-window.c
===================================================================
RCS file: /cvs/gnome/yelp/src/yelp-window.c,v
retrieving revision 1.172
diff -u -p -p -u -r1.172 yelp-window.c
--- src/yelp-window.c	16 May 2005 21:02:33 -0000	1.172
+++ src/yelp-window.c	12 Jul 2005 02:16:40 -0000
@@ -41,6 +41,7 @@
 
 #include "yelp-bookmarks.h"
 #include "yelp-db-pager.h"
+#include "yelp-db-print-pager.h"
 #include "yelp-error.h"
 #include "yelp-html.h"
 #include "yelp-pager.h"
@@ -155,6 +156,8 @@ static void    window_add_widget        
 					 GtkWidget    *vbox);
 static void    window_new_window_cb     (GtkAction *action, YelpWindow *window);
 static void    window_about_document_cb (GtkAction *action, YelpWindow *window);
+static void    window_print_document_cb (GtkAction *action, YelpWindow *window);
+static void    window_print_page_cb    (GtkAction *action, YelpWindow *window);
 static void    window_open_location_cb  (GtkAction *action, YelpWindow *window);
 static void    window_close_window_cb   (GtkAction *action, YelpWindow *window);
 static void    window_copy_cb           (GtkAction *action, YelpWindow *window);
@@ -294,6 +297,16 @@ static const GtkActionEntry entries[] = 
       "<Control>N",
       NULL,
       G_CALLBACK (window_new_window_cb) },
+    { "PrintDocument", NULL,
+      N_("Print This Document"),
+      NULL,
+      NULL,
+      G_CALLBACK (window_print_document_cb) },
+    { "PrintPage", NULL,
+      N_("Print This Page"),
+      NULL,
+      NULL,
+      G_CALLBACK (window_print_page_cb) },
     { "AboutDocument", NULL,
       N_("About This Document"),
       NULL,
@@ -1816,6 +1829,170 @@ window_new_window_cb (GtkAction *action,
     g_return_if_fail (YELP_IS_WINDOW (window));
 
     g_signal_emit (window, signals[NEW_WINDOW_REQUESTED], 0, NULL);
+}
+
+typedef struct {
+    gulong page_handler;
+    gulong error_handler;
+    gulong cancel_handler;
+    gulong finish_handler;
+    YelpPager *pager;
+} PrintStruct;
+
+static void
+print_disconnect (PrintStruct *data)
+{
+    if (data->page_handler) {
+	g_signal_handler_disconnect (data->pager,
+				     data->page_handler);
+	data->page_handler = 0;
+    }
+    if (data->error_handler) {
+	g_signal_handler_disconnect (data->pager,
+				     data->error_handler);
+	data->error_handler = 0;
+    }
+    if (data->cancel_handler) {
+	g_signal_handler_disconnect (data->pager,
+				     data->cancel_handler);
+	data->cancel_handler = 0;
+    }
+    if (data->finish_handler) {
+	g_signal_handler_disconnect (data->pager,
+				     data->finish_handler);
+	data->finish_handler = 0;
+    }
+    if (data) {
+	if (data->pager)
+	    g_object_unref (data->pager);
+    }
+    g_free (data);
+}
+
+static void
+print_pager_page_cb (YelpPager *pager,
+		     gchar     *page_id,
+		     gpointer   user_data)
+{
+    PrintStruct *data = user_data;
+    YelpPage    *page;
+
+    d (g_print ("print_pager_page_cb\n"));
+    d (g_print ("  page_id=\"%s\"\n", page_id));
+
+
+    page = (YelpPage *) yelp_pager_get_page (pager, page_id);
+
+    if (page) {
+	YelpHtml *html;
+	GtkWidget *gtk_window;
+	int length, offset;
+
+	d(g_print (page->contents));
+
+	gtk_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+	html = yelp_html_new ();
+	gtk_container_add (GTK_CONTAINER (gtk_window), GTK_WIDGET (html));
+	gtk_widget_realize (gtk_window);
+	gtk_widget_realize (GTK_WIDGET (html));
+
+
+	yelp_html_set_base_uri (html, page->page_id);
+	yelp_html_open_stream (html, "application/xhtml+xml");
+	for (length = strlen (page->contents), offset = 0; length > 0; length -= BUFFER_SIZE, offset += BUFFER_SIZE) {
+	    g_print ("data: %.*s\n", MIN (length, BUFFER_SIZE), page->contents + offset);
+	    yelp_html_write (html, page->contents + offset, MIN (length, BUFFER_SIZE));
+	}
+	yelp_html_close (html);
+
+	yelp_html_print (html);
+
+	print_disconnect (data);
+
+	/* This needs to be done at some point, but we need to wait until printing is done. */
+	/* gtk_widget_destroy (gtk_window); */
+    }
+}
+
+static void
+print_pager_error_cb (YelpPager   *pager,
+		      gpointer     user_data)
+{
+    PrintStruct *data = user_data;
+    /*     GError *error = yelp_pager_get_error (pager);*/
+
+    d (g_print ("print_pager_error_cb\n"));
+
+    print_disconnect (data);
+}
+
+static void
+print_pager_cancel_cb (YelpPager   *pager,
+		       gpointer     user_data)
+{
+    PrintStruct *data = user_data;
+    d (g_print ("print_pager_cancel_cb\n"));
+
+    print_disconnect (data);
+}
+
+static void
+print_pager_finish_cb (YelpPager   *pager,
+		       gpointer     user_data)
+{
+    PrintStruct *data = user_data;
+
+    d (g_print ("print_pager_finish_cb\n"));
+
+    print_disconnect (data);
+}
+
+static void
+window_print_document_cb (GtkAction *action, YelpWindow *window)
+{
+    PrintStruct *data;
+    YelpPager *pager;
+
+    if (!window->priv->current_doc)
+	return;
+
+    pager = yelp_db_print_pager_new (window->priv->current_doc);
+
+    if (!pager) {
+	return;
+    }
+
+    data = g_new0 (PrintStruct, 1);
+    data->pager = pager;
+
+    data->page_handler =
+	g_signal_connect (data->pager,
+			  "page",
+			  G_CALLBACK (print_pager_page_cb),
+			  data);
+    data->error_handler =
+	g_signal_connect (data->pager,
+			  "error",
+			  G_CALLBACK (print_pager_error_cb),
+			  data);
+    data->cancel_handler =
+	g_signal_connect (data->pager,
+			  "error",
+			  G_CALLBACK (print_pager_cancel_cb),
+			  data);
+    data->finish_handler =
+	g_signal_connect (data->pager,
+			  "finish",
+			  G_CALLBACK (print_pager_finish_cb),
+			  data);
+
+    /* handled = */ yelp_pager_start (data->pager);
+}
+
+static void
+window_print_page_cb (GtkAction *action, YelpWindow *window)
+{
+    yelp_html_print (window->priv->html_view);
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]