+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):
#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
{
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,
}
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
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)
{
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);
* 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;
pdf_document->page_valid = FALSE;
+ g_object_notify (G_OBJECT (pdf_document), "title");
+
return TRUE;
}
}
+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
#include <stdio.h>
#include <math.h>
-#include "ev-document.h"
#include "ps-document.h"
-#include "ps.h"
#include "gsdefaults.h"
#ifdef HAVE_LOCALE_H
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;
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)
{
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);
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 */
/* 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];
#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
#include <stdio.h>
#include <gsio.h>
+#include <gstypes.h>
G_BEGIN_DECLS
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)
{
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 {
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);