From dbbd21a4d621a47629ac03ffc71651172f574138 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sat, 4 Jun 2005 09:39:48 +0000 Subject: [PATCH] Rework properties code to take only EvPropertyInfo in the constructor so 2005-06-04 Marco Pesenti Gritti * backend/ev-document-info.h: * backend/ev-document.c: (ev_document_info_free): * data/evince-properties.glade: * pdf/ev-poppler.cc: * ps/ps-document.c: (ps_document_get_info): * shell/ev-properties.c: (ev_properties_format_date), (set_property), (ev_properties_new): * shell/ev-properties.h: * shell/ev-window.c: (ev_window_cmd_file_properties): Rework properties code to take only EvPropertyInfo in the constructor so that it can be useful for nautilus plugin too. Deal with backends that doesnt support some properties. Make set property code generic. --- ChangeLog | 19 ++++ backend/ev-document-info.h | 6 +- backend/ev-document.c | 1 + data/evince-properties.glade | 24 ++--- pdf/ev-poppler.cc | 16 ++- ps/ps-document.c | 4 +- shell/ev-properties.c | 201 +++++++++++++++++++---------------- shell/ev-properties.h | 20 +--- shell/ev-window.c | 13 ++- 9 files changed, 174 insertions(+), 130 deletions(-) diff --git a/ChangeLog b/ChangeLog index ca7388ef..2239c9b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2005-06-04 Marco Pesenti Gritti + + * backend/ev-document-info.h: + * backend/ev-document.c: (ev_document_info_free): + * data/evince-properties.glade: + * pdf/ev-poppler.cc: + * ps/ps-document.c: (ps_document_get_info): + * shell/ev-properties.c: (ev_properties_format_date), + (set_property), (ev_properties_new): + * shell/ev-properties.h: + * shell/ev-window.c: (ev_window_cmd_file_properties): + + Rework properties code to take only EvPropertyInfo + in the constructor so that it can be useful for + nautilus plugin too. + + Deal with backends that doesnt support some properties. + Make set property code generic. + 2005-06-04 Christian Persch * data/evince-properties.glade: diff --git a/backend/ev-document-info.h b/backend/ev-document-info.h index 299576c8..77fecf2e 100644 --- a/backend/ev-document-info.h +++ b/backend/ev-document-info.h @@ -88,7 +88,9 @@ typedef enum EV_DOCUMENT_INFO_LINEARIZED = 1 << 10, EV_DOCUMENT_INFO_START_MODE = 1 << 11, EV_DOCUMENT_INFO_UI_HINTS = 1 << 12, - EV_DOCUMENT_INFO_PERMISSIONS = 1 << 13 + EV_DOCUMENT_INFO_PERMISSIONS = 1 << 13, + EV_DOCUMENT_INFO_N_PAGES = 1 << 14, + EV_DOCUMENT_INFO_SECURITY = 1 << 15 } EvDocumentInfoFields; struct _EvDocumentInfo @@ -101,12 +103,14 @@ struct _EvDocumentInfo char *creator; char *producer; char *linearized; + char *security; GTime *creation_date; GTime *modified_date; EvDocumentLayout layout; EvDocumentMode mode; guint ui_hints; guint permissions; + int n_pages; /* Mask of all the valid fields */ guint fields_mask; diff --git a/backend/ev-document.c b/backend/ev-document.c index 714becb1..3793050d 100644 --- a/backend/ev-document.c +++ b/backend/ev-document.c @@ -252,6 +252,7 @@ ev_document_info_free (EvDocumentInfo *info) g_free (info->author); g_free (info->subject); g_free (info->keywords); + g_free (info->security); g_free (info); } diff --git a/data/evince-properties.glade b/data/evince-properties.glade index fa6da164..9f65610f 100644 --- a/data/evince-properties.glade +++ b/data/evince-properties.glade @@ -74,7 +74,7 @@ 12 - + True <b>Title:</b> False @@ -102,7 +102,7 @@ - + True <b>Subject:</b> False @@ -130,7 +130,7 @@ - + True <b>Author:</b> False @@ -158,7 +158,7 @@ - + True <b>Keywords:</b> False @@ -186,7 +186,7 @@ - + True <b>Creator:</b> False @@ -214,7 +214,7 @@ - + True <b>Producer:</b> False @@ -242,7 +242,7 @@ - + True <b>Created:</b> False @@ -270,7 +270,7 @@ - + True <b>Modified:</b> False @@ -298,7 +298,7 @@ - + True <b>Security:</b> False @@ -326,7 +326,7 @@ - + True <b>PDF Version:</b> False @@ -354,7 +354,7 @@ - + True <b>Number of Pages:</b> False @@ -382,7 +382,7 @@ - + True <b>Optimized:</b> False diff --git a/pdf/ev-poppler.cc b/pdf/ev-poppler.cc index 684812c3..7f2330da 100644 --- a/pdf/ev-poppler.cc +++ b/pdf/ev-poppler.cc @@ -23,6 +23,7 @@ #include #include #include +#include #include "ev-poppler.h" #include "ev-ps-exporter.h" @@ -335,7 +336,9 @@ pdf_document_get_info (EvDocument *document) EV_DOCUMENT_INFO_PRODUCER | EV_DOCUMENT_INFO_CREATION_DATE | EV_DOCUMENT_INFO_MOD_DATE | - EV_DOCUMENT_INFO_LINEARIZED; + EV_DOCUMENT_INFO_LINEARIZED | + EV_DOCUMENT_INFO_N_PAGES | + EV_DOCUMENT_INFO_SECURITY; g_object_get (PDF_DOCUMENT (document)->document, @@ -432,6 +435,17 @@ pdf_document_get_info (EvDocument *document) if (permissions & POPPLER_PERMISSIONS_OK_TO_ADD_NOTES) { info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_ADD_NOTES; } + + info->n_pages = ev_document_get_n_pages (document); + + if (ev_document_security_has_document_security (EV_DOCUMENT_SECURITY (document))) { + /* translators: this is the document security state */ + info->security = g_strdup (_("Yes")); + } else { + /* translators: this is the document security state */ + info->security = g_strdup (_("No")); + } + return info; } diff --git a/ps/ps-document.c b/ps/ps-document.c index 8684f4d5..29a0638a 100644 --- a/ps/ps-document.c +++ b/ps/ps-document.c @@ -1347,8 +1347,10 @@ ps_document_get_info (EvDocument *document) PSDocument *ps = PS_DOCUMENT (document); info = g_new0 (EvDocumentInfo, 1); - info->fields_mask = EV_DOCUMENT_INFO_TITLE; + info->fields_mask = EV_DOCUMENT_INFO_TITLE | + EV_DOCUMENT_INFO_N_PAGES; info->title = g_strdup (ps->doc->title); + info->n_pages = ev_document_get_n_pages (document); return info; } diff --git a/shell/ev-properties.c b/shell/ev-properties.c index 995de60b..4d904653 100644 --- a/shell/ev-properties.c +++ b/shell/ev-properties.c @@ -27,91 +27,48 @@ #include #include #include +#include +#include -GtkDialog * -ev_properties_new (EvDocument *document, - GtkWidget *toplevel) +typedef enum { - const char *glade_file = DATADIR "/evince-properties.glade"; - GladeXML *xml; - GtkWidget *dialog = NULL; - EvDocumentInfo *info; - GtkWidget *title, *subject, *author, *keywords, *producer, *creator; - GtkWidget *created, *modified, *security, *version, *pages, *optimized; - gchar *n_pages, **format_str, *pdf_version; - gchar *creation_date, *modified_date; - gchar *secured_document; - - /* Create a new GladeXML object from XML file glade_file */ - xml = glade_xml_new (glade_file, NULL, NULL); - g_return_val_if_fail (xml != NULL, NULL); - - /* Retrieve the document structure */ - info = ev_document_get_info (document); + TITLE_PROPERTY, + SUBJECT_PROPERTY, + AUTHOR_PROPERTY, + KEYWORDS_PROPERTY, + PRODUCER_PROPERTY, + CREATOR_PROPERTY, + CREATION_DATE_PROPERTY, + MOD_DATE_PROPERTY, + N_PAGES_PROPERTY, + LINEARIZED_PROPERTY, + FORMAT_PROPERTY, + SECURITY_PROPERTY +} Property; - /* Assign variables to labels */ - dialog = glade_xml_get_widget (xml, "properties_dialog"); - title = glade_xml_get_widget (xml, "title"); - subject = glade_xml_get_widget (xml, "subject"); - author = glade_xml_get_widget (xml, "author"); - keywords = glade_xml_get_widget (xml, "keywords"); - producer = glade_xml_get_widget (xml, "producer"); - creator = glade_xml_get_widget (xml, "creator"); - created = glade_xml_get_widget (xml, "created"); - modified = glade_xml_get_widget (xml, "modified"); - security = glade_xml_get_widget (xml, "security"); - version = glade_xml_get_widget (xml, "version"); - pages = glade_xml_get_widget (xml, "pages"); - optimized = glade_xml_get_widget (xml, "optimized"); - - /* Number of pages */ - n_pages = g_strdup_printf (_("%d"), ev_document_get_n_pages (document)); - - /* PDF version */ - format_str = g_strsplit (info->format, "-", 2); - pdf_version = g_strdup_printf (_("%s"), format_str[1]); - - /* Creation and modified date */ - creation_date = ev_properties_format_date ((GTime) info->creation_date); - modified_date = ev_properties_format_date ((GTime) info->modified_date); - - /* Does the document have security? */ - if (ev_document_security_has_document_security (EV_DOCUMENT_SECURITY (document))) { - secured_document = "Yes"; - } else { - secured_document = "No"; - } - - /* Shorten label values to fit window size by ellipsizing */ - gtk_label_set_ellipsize (GTK_LABEL (title), PANGO_ELLIPSIZE_END); - gtk_label_set_ellipsize (GTK_LABEL (keywords), PANGO_ELLIPSIZE_END); - - /* Assign values to label fields */ - gtk_label_set_text (GTK_LABEL (title), info->title); - gtk_label_set_text (GTK_LABEL (subject), info->subject); - gtk_label_set_text (GTK_LABEL (author), info->author); - gtk_label_set_text (GTK_LABEL (keywords), info->keywords); - gtk_label_set_text (GTK_LABEL (producer), info->producer); - gtk_label_set_text (GTK_LABEL (creator), info->creator); - gtk_label_set_text (GTK_LABEL (created), creation_date); - gtk_label_set_text (GTK_LABEL (modified), modified_date); - gtk_label_set_text (GTK_LABEL (security), secured_document); - gtk_label_set_text (GTK_LABEL (version), pdf_version); - gtk_label_set_text (GTK_LABEL (pages), n_pages); - gtk_label_set_text (GTK_LABEL (optimized), info->linearized); +typedef struct +{ + Property property; + const char *label_id; +} PropertyInfo; - /* Clean up */ - g_strfreev (format_str); - g_free (n_pages); - g_free (pdf_version); - g_free (creation_date); - g_free (modified_date); - - return GTK_DIALOG (dialog); -} +static const PropertyInfo properties_info[] = { + { TITLE_PROPERTY, "title" }, + { SUBJECT_PROPERTY, "subject" }, + { AUTHOR_PROPERTY, "author" }, + { KEYWORDS_PROPERTY, "keywords" }, + { PRODUCER_PROPERTY, "producer" }, + { CREATOR_PROPERTY, "creator" }, + { CREATION_DATE_PROPERTY, "created" }, + { MOD_DATE_PROPERTY, "modified" }, + { N_PAGES_PROPERTY, "pages" }, + { LINEARIZED_PROPERTY, "optimized" }, + { FORMAT_PROPERTY, "version" }, + { SECURITY_PROPERTY, "security" } +}; /* Returns a locale specific date and time representation */ -gchar * +static gchar * ev_properties_format_date (GTime utime) { struct tm *time; @@ -120,21 +77,83 @@ ev_properties_format_date (GTime utime) date_string = g_new0 (char, 101); time = localtime ((const time_t *) &utime); - my_strftime (date_string, 100, "%c", time); + strftime (date_string, 100, "%c", time); return date_string; } -/* Some buggy versions of gcc complain about the use of %c: - * warning: `%c' yields only last 2 digits of year in some locales. - * - * This is a relatively clean one is to add an intermediate - * function thanks to the strftime(3) manpage - */ -size_t -my_strftime (char *s, size_t max, - const char *fmt, - const struct tm *tm) +static void +set_property (GladeXML *xml, Property property, const char *text) +{ + GtkWidget *widget; + + widget = glade_xml_get_widget (xml, properties_info[property].label_id); + g_return_if_fail (GTK_IS_LABEL (widget)); + gtk_label_set_text (GTK_LABEL (widget), text); +} + +GtkDialog * +ev_properties_new (EvDocumentInfo *info) { - return strftime (s, max, fmt, tm); + GladeXML *xml; + GtkWidget *dialog; + char *text; + + /* Create a new GladeXML object from XML file glade_file */ + xml = glade_xml_new (DATADIR "/evince-properties.glade", NULL, NULL); + g_return_val_if_fail (xml != NULL, NULL); + + dialog = glade_xml_get_widget (xml, "properties_dialog"); + g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL); + + if (info->fields_mask & EV_DOCUMENT_INFO_TITLE) { + set_property (xml, TITLE_PROPERTY, info->title); + } + if (info->fields_mask & EV_DOCUMENT_INFO_SUBJECT) { + set_property (xml, SUBJECT_PROPERTY, info->subject); + } + if (info->fields_mask & EV_DOCUMENT_INFO_AUTHOR) { + set_property (xml, AUTHOR_PROPERTY, info->author); + } + if (info->fields_mask & EV_DOCUMENT_INFO_KEYWORDS) { + set_property (xml, KEYWORDS_PROPERTY, info->keywords); + } + if (info->fields_mask & EV_DOCUMENT_INFO_PRODUCER) { + set_property (xml, PRODUCER_PROPERTY, info->producer); + } + if (info->fields_mask & EV_DOCUMENT_INFO_CREATOR) { + set_property (xml, CREATOR_PROPERTY, info->creator); + } + if (info->fields_mask & EV_DOCUMENT_INFO_CREATION_DATE) { + text = ev_properties_format_date ((GTime) info->creation_date); + set_property (xml, CREATION_DATE_PROPERTY, text); + g_free (text); + } + if (info->fields_mask & EV_DOCUMENT_INFO_MOD_DATE) { + text = ev_properties_format_date ((GTime) info->modified_date); + set_property (xml, MOD_DATE_PROPERTY, text); + g_free (text); + } + if (info->fields_mask & EV_DOCUMENT_INFO_FORMAT) { + char **format_str = g_strsplit (info->format, "-", 2); + + text = g_strdup_printf (_("%s"), format_str[1]); + set_property (xml, FORMAT_PROPERTY, text); + + g_free (text); + g_strfreev (format_str); + } + if (info->fields_mask & EV_DOCUMENT_INFO_N_PAGES) { + text = g_strdup_printf (_("%d"), info->n_pages); + set_property (xml, N_PAGES_PROPERTY, text); + g_free (text); + } + if (info->fields_mask & EV_DOCUMENT_INFO_LINEARIZED) { + set_property (xml, LINEARIZED_PROPERTY, info->linearized); + } + if (info->fields_mask & EV_DOCUMENT_INFO_SECURITY) { + set_property (xml, SECURITY_PROPERTY, info->security); + } + + return GTK_DIALOG (dialog); } diff --git a/shell/ev-properties.h b/shell/ev-properties.h index 0d0eaf8e..1accd2fe 100644 --- a/shell/ev-properties.h +++ b/shell/ev-properties.h @@ -22,31 +22,13 @@ #define __EV_PROPERTIES_H__ #include "ev-document.h" -#include "ev-document-security.h" #include "ev-window.h" -#include -#include #include -#include -#include G_BEGIN_DECLS -typedef struct _EvProperties EvProperties; - -struct _EvProperties { - GtkDialog parent; -}; - -GtkDialog *ev_properties_new (EvDocument *document, - GtkWidget *toplevel); - -gchar *ev_properties_format_date (GTime utime); - -size_t my_strftime (char *s, size_t max, - const char *fmt, - const struct tm *tm); +GtkDialog *ev_properties_new (EvDocumentInfo *info); G_END_DECLS diff --git a/shell/ev-window.c b/shell/ev-window.c index b94871ba..2ebcc1b3 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -1184,11 +1184,14 @@ ev_window_cmd_file_print (GtkAction *action, EvWindow *ev_window) static void ev_window_cmd_file_properties (GtkAction *action, EvWindow *ev_window) { - GtkDialog *dialog; - - dialog = ev_properties_new (ev_window->priv->document, GTK_WIDGET (ev_window)); - gtk_dialog_run (dialog); - gtk_widget_destroy (GTK_WIDGET (dialog)); + EvDocumentInfo *info; + GtkDialog *dialog; + + info = ev_document_get_info (ev_window->priv->document); + dialog = ev_properties_new (info); + gtk_dialog_run (dialog); + gtk_widget_destroy (GTK_WIDGET (dialog)); + ev_document_info_free (info); } static void -- 2.43.5