From 1561766454d8a06d887da5c2955b8c4d1dddd9a3 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Thu, 14 Apr 2005 15:41:30 +0000 Subject: [PATCH] Fix the crash when trying to copy in backends that doesnt support it. We 2005-04-14 Marco Pesenti Gritti * backend/ev-document.h: * djvu/djvu-document.c: (djvu_document_can_get_text), (djvu_document_document_iface_init): * dvi/dvi-document.c: (dvi_document_can_get_text), (dvi_document_document_iface_init): * pdf/ev-poppler.cc: * pixbuf/pixbuf-document.c: (pixbuf_document_can_get_text), (pixbuf_document_document_iface_init): * ps/ps-document.c: (ps_document_can_get_text), (ps_document_document_iface_init): * shell/ev-view.c: (ev_view_copy), (ev_view_primary_get_cb): * shell/ev-window.c: (update_action_sensitivity): Fix the crash when trying to copy in backends that doesnt support it. We can implement a better solution once we do real text selection. --- ChangeLog | 19 +++++++++++++++++++ backend/ev-document.c | 8 ++++++++ backend/ev-document.h | 2 ++ djvu/djvu-document.c | 10 ++++------ dvi/dvi-document.c | 10 ++++------ pdf/ev-poppler.cc | 9 +++++++-- pixbuf/pixbuf-document.c | 10 ++++------ ps/ps-document.c | 9 ++++----- shell/ev-view.c | 8 ++++++++ shell/ev-window.c | 7 +++++-- 10 files changed, 65 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4fc983a7..87c05e83 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2005-04-14 Marco Pesenti Gritti + + * backend/ev-document.h: + * djvu/djvu-document.c: (djvu_document_can_get_text), + (djvu_document_document_iface_init): + * dvi/dvi-document.c: (dvi_document_can_get_text), + (dvi_document_document_iface_init): + * pdf/ev-poppler.cc: + * pixbuf/pixbuf-document.c: (pixbuf_document_can_get_text), + (pixbuf_document_document_iface_init): + * ps/ps-document.c: (ps_document_can_get_text), + (ps_document_document_iface_init): + * shell/ev-view.c: (ev_view_copy), (ev_view_primary_get_cb): + * shell/ev-window.c: (update_action_sensitivity): + + Fix the crash when trying to copy in backends that doesnt + support it. We can implement a better solution once we + do real text selection. + 2005-04-12 Marco Pesenti Gritti * data/evince-ui.xml: diff --git a/backend/ev-document.c b/backend/ev-document.c index aa61fc69..124a6261 100644 --- a/backend/ev-document.c +++ b/backend/ev-document.c @@ -182,6 +182,14 @@ ev_document_get_page_label(EvDocument *document, return iface->get_page_label (document, page); } +gboolean +ev_document_can_get_text (EvDocument *document) +{ + EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); + + return iface->can_get_text (document); +} + char * ev_document_get_text (EvDocument *document, int page, diff --git a/backend/ev-document.h b/backend/ev-document.h index 743b9478..6cdf8d24 100644 --- a/backend/ev-document.h +++ b/backend/ev-document.h @@ -79,6 +79,7 @@ struct _EvDocumentIface double *height); char * (* get_page_label) (EvDocument *document, int page); + gboolean (* can_get_text) (EvDocument *document); char * (* get_text) (EvDocument *document, int page, EvRectangle *rect); @@ -109,6 +110,7 @@ void ev_document_get_page_size (EvDocument *document, double *height); char *ev_document_get_page_label(EvDocument *document, int page); +gboolean ev_document_can_get_text (EvDocument *document); char *ev_document_get_text (EvDocument *document, int page, EvRectangle *rect); diff --git a/djvu/djvu-document.c b/djvu/djvu-document.c index 1b155bf4..d74af665 100644 --- a/djvu/djvu-document.c +++ b/djvu/djvu-document.c @@ -224,12 +224,10 @@ djvu_document_class_init (DjvuDocumentClass *klass) g_object_class_override_property (gobject_class, PROP_TITLE, "title"); } -static char * -djvu_document_get_text (EvDocument *document, gint page, EvRectangle *rect) +static gboolean +djvu_document_can_get_text (EvDocument *document) { - /* FIXME this method should not be in EvDocument */ - g_warning ("djvu_document_get_text not implemented"); - return NULL; + return FALSE; } static void @@ -237,7 +235,7 @@ djvu_document_document_iface_init (EvDocumentIface *iface) { iface->load = djvu_document_load; iface->save = djvu_document_save; - iface->get_text = djvu_document_get_text; + iface->can_get_text = djvu_document_can_get_text; iface->get_n_pages = djvu_document_get_n_pages; iface->get_page_size = djvu_document_get_page_size; iface->render_pixbuf = djvu_document_render_pixbuf; diff --git a/dvi/dvi-document.c b/dvi/dvi-document.c index f827ff40..b9edc9e6 100644 --- a/dvi/dvi-document.c +++ b/dvi/dvi-document.c @@ -238,12 +238,10 @@ dvi_document_class_init (DviDocumentClass *klass) g_object_class_override_property (gobject_class, PROP_TITLE, "title"); } -static char * -dvi_document_get_text (EvDocument *document, gint page, EvRectangle *rect) +static gboolean +dvi_document_can_get_text (EvDocument *document) { - /* FIXME this method should not be in EvDocument */ - g_warning ("dvi_document_get_text not implemented"); - return NULL; + return FALSE; } static void @@ -251,7 +249,7 @@ dvi_document_document_iface_init (EvDocumentIface *iface) { iface->load = dvi_document_load; iface->save = dvi_document_save; - iface->get_text = dvi_document_get_text; + iface->can_get_text = dvi_document_can_get_text; iface->get_n_pages = dvi_document_get_n_pages; iface->get_page_size = dvi_document_get_page_size; iface->render_pixbuf = dvi_document_render_pixbuf; diff --git a/pdf/ev-poppler.cc b/pdf/ev-poppler.cc index ac602b04..1599f2f2 100644 --- a/pdf/ev-poppler.cc +++ b/pdf/ev-poppler.cc @@ -324,6 +324,12 @@ pdf_document_set_password (EvDocumentSecurity *document_security, document->password = g_strdup (password); } +static gboolean +pdf_document_can_get_text (EvDocument *document) +{ + return TRUE; +} + static char * pdf_document_get_text (EvDocument *document, int page, EvRectangle *rect) { @@ -341,8 +347,6 @@ pdf_document_get_text (EvDocument *document, int page, EvRectangle *rect) r.x2 = rect->x2; r.y2 = height - rect->y1; - g_print ("%f %f %f %f\n", r.x1, r.y1, r.x2, r.y2); - return poppler_page_get_text (poppler_page, &r); } @@ -357,6 +361,7 @@ pdf_document_document_iface_init (EvDocumentIface *iface) iface->get_links = pdf_document_get_links; iface->render_pixbuf = pdf_document_render_pixbuf; iface->get_text = pdf_document_get_text; + iface->can_get_text = pdf_document_can_get_text; }; static void diff --git a/pixbuf/pixbuf-document.c b/pixbuf/pixbuf-document.c index b83da789..0aabb55f 100644 --- a/pixbuf/pixbuf-document.c +++ b/pixbuf/pixbuf-document.c @@ -169,12 +169,10 @@ pixbuf_document_class_init (PixbufDocumentClass *klass) g_object_class_override_property (gobject_class, PROP_TITLE, "title"); } -static char * -pixbuf_document_get_text (EvDocument *document, int page, EvRectangle *rect) +static gboolean +pixbuf_document_can_get_text (EvDocument *document) { - /* FIXME this method should not be in EvDocument */ - g_warning ("pixbuf_document_get_text not implemented"); - return NULL; + return FALSE; } static void @@ -182,7 +180,7 @@ pixbuf_document_document_iface_init (EvDocumentIface *iface) { iface->load = pixbuf_document_load; iface->save = pixbuf_document_save; - iface->get_text = pixbuf_document_get_text; + iface->can_get_text = pixbuf_document_can_get_text; iface->get_n_pages = pixbuf_document_get_n_pages; iface->get_page_size = pixbuf_document_get_page_size; iface->render_pixbuf = pixbuf_document_render_pixbuf; diff --git a/ps/ps-document.c b/ps/ps-document.c index c857a21d..d06855f3 100644 --- a/ps/ps-document.c +++ b/ps/ps-document.c @@ -1286,11 +1286,10 @@ ps_document_get_page_size (EvDocument *document, } } -static char * -ps_document_get_text (EvDocument *document, int page, EvRectangle *rect) +static gboolean +ps_document_can_get_text (EvDocument *document) { - g_warning ("ps_document_get_text not implemented"); /* FIXME ? */ - return NULL; + return FALSE; } static gboolean @@ -1348,7 +1347,7 @@ ps_document_document_iface_init (EvDocumentIface *iface) { iface->load = ps_document_load; iface->save = ps_document_save; - iface->get_text = ps_document_get_text; + iface->can_get_text = ps_document_can_get_text; iface->get_n_pages = ps_document_get_n_pages; iface->get_page_size = ps_document_get_page_size; iface->render_pixbuf = ps_document_render_pixbuf; diff --git a/shell/ev-view.c b/shell/ev-view.c index 5678fc28..b615b6c4 100644 --- a/shell/ev-view.c +++ b/shell/ev-view.c @@ -620,6 +620,10 @@ ev_view_copy (EvView *ev_view) GtkClipboard *clipboard; char *text; + if (!ev_document_can_get_text (ev_view->document)) { + return; + } + g_mutex_lock (EV_DOC_MUTEX); text = ev_document_get_text (ev_view->document, ev_view->current_page, @@ -641,6 +645,10 @@ ev_view_primary_get_cb (GtkClipboard *clipboard, EvView *ev_view = EV_VIEW (data); char *text; + if (!ev_document_can_get_text (ev_view->document)) { + return; + } + g_mutex_lock (EV_DOC_MUTEX); text = ev_document_get_text (ev_view->document, ev_view->current_page, diff --git a/shell/ev-window.c b/shell/ev-window.c index 734846ff..4d03050e 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -183,6 +183,7 @@ update_action_sensitivity (EvWindow *ev_window) EvDocument *document; EvWindowPageMode page_mode; EvView *view; + gboolean sensitive; document = ev_window->priv->document; page_mode = ev_window->priv->page_mode; @@ -195,8 +196,10 @@ update_action_sensitivity (EvWindow *ev_window) /* "FileCloseWindow": always sensitive */ /* Edit menu */ - set_action_sensitive (ev_window, "EditCopy", document!=NULL); - set_action_sensitive (ev_window, "EditSelectAll", document!=NULL); + + sensitive = document && ev_document_can_get_text (document); + set_action_sensitive (ev_window, "EditCopy", sensitive); + set_action_sensitive (ev_window, "EditSelectAll", sensitive); if (document) set_action_sensitive (ev_window, "EditFind", EV_IS_DOCUMENT_FIND (document)); -- 2.43.5