]> www.fi.muni.cz Git - evince.git/commitdiff
Initial support for document title. Not working yet.
authorMarco Pesenti Gritti <marco@gnome.org>
Mon, 3 Jan 2005 13:43:31 +0000 (13:43 +0000)
committerMarco Pesenti Gritti <marco@src.gnome.org>
Mon, 3 Jan 2005 13:43:31 +0000 (13:43 +0000)
2005-01-03  Marco Pesenti Gritti  <marco@gnome.org>

        * 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.

ChangeLog
backend/ev-document.c
backend/ev-document.h
pdf/xpdf/pdf-document.cc
ps/ps-document.c
ps/ps-document.h
ps/ps.h
shell/ev-window.c

index 8f75e58c5cdd90eab55381a6a8cca2f0aa929292..1ce27d45ce2dc6178d51c15e07333844f438052d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2005-01-03  Marco Pesenti Gritti  <marco@gnome.org>
+
+       * 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  <marco@gnome.org>
 
        * shell/ev-view.c: (ev_view_realize), (ev_view_button_press_event):
index dcc620483dd10729a93884d4fff338395924af19..a76a555b64e295d9ebc25d1bed28d8fba9a48b0f 100644 (file)
@@ -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)
 {
index 0059fd43c91685d28e60b58ce821d9ab725bf5c8..84b9e979ace66501dc580e5d9f1786251fdb0e5e 100644 (file)
@@ -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);
index 24e0b36298e3fd258bff34cced8224d732ffeade..ede8f77e992309d1743c399a3067f9a50c2cb905 100644 (file)
@@ -17,6 +17,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
+#include <glib/gi18n.h>
+
 #include "gpdf-g-switch.h"
 #include "pdf-document.h"
 #include "ev-ps-exporter.h"
 #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;
 }
 
@@ -857,12 +866,99 @@ 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
index 7619f03fc3f55569b68dbd86b2c6d42450c7f3af..09e4ef3d32016e25ee0c25c035597d0274f0122a 100644 (file)
@@ -149,9 +149,7 @@ The DONE message indicates that ghostscript has finished processing.
 #include <stdio.h>
 #include <math.h>
 
-#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;
@@ -282,6 +285,41 @@ ps_document_init(PSDocument * gs)
   gs->gs_status = _("No document loaded.");
 }
 
+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)
 {
@@ -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];
index fd7e811573fbac30c704151481cf5d579b8911ab..dd5555ed6947a2d22e1c3c67e045aac53620fa6c 100644 (file)
 #ifndef __PS_DOCUMENT_H__
 #define __PS_DOCUMENT_H__
 
-#include <gdk/gdk.h>
-#include <gtk/gtkwidget.h>
-
-#include <gconf/gconf-client.h>
-
-#include <errno.h>
-#include <signal.h>
-#include <unistd.h>
 #include <sys/types.h>
-#include <stdio.h>
 
+#include "ev-document.h"
+#include "ps.h"
 #include "gstypes.h"
 
 G_BEGIN_DECLS
diff --git a/ps/ps.h b/ps/ps.h
index b7bcda777877d65ec4a3e91e57cd44f6e3ea794e..09039f17dce80d61e123efc3a3e1992bf250bb4e 100644 (file)
--- a/ps/ps.h
+++ b/ps/ps.h
@@ -28,6 +28,7 @@
 #include <stdio.h>
 
 #include <gsio.h>
+#include <gstypes.h>
 
 G_BEGIN_DECLS
 
index 19394f5034195718527af2410e0000d022e52798..19c67342dd016b0d1a40f28cc47e95843cd4176a 100644 (file)
@@ -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);