From f53f3523ebc7a082eb8a1c046cee836b67696912 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Mon, 03 Jan 2005 13:43:31 +0000 Subject: Initial support for document title. Not working yet. 2005-01-03 Marco Pesenti Gritti * backend/ev-document.c: (ev_document_get_type), (ev_document_class_init), (ev_document_load), (ev_document_get_title): * backend/ev-document.h: * pdf/xpdf/pdf-document.cc: * ps/ps-document.c: (ps_document_set_property), (ps_document_get_property), (ps_document_class_init), (document_load): * ps/ps-document.h: * ps/ps.h: * shell/ev-window.c: (update_window_title), (ev_window_open), (ev_window_init): Initial support for document title. Not working yet. --- diff --git a/ChangeLog b/ChangeLog index 8f75e58..1ce27d4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2005-01-03 Marco Pesenti Gritti + + * backend/ev-document.c: (ev_document_get_type), + (ev_document_class_init), (ev_document_load), + (ev_document_get_title): + * backend/ev-document.h: + * pdf/xpdf/pdf-document.cc: + * ps/ps-document.c: (ps_document_set_property), + (ps_document_get_property), (ps_document_class_init), + (document_load): + * ps/ps-document.h: + * ps/ps.h: + * shell/ev-window.c: (update_window_title), (ev_window_open), + (ev_window_init): + + Initial support for document title. Not working yet. + 2005-01-02 Marco Pesenti Gritti * shell/ev-view.c: (ev_view_realize), (ev_view_button_press_event): diff --git a/backend/ev-document.c b/backend/ev-document.c index dcc6204..a76a555 100644 --- a/backend/ev-document.c +++ b/backend/ev-document.c @@ -23,7 +23,7 @@ #include "ev-document.h" #include "ev-backend-marshalers.h" -static void ev_document_base_init (gpointer g_class); +static void ev_document_class_init (gpointer g_class); enum { @@ -43,8 +43,9 @@ ev_document_get_type (void) static const GTypeInfo our_info = { sizeof (EvDocumentIface), - ev_document_base_init, NULL, + NULL, + (GClassInitFunc)ev_document_class_init }; type = g_type_register_static (G_TYPE_INTERFACE, @@ -56,24 +57,23 @@ ev_document_get_type (void) } static void -ev_document_base_init (gpointer g_class) +ev_document_class_init (gpointer g_class) { - static gboolean initialized = FALSE; - - if (!initialized) - { - signals[CHANGED] = - g_signal_new ("changed", - EV_TYPE_DOCUMENT, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EvDocumentIface, changed), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - initialized = TRUE; - } + signals[CHANGED] = + g_signal_new ("changed", + EV_TYPE_DOCUMENT, + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (EvDocumentIface, changed), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); + + g_object_interface_install_property (g_class, + g_param_spec_string ("title", + "Document Title", + "The title of the document", + NULL, 0)); } gboolean @@ -85,6 +85,16 @@ ev_document_load (EvDocument *document, return iface->load (document, uri, error); } +char * +ev_document_get_title (EvDocument *document) +{ + char *title; + + g_object_get (document, "title", &title, NULL); + + return title; +} + int ev_document_get_n_pages (EvDocument *document) { diff --git a/backend/ev-document.h b/backend/ev-document.h index 0059fd4..84b9e97 100644 --- a/backend/ev-document.h +++ b/backend/ev-document.h @@ -75,6 +75,7 @@ GType ev_document_get_type (void); gboolean ev_document_load (EvDocument *document, const char *uri, GError **error); +char *ev_document_get_title (EvDocument *document); int ev_document_get_n_pages (EvDocument *document); void ev_document_set_page (EvDocument *document, int page); diff --git a/pdf/xpdf/pdf-document.cc b/pdf/xpdf/pdf-document.cc index 24e0b36..ede8f77 100644 --- a/pdf/xpdf/pdf-document.cc +++ b/pdf/xpdf/pdf-document.cc @@ -17,6 +17,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include + #include "gpdf-g-switch.h" #include "pdf-document.h" #include "ev-ps-exporter.h" @@ -32,6 +34,11 @@ #include "goo/GList.h" #include "PSOutputDev.h" +enum { + PROP_0, + PROP_TITLE +}; + typedef struct { PdfDocument *document; @@ -177,6 +184,8 @@ pdf_document_load (EvDocument *document, pdf_document->page_valid = FALSE; + g_object_notify (G_OBJECT (pdf_document), "title"); + return TRUE; } @@ -858,11 +867,98 @@ pdf_document_finalize (GObject *object) } static void +pdf_document_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (prop_id) + + { + case PROP_TITLE: + /* read only */ + break; + } +} + +static gboolean +has_unicode_marker (GString *string) +{ + return ((string->getChar (0) & 0xff) == 0xfe && + (string->getChar (1) & 0xff) == 0xff); +} + +static gchar * +pdf_info_dict_get_string (Dict *info_dict, const gchar *key) { + Object obj; + GString *value; + gchar *result; + + g_return_val_if_fail (info_dict != NULL, NULL); + g_return_val_if_fail (key != NULL, NULL); + + if (!info_dict->lookup ((gchar *)key, &obj)->isString ()) { + obj.free (); + return g_strdup (_("Unknown")); + } + + value = obj.getString (); + + if (has_unicode_marker (value)) { + result = g_convert (value->getCString () + 2, + value->getLength () - 2, + "UTF-8", "UTF-16BE", NULL, NULL, NULL); + } else { + result = g_strndup (value->getCString (), value->getLength ()); + } + + obj.free (); + + return result; +} + +static char * +pdf_document_get_title (PdfDocument *pdf_document) +{ + char *title; + Object info; + + pdf_document->doc->getDocInfo (&info); + + if (info.isDict ()) { + title = pdf_info_dict_get_string (info.getDict(), "Title"); + } +} + +static void +pdf_document_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + PdfDocument *pdf_document = PDF_DOCUMENT (object); + char *title; + + switch (prop_id) + { + case PROP_TITLE: + title = pdf_document_get_title (pdf_document); + g_value_set_string (value, title); + g_free (title); + break; + } +} + +static void pdf_document_class_init (PdfDocumentClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); gobject_class->finalize = pdf_document_finalize; + gobject_class->get_property = pdf_document_get_property; + gobject_class->set_property = pdf_document_set_property; + + g_object_class_override_property (gobject_class, PROP_TITLE, "title"); } static void diff --git a/ps/ps-document.c b/ps/ps-document.c index 7619f03..09e4ef3 100644 --- a/ps/ps-document.c +++ b/ps/ps-document.c @@ -149,9 +149,7 @@ The DONE message indicates that ghostscript has finished processing. #include #include -#include "ev-document.h" #include "ps-document.h" -#include "ps.h" #include "gsdefaults.h" #ifdef HAVE_LOCALE_H @@ -175,6 +173,11 @@ The DONE message indicates that ghostscript has finished processing. enum { INTERPRETER_MESSAGE, INTERPRETER_ERROR, LAST_SIGNAL }; +enum { + PROP_0, + PROP_TITLE +}; + /* structure to describe section of file to send to ghostscript */ struct record_list { FILE *fp; @@ -283,6 +286,41 @@ ps_document_init(PSDocument * gs) } static void +ps_document_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (prop_id) + + { + case PROP_TITLE: + /* read only */ + break; + } +} + +static void +ps_document_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + PSDocument *ps = PS_DOCUMENT (object); + + switch (prop_id) + { + case PROP_TITLE: + if (ps->doc) { + g_value_set_string (value, ps->doc->title); + } else { + g_value_set_string (value, NULL); + } + break; + } +} + +static void ps_document_class_init(PSDocumentClass * klass) { GObjectClass *object_class; @@ -292,6 +330,8 @@ ps_document_class_init(PSDocumentClass * klass) gs_class = klass; object_class->finalize = ps_document_finalize; + object_class->get_property = ps_document_get_property; + object_class->set_property = ps_document_set_property; /* Create atoms */ klass->gs_atom = gdk_atom_intern("GHOSTVIEW", FALSE); @@ -300,6 +340,8 @@ ps_document_class_init(PSDocumentClass * klass) klass->string_atom = gdk_atom_intern("STRING", FALSE); gtk_gs_defaults_load(); + + g_object_class_override_property (object_class, PROP_TITLE, "title"); } /* Clean all memory and temporal files */ @@ -1296,6 +1338,8 @@ document_load(PSDocument * gs, const gchar * fname) /* we grab the vital statistics!!! */ gs->doc = psscan(gs->gs_psfile, gs->respect_eof, filename); + g_object_notify (G_OBJECT (gs), "title"); + if(gs->doc == NULL) { /* File does not seem to be a Postscript one */ gchar buf[1024]; diff --git a/ps/ps-document.h b/ps/ps-document.h index fd7e811..dd5555e 100644 --- a/ps/ps-document.h +++ b/ps/ps-document.h @@ -24,17 +24,10 @@ #ifndef __PS_DOCUMENT_H__ #define __PS_DOCUMENT_H__ -#include -#include - -#include - -#include -#include -#include #include -#include +#include "ev-document.h" +#include "ps.h" #include "gstypes.h" G_BEGIN_DECLS diff --git a/ps/ps.h b/ps/ps.h index b7bcda7..09039f1 100644 --- a/ps/ps.h +++ b/ps/ps.h @@ -28,6 +28,7 @@ #include #include +#include G_BEGIN_DECLS diff --git a/shell/ev-window.c b/shell/ev-window.c index 19394f5..19c6734 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -249,6 +249,24 @@ mime_type_supported_by_gdk_pixbuf (const gchar *mime_type) return retval; } +static void +update_window_title (EvDocument *document, GParamSpec *pspec, EvWindow *ev_window) +{ + char *title = NULL; + + if (document) { + title = ev_document_get_title (document); + } + + if (title == NULL) { + title = g_strdup (_("Document Viewer")); + } + + gtk_window_set_title (GTK_WINDOW (ev_window), title); + + g_free (title); +} + void ev_window_open (EvWindow *ev_window, const char *uri) { @@ -279,6 +297,11 @@ ev_window_open (EvWindow *ev_window, const char *uri) ev_sidebar_set_document (EV_SIDEBAR (ev_window->priv->sidebar), document); + g_signal_connect_object (G_OBJECT (document), + "notify::title", + G_CALLBACK (update_window_title), + ev_window, 0); + update_action_sensitivity (ev_window); } else { @@ -1150,7 +1173,7 @@ ev_window_init (EvWindow *ev_window) ev_window->priv = EV_WINDOW_GET_PRIVATE (ev_window); - gtk_window_set_title (GTK_WINDOW (ev_window), _("Document Viewer")); + update_window_title (NULL, NULL, ev_window); ev_window->priv->main_box = gtk_vbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (ev_window), ev_window->priv->main_box); -- cgit v0.9.1