]> www.fi.muni.cz Git - evince.git/blob - shell/ev-properties.c
Hide the fonts tab
[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 #include <time.h>
31 #include <sys/time.h>
32
33 typedef enum
34 {
35         TITLE_PROPERTY,
36         SUBJECT_PROPERTY,
37         AUTHOR_PROPERTY,
38         KEYWORDS_PROPERTY,
39         PRODUCER_PROPERTY,
40         CREATOR_PROPERTY,
41         CREATION_DATE_PROPERTY,
42         MOD_DATE_PROPERTY,
43         N_PAGES_PROPERTY,
44         LINEARIZED_PROPERTY,
45         FORMAT_PROPERTY,
46         SECURITY_PROPERTY
47 } Property;
48
49 typedef struct
50 {
51         Property property;
52         const char *label_id;
53 } PropertyInfo;
54
55 static const PropertyInfo properties_info[] = {
56         { TITLE_PROPERTY, "title" },
57         { SUBJECT_PROPERTY, "subject" },
58         { AUTHOR_PROPERTY, "author" },
59         { KEYWORDS_PROPERTY, "keywords" },
60         { PRODUCER_PROPERTY, "producer" },
61         { CREATOR_PROPERTY, "creator" },
62         { CREATION_DATE_PROPERTY, "created" },
63         { MOD_DATE_PROPERTY, "modified" },
64         { N_PAGES_PROPERTY, "pages" },
65         { LINEARIZED_PROPERTY, "optimized" },
66         { FORMAT_PROPERTY, "version" },
67         { SECURITY_PROPERTY, "security" }
68 };
69
70 /* Returns a locale specific date and time representation */
71 static gchar *
72 ev_properties_format_date (GTime utime)
73 {
74         struct tm *time;
75         gchar *date_string;
76         
77         date_string = g_new0 (char, 101);
78         
79         time = localtime ((const time_t *) &utime);                     
80         strftime (date_string, 100, "%c", time);                
81         
82         return date_string;
83 }
84
85 static void
86 set_property (GladeXML *xml, Property property, const char *text)
87 {
88         GtkWidget *widget;
89
90         widget = glade_xml_get_widget (xml, properties_info[property].label_id);
91         g_return_if_fail (GTK_IS_LABEL (widget));
92         gtk_label_set_text (GTK_LABEL (widget), text);
93 }
94
95 GtkDialog *
96 ev_properties_new (EvDocumentInfo *info)
97 {
98         GladeXML *xml;
99         GtkWidget *dialog;
100         char *text;
101         
102         /* Create a new GladeXML object from XML file glade_file */
103         xml = glade_xml_new (DATADIR "/evince-properties.glade", NULL, NULL);
104         g_return_val_if_fail (xml != NULL, NULL);
105
106         dialog = glade_xml_get_widget (xml, "properties_dialog");
107         g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL);
108                                         
109         if (info->fields_mask & EV_DOCUMENT_INFO_TITLE) {
110                 set_property (xml, TITLE_PROPERTY, info->title);
111         }
112         if (info->fields_mask & EV_DOCUMENT_INFO_SUBJECT) {
113                 set_property (xml, SUBJECT_PROPERTY, info->subject);
114         }
115         if (info->fields_mask & EV_DOCUMENT_INFO_AUTHOR) {
116                 set_property (xml, AUTHOR_PROPERTY, info->author);
117         }
118         if (info->fields_mask & EV_DOCUMENT_INFO_KEYWORDS) {
119                 set_property (xml, KEYWORDS_PROPERTY, info->keywords);
120         }
121         if (info->fields_mask & EV_DOCUMENT_INFO_PRODUCER) {
122                 set_property (xml, PRODUCER_PROPERTY, info->producer);
123         }
124         if (info->fields_mask & EV_DOCUMENT_INFO_CREATOR) {
125                 set_property (xml, CREATOR_PROPERTY, info->creator);
126         }
127         if (info->fields_mask & EV_DOCUMENT_INFO_CREATION_DATE) {
128                 text = ev_properties_format_date ((GTime) info->creation_date);
129                 set_property (xml, CREATION_DATE_PROPERTY, text);
130                 g_free (text);
131         }
132         if (info->fields_mask & EV_DOCUMENT_INFO_MOD_DATE) {
133                 text = ev_properties_format_date ((GTime) info->modified_date);
134                 set_property (xml, MOD_DATE_PROPERTY, text);
135                 g_free (text);
136         }
137         if (info->fields_mask & EV_DOCUMENT_INFO_FORMAT) {
138                 char **format_str = g_strsplit (info->format, "-", 2);
139
140                 text = g_strdup_printf (_("%s"), format_str[1]);
141                 set_property (xml, FORMAT_PROPERTY, text);
142
143                 g_free (text);
144                 g_strfreev (format_str);
145         }
146         if (info->fields_mask & EV_DOCUMENT_INFO_N_PAGES) {
147                 text = g_strdup_printf (_("%d"), info->n_pages);
148                 set_property (xml, N_PAGES_PROPERTY, text);
149                 g_free (text);
150         }
151         if (info->fields_mask & EV_DOCUMENT_INFO_LINEARIZED) {
152                 set_property (xml, LINEARIZED_PROPERTY, info->linearized);
153         }
154         if (info->fields_mask & EV_DOCUMENT_INFO_SECURITY) {
155                 set_property (xml, SECURITY_PROPERTY, info->security);
156         }
157
158         return GTK_DIALOG (dialog); 
159 }