diff options
-rw-r--r-- | ChangeLog | 19 | ||||
-rw-r--r-- | backend/ev-document-info.h | 6 | ||||
-rw-r--r-- | backend/ev-document.c | 1 | ||||
-rw-r--r-- | data/evince-properties.glade | 24 | ||||
-rw-r--r-- | pdf/ev-poppler.cc | 16 | ||||
-rw-r--r-- | ps/ps-document.c | 4 | ||||
-rw-r--r-- | shell/ev-properties.c | 201 | ||||
-rw-r--r-- | shell/ev-properties.h | 20 | ||||
-rw-r--r-- | shell/ev-window.c | 13 |
9 files changed, 174 insertions, 130 deletions
@@ -1,3 +1,22 @@ +2005-06-04 Marco Pesenti Gritti <mpg@redhat.com> + + * 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 <chpe@gnome.org> * data/evince-properties.glade: diff --git a/backend/ev-document-info.h b/backend/ev-document-info.h index 299576c..77fecf2 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 714becb..3793050 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 fa6da16..9f65610 100644 --- a/data/evince-properties.glade +++ b/data/evince-properties.glade @@ -74,7 +74,7 @@ <property name="column_spacing">12</property> <child> - <widget class="GtkLabel" id="label3"> + <widget class="GtkLabel" id="title_caption"> <property name="visible">True</property> <property name="label" translatable="yes"><b>Title:</b></property> <property name="use_underline">False</property> @@ -102,7 +102,7 @@ </child> <child> - <widget class="GtkLabel" id="label4"> + <widget class="GtkLabel" id="subject_caption"> <property name="visible">True</property> <property name="label" translatable="yes"><b>Subject:</b></property> <property name="use_underline">False</property> @@ -130,7 +130,7 @@ </child> <child> - <widget class="GtkLabel" id="label5"> + <widget class="GtkLabel" id="author_caption"> <property name="visible">True</property> <property name="label" translatable="yes"><b>Author:</b></property> <property name="use_underline">False</property> @@ -158,7 +158,7 @@ </child> <child> - <widget class="GtkLabel" id="label6"> + <widget class="GtkLabel" id="keywords_caption"> <property name="visible">True</property> <property name="label" translatable="yes"><b>Keywords:</b></property> <property name="use_underline">False</property> @@ -186,7 +186,7 @@ </child> <child> - <widget class="GtkLabel" id="label7"> + <widget class="GtkLabel" id="creator_caption"> <property name="visible">True</property> <property name="label" translatable="yes"><b>Creator:</b></property> <property name="use_underline">False</property> @@ -214,7 +214,7 @@ </child> <child> - <widget class="GtkLabel" id="label8"> + <widget class="GtkLabel" id="producer_caption"> <property name="visible">True</property> <property name="label" translatable="yes"><b>Producer:</b></property> <property name="use_underline">False</property> @@ -242,7 +242,7 @@ </child> <child> - <widget class="GtkLabel" id="label9"> + <widget class="GtkLabel" id="created_caption"> <property name="visible">True</property> <property name="label" translatable="yes"><b>Created:</b></property> <property name="use_underline">False</property> @@ -270,7 +270,7 @@ </child> <child> - <widget class="GtkLabel" id="label10"> + <widget class="GtkLabel" id="modified_caption"> <property name="visible">True</property> <property name="label" translatable="yes"><b>Modified:</b></property> <property name="use_underline">False</property> @@ -298,7 +298,7 @@ </child> <child> - <widget class="GtkLabel" id="label11"> + <widget class="GtkLabel" id="security_caption"> <property name="visible">True</property> <property name="label" translatable="yes"><b>Security:</b></property> <property name="use_underline">False</property> @@ -326,7 +326,7 @@ </child> <child> - <widget class="GtkLabel" id="label12"> + <widget class="GtkLabel" id="version_caption"> <property name="visible">True</property> <property name="label" translatable="yes"><b>PDF Version:</b></property> <property name="use_underline">False</property> @@ -354,7 +354,7 @@ </child> <child> - <widget class="GtkLabel" id="label13"> + <widget class="GtkLabel" id="pages_caption"> <property name="visible">True</property> <property name="label" translatable="yes"><b>Number of Pages:</b></property> <property name="use_underline">False</property> @@ -382,7 +382,7 @@ </child> <child> - <widget class="GtkLabel" id="label14"> + <widget class="GtkLabel" id="optimized_caption"> <property name="visible">True</property> <property name="label" translatable="yes"><b>Optimized:</b></property> <property name="use_underline">False</property> diff --git a/pdf/ev-poppler.cc b/pdf/ev-poppler.cc index 684812c..7f2330d 100644 --- a/pdf/ev-poppler.cc +++ b/pdf/ev-poppler.cc @@ -23,6 +23,7 @@ #include <poppler.h> #include <poppler-document.h> #include <poppler-page.h> +#include <glib/gi18n.h> #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 8684f4d..29a0638 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 995de60..4d90465 100644 --- a/shell/ev-properties.c +++ b/shell/ev-properties.c @@ -27,91 +27,48 @@ #include <glib/gi18n.h> #include <gtk/gtk.h> #include <glade/glade.h> +#include <time.h> +#include <sys/time.h> -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 0d0eaf8..1accd2f 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 <time.h> -#include <sys/time.h> #include <gtk/gtkdialog.h> -#include <gtk/gtkwidget.h> -#include <gtk/gtkwindow.h> 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 b94871b..2ebcc1b 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 |