]> www.fi.muni.cz Git - evince.git/commitdiff
Rework properties code to take only EvPropertyInfo in the constructor so
authorMarco Pesenti Gritti <mpg@redhat.com>
Sat, 4 Jun 2005 09:39:48 +0000 (09:39 +0000)
committerMarco Pesenti Gritti <marco@src.gnome.org>
Sat, 4 Jun 2005 09:39:48 +0000 (09:39 +0000)
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.

ChangeLog
backend/ev-document-info.h
backend/ev-document.c
data/evince-properties.glade
pdf/ev-poppler.cc
ps/ps-document.c
shell/ev-properties.c
shell/ev-properties.h
shell/ev-window.c

index ca7388ef98fd128cdb0ac31ec6c198b5c18d632c..2239c9b9f49782c1a858dd390ed61f00728ad3ec 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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:
index 299576c8e08f77e2954959949e60969763e12117..77fecf2e77a93d08cd64d4ebc7c9997955fb290a 100644 (file)
@@ -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;
index 714becb19140c9f9cc139f25bd0794403e22acf0..3793050d3750d4cb7b9e5874edd2df34f48f9652 100644 (file)
@@ -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);
 }
index fa6da164047e27adce9e36d2d19e55032649c3e8..9f65610fd918d86d13a46dd729a1a3f827f30746 100644 (file)
@@ -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">&lt;b&gt;Title:&lt;/b&gt;</property>
                  <property name="use_underline">False</property>
              </child>
 
              <child>
-               <widget class="GtkLabel" id="label4">
+               <widget class="GtkLabel" id="subject_caption">
                  <property name="visible">True</property>
                  <property name="label" translatable="yes">&lt;b&gt;Subject:&lt;/b&gt;</property>
                  <property name="use_underline">False</property>
              </child>
 
              <child>
-               <widget class="GtkLabel" id="label5">
+               <widget class="GtkLabel" id="author_caption">
                  <property name="visible">True</property>
                  <property name="label" translatable="yes">&lt;b&gt;Author:&lt;/b&gt;</property>
                  <property name="use_underline">False</property>
              </child>
 
              <child>
-               <widget class="GtkLabel" id="label6">
+               <widget class="GtkLabel" id="keywords_caption">
                  <property name="visible">True</property>
                  <property name="label" translatable="yes">&lt;b&gt;Keywords:&lt;/b&gt;</property>
                  <property name="use_underline">False</property>
              </child>
 
              <child>
-               <widget class="GtkLabel" id="label7">
+               <widget class="GtkLabel" id="creator_caption">
                  <property name="visible">True</property>
                  <property name="label" translatable="yes">&lt;b&gt;Creator:&lt;/b&gt;</property>
                  <property name="use_underline">False</property>
              </child>
 
              <child>
-               <widget class="GtkLabel" id="label8">
+               <widget class="GtkLabel" id="producer_caption">
                  <property name="visible">True</property>
                  <property name="label" translatable="yes">&lt;b&gt;Producer:&lt;/b&gt;</property>
                  <property name="use_underline">False</property>
              </child>
 
              <child>
-               <widget class="GtkLabel" id="label9">
+               <widget class="GtkLabel" id="created_caption">
                  <property name="visible">True</property>
                  <property name="label" translatable="yes">&lt;b&gt;Created:&lt;/b&gt;</property>
                  <property name="use_underline">False</property>
              </child>
 
              <child>
-               <widget class="GtkLabel" id="label10">
+               <widget class="GtkLabel" id="modified_caption">
                  <property name="visible">True</property>
                  <property name="label" translatable="yes">&lt;b&gt;Modified:&lt;/b&gt;</property>
                  <property name="use_underline">False</property>
              </child>
 
              <child>
-               <widget class="GtkLabel" id="label11">
+               <widget class="GtkLabel" id="security_caption">
                  <property name="visible">True</property>
                  <property name="label" translatable="yes">&lt;b&gt;Security:&lt;/b&gt;</property>
                  <property name="use_underline">False</property>
              </child>
 
              <child>
-               <widget class="GtkLabel" id="label12">
+               <widget class="GtkLabel" id="version_caption">
                  <property name="visible">True</property>
                  <property name="label" translatable="yes">&lt;b&gt;PDF Version:&lt;/b&gt;</property>
                  <property name="use_underline">False</property>
              </child>
 
              <child>
-               <widget class="GtkLabel" id="label13">
+               <widget class="GtkLabel" id="pages_caption">
                  <property name="visible">True</property>
                  <property name="label" translatable="yes">&lt;b&gt;Number of Pages:&lt;/b&gt;</property>
                  <property name="use_underline">False</property>
              </child>
 
              <child>
-               <widget class="GtkLabel" id="label14">
+               <widget class="GtkLabel" id="optimized_caption">
                  <property name="visible">True</property>
                  <property name="label" translatable="yes">&lt;b&gt;Optimized:&lt;/b&gt;</property>
                  <property name="use_underline">False</property>
index 684812c3efe81fc35c0ddb4dd708b0c9e620d25c..7f2330da8755974adfbced7f3efcb1248ee4ecd0 100644 (file)
@@ -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;
 }
 
index 8684f4d562214b356c72c13166954bc4e5172515..29a0638a93c76095d087e2a76211784b938f80f2 100644 (file)
@@ -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;
 }
index 995de60bad31bbe85fdbbf582a9e6d3227fca40e..4d904653052488dc9fabf76969474e2a4a303d95 100644 (file)
 #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); 
 }
index 0d0eaf8ef9d4dad5e42e70d2df21ab039b7b64dd..1accd2fe974d626a080602e21216e5f3ce79407e 100644 (file)
 #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
 
index b94871ba15aacd2c792f0cdf93e53e706c78beec..2ebcc1b3572ad4292677664606077f7f1ebbade4 100644 (file)
@@ -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