]> www.fi.muni.cz Git - evince.git/blob - shell/ev-properties.c
Initial go at file properties. Patch by Emil Soleyman-Zomalan
[evince.git] / shell / ev-properties.c
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
3  *
4  *  Copyright (C) 2005 Red Hat, Inc
5  *
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.
10  *
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.
15  *
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.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include "ev-properties.h"
26
27 #include <glib/gi18n.h>
28 #include <gtk/gtk.h>
29 #include <glade/glade.h>
30
31 GtkDialog *
32 ev_properties_new (EvDocument   *document, 
33                                    GtkWidget    *toplevel)
34 {
35         const char *glade_file = DATADIR "/evince-properties.glade";
36         GladeXML *xml;
37         GtkWidget *dialog = NULL;
38         EvDocumentInfo *info;
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;
44         
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);
48
49         /* Retrieve the document structure */
50         info = ev_document_get_info (document);
51
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");
66
67         /* Number of pages */
68         n_pages = g_strdup_printf (_("%d"), ev_document_get_n_pages (document));
69
70         /* PDF version */
71         format_str = g_strsplit (info->format, "-", 2);
72         pdf_version = g_strdup_printf (_("%s"), format_str[1]);
73         
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);
77         
78         /* Does the document have security? */
79         if (ev_document_security_has_document_security (EV_DOCUMENT_SECURITY (document))) {
80                 secured_document = "Yes";
81         } else {
82                 secured_document = "No";
83         }
84                                         
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);
88         
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);
102
103         /* Clean up */
104         g_strfreev (format_str);
105         g_free (n_pages);
106         g_free (pdf_version);
107         g_free (creation_date);
108         g_free (modified_date); 
109                 
110         return GTK_DIALOG (dialog); 
111 }
112
113 /* Returns a locale specific date and time representation */
114 gchar *
115 ev_properties_format_date (GTime utime)
116 {
117         struct tm *time;
118         gchar *date_string;
119         
120         date_string = g_new0 (char, 101);
121         
122         time = localtime ((const time_t *) &utime);                     
123         my_strftime (date_string, 100, "%c", time);             
124         
125         return date_string;
126 }
127
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.
130  * 
131  * This is a relatively clean one is to add an intermediate
132  * function thanks to the strftime(3) manpage
133  */
134 size_t  
135 my_strftime (char  *s, size_t max, 
136                          const char *fmt, 
137                          const struct tm *tm) 
138 {
139         return strftime (s, max, fmt, tm);
140 }