Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <mpg@redhat.com>2005-06-04 09:39:48 (GMT)
committer Marco Pesenti Gritti <marco@src.gnome.org>2005-06-04 09:39:48 (GMT)
commitdbbd21a4d621a47629ac03ffc71651172f574138 (patch)
tree318dec35ac26574f35990d2f6f2a793fd773be24 /shell
parentbbd8576757758f6e6ffb633d61bab361337e7927 (diff)
Rework properties code to take only EvPropertyInfo in the constructor so
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.
Diffstat (limited to 'shell')
-rw-r--r--shell/ev-properties.c201
-rw-r--r--shell/ev-properties.h20
-rw-r--r--shell/ev-window.c13
3 files changed, 119 insertions, 115 deletions
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