1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /* this file is part of evince, a gnome document viewer
4 * Copyright (C) 2005 Red Hat, Inc
6 * Evince is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Evince is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
25 #include "ev-properties.h"
27 #include <glib/gi18n.h>
29 #include <glade/glade.h>
32 ev_properties_new (EvDocument *document,
35 const char *glade_file = DATADIR "/evince-properties.glade";
37 GtkWidget *dialog = NULL;
39 GtkWidget *title, *subject, *author, *keywords, *producer, *creator;
40 GtkWidget *created, *modified, *security, *version, *pages, *optimized;
41 gchar *n_pages, **format_str, *pdf_version;
42 gchar *creation_date, *modified_date;
43 gchar *secured_document;
45 /* Create a new GladeXML object from XML file glade_file */
46 xml = glade_xml_new (glade_file, NULL, NULL);
47 g_return_val_if_fail (xml != NULL, NULL);
49 /* Retrieve the document structure */
50 info = ev_document_get_info (document);
52 /* Assign variables to labels */
53 dialog = glade_xml_get_widget (xml, "properties_dialog");
54 title = glade_xml_get_widget (xml, "title");
55 subject = glade_xml_get_widget (xml, "subject");
56 author = glade_xml_get_widget (xml, "author");
57 keywords = glade_xml_get_widget (xml, "keywords");
58 producer = glade_xml_get_widget (xml, "producer");
59 creator = glade_xml_get_widget (xml, "creator");
60 created = glade_xml_get_widget (xml, "created");
61 modified = glade_xml_get_widget (xml, "modified");
62 security = glade_xml_get_widget (xml, "security");
63 version = glade_xml_get_widget (xml, "version");
64 pages = glade_xml_get_widget (xml, "pages");
65 optimized = glade_xml_get_widget (xml, "optimized");
68 n_pages = g_strdup_printf (_("%d"), ev_document_get_n_pages (document));
71 format_str = g_strsplit (info->format, "-", 2);
72 pdf_version = g_strdup_printf (_("%s"), format_str[1]);
74 /* Creation and modified date */
75 creation_date = ev_properties_format_date ((GTime) info->creation_date);
76 modified_date = ev_properties_format_date ((GTime) info->modified_date);
78 /* Does the document have security? */
79 if (ev_document_security_has_document_security (EV_DOCUMENT_SECURITY (document))) {
80 secured_document = "Yes";
82 secured_document = "No";
85 /* Shorten label values to fit window size by ellipsizing */
86 gtk_label_set_ellipsize (GTK_LABEL (title), PANGO_ELLIPSIZE_END);
87 gtk_label_set_ellipsize (GTK_LABEL (keywords), PANGO_ELLIPSIZE_END);
89 /* Assign values to label fields */
90 gtk_label_set_text (GTK_LABEL (title), info->title);
91 gtk_label_set_text (GTK_LABEL (subject), info->subject);
92 gtk_label_set_text (GTK_LABEL (author), info->author);
93 gtk_label_set_text (GTK_LABEL (keywords), info->keywords);
94 gtk_label_set_text (GTK_LABEL (producer), info->producer);
95 gtk_label_set_text (GTK_LABEL (creator), info->creator);
96 gtk_label_set_text (GTK_LABEL (created), creation_date);
97 gtk_label_set_text (GTK_LABEL (modified), modified_date);
98 gtk_label_set_text (GTK_LABEL (security), secured_document);
99 gtk_label_set_text (GTK_LABEL (version), pdf_version);
100 gtk_label_set_text (GTK_LABEL (pages), n_pages);
101 gtk_label_set_text (GTK_LABEL (optimized), info->linearized);
104 g_strfreev (format_str);
106 g_free (pdf_version);
107 g_free (creation_date);
108 g_free (modified_date);
110 return GTK_DIALOG (dialog);
113 /* Returns a locale specific date and time representation */
115 ev_properties_format_date (GTime utime)
120 date_string = g_new0 (char, 101);
122 time = localtime ((const time_t *) &utime);
123 my_strftime (date_string, 100, "%c", time);
128 /* Some buggy versions of gcc complain about the use of %c:
129 * warning: `%c' yields only last 2 digits of year in some locales.
131 * This is a relatively clean one is to add an intermediate
132 * function thanks to the strftime(3) manpage
135 my_strftime (char *s, size_t max,
139 return strftime (s, max, fmt, tm);