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-view.h"
26 #include "ev-document-fonts.h"
28 #include <glib/gi18n.h>
30 #include <glade/glade.h>
43 CREATION_DATE_PROPERTY,
57 static const PropertyInfo properties_info[] = {
58 { TITLE_PROPERTY, "title" },
59 { SUBJECT_PROPERTY, "subject" },
60 { AUTHOR_PROPERTY, "author" },
61 { KEYWORDS_PROPERTY, "keywords" },
62 { PRODUCER_PROPERTY, "producer" },
63 { CREATOR_PROPERTY, "creator" },
64 { CREATION_DATE_PROPERTY, "created" },
65 { MOD_DATE_PROPERTY, "modified" },
66 { N_PAGES_PROPERTY, "pages" },
67 { LINEARIZED_PROPERTY, "optimized" },
68 { FORMAT_PROPERTY, "version" },
69 { SECURITY_PROPERTY, "security" }
72 struct _EvPropertiesView {
73 GtkVBox base_instance;
78 struct _EvPropertiesViewClass {
79 GtkVBoxClass base_class;
82 G_DEFINE_TYPE (EvPropertiesView, ev_properties_view, GTK_TYPE_VBOX)
85 ev_properties_view_dispose (GObject *object)
87 EvPropertiesView *properties = EV_PROPERTIES_VIEW (object);
89 if (properties->xml) {
90 g_object_unref (properties->xml);
91 properties->xml = NULL;
96 ev_properties_view_class_init (EvPropertiesViewClass *properties_class)
98 GObjectClass *g_object_class = G_OBJECT_CLASS (properties_class);
100 g_object_class->dispose = ev_properties_view_dispose;
103 /* Returns a locale specific date and time representation */
105 ev_properties_view_format_date (GTime utime)
107 time_t time = (time_t) utime;
110 const char *fmt_hack = "%c";
113 if (time == 0 || !localtime_r (&time, &t)) return NULL;
115 len = strftime (s, sizeof (s), fmt_hack, &t);
116 if (len == 0 || s[0] == '\0') return NULL;
118 return g_locale_to_utf8 (s, -1, NULL, NULL, NULL);
121 /* This is cut out of gconvert.c from glib (and mildly modified). Not all
122 backends give valid UTF-8 for properties, so we make sure that is.
125 make_valid_utf8 (const gchar *name)
128 const gchar *remainder, *invalid;
129 gint remaining_bytes, valid_bytes;
133 remaining_bytes = strlen (name);
135 while (remaining_bytes != 0)
137 if (g_utf8_validate (remainder, remaining_bytes, &invalid))
139 valid_bytes = invalid - remainder;
142 string = g_string_sized_new (remaining_bytes);
144 g_string_append_len (string, remainder, valid_bytes);
145 g_string_append_c (string, '?');
147 remaining_bytes -= valid_bytes + 1;
148 remainder = invalid + 1;
152 return g_strdup (name);
154 g_string_append (string, remainder);
156 g_assert (g_utf8_validate (string->str, -1, NULL));
158 return g_string_free (string, FALSE);
162 set_property (GladeXML *xml, Property property, const char *text)
167 widget = glade_xml_get_widget (xml, properties_info[property].label_id);
168 g_return_if_fail (GTK_IS_LABEL (widget));
170 if (text == NULL || text[0] == '\000') {
173 markup = g_markup_printf_escaped ("<i>%s</i>", _("None"));
174 gtk_label_set_markup (GTK_LABEL (widget), markup);
179 text = text ? text : "";
181 valid_text = make_valid_utf8 (text);
183 gtk_label_set_text (GTK_LABEL (widget), valid_text);
189 ev_properties_view_set_info (EvPropertiesView *properties, const EvDocumentInfo *info)
191 GladeXML *xml = properties->xml;
194 if (info->fields_mask & EV_DOCUMENT_INFO_TITLE) {
195 set_property (xml, TITLE_PROPERTY, info->title);
197 if (info->fields_mask & EV_DOCUMENT_INFO_SUBJECT) {
198 set_property (xml, SUBJECT_PROPERTY, info->subject);
200 if (info->fields_mask & EV_DOCUMENT_INFO_AUTHOR) {
201 set_property (xml, AUTHOR_PROPERTY, info->author);
203 if (info->fields_mask & EV_DOCUMENT_INFO_KEYWORDS) {
204 set_property (xml, KEYWORDS_PROPERTY, info->keywords);
206 if (info->fields_mask & EV_DOCUMENT_INFO_PRODUCER) {
207 set_property (xml, PRODUCER_PROPERTY, info->producer);
209 if (info->fields_mask & EV_DOCUMENT_INFO_CREATOR) {
210 set_property (xml, CREATOR_PROPERTY, info->creator);
212 if (info->fields_mask & EV_DOCUMENT_INFO_CREATION_DATE) {
213 text = ev_properties_view_format_date (info->creation_date);
214 set_property (xml, CREATION_DATE_PROPERTY, text);
217 if (info->fields_mask & EV_DOCUMENT_INFO_MOD_DATE) {
218 text = ev_properties_view_format_date (info->modified_date);
219 set_property (xml, MOD_DATE_PROPERTY, text);
222 if (info->fields_mask & EV_DOCUMENT_INFO_FORMAT) {
223 text = g_strdup_printf ("%s", info->format);
224 set_property (xml, FORMAT_PROPERTY, text);
227 if (info->fields_mask & EV_DOCUMENT_INFO_N_PAGES) {
228 text = g_strdup_printf ("%d", info->n_pages);
229 set_property (xml, N_PAGES_PROPERTY, text);
232 if (info->fields_mask & EV_DOCUMENT_INFO_LINEARIZED) {
233 set_property (xml, LINEARIZED_PROPERTY, info->linearized);
235 if (info->fields_mask & EV_DOCUMENT_INFO_SECURITY) {
236 set_property (xml, SECURITY_PROPERTY, info->security);
241 ev_properties_view_init (EvPropertiesView *properties)
245 /* Create a new GladeXML object from XML file glade_file */
246 xml = glade_xml_new (DATADIR "/evince-properties.glade", "general_page_root", GETTEXT_PACKAGE);
247 properties->xml = xml;
248 g_assert (xml != NULL);
250 gtk_box_pack_start (GTK_BOX (properties),
251 glade_xml_get_widget (xml, "general_page_root"),
256 ev_properties_view_register_type (GTypeModule *module)
258 ev_properties_view_get_type ();
262 ev_properties_view_new (void)
264 EvPropertiesView *properties;
266 properties = g_object_new (EV_TYPE_PROPERTIES, NULL);
268 return GTK_WIDGET (properties);