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>
41 CREATION_DATE_PROPERTY,
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" }
70 /* Returns a locale specific date and time representation */
72 ev_properties_format_date (GTime utime)
74 time_t time = (time_t) utime;
77 const char *fmt_hack = "%c";
80 if (!localtime_r (&time, &t)) return NULL;
82 len = strftime (s, sizeof (s), fmt_hack, &t);
83 if (len == 0 || s[0] == '\0') return NULL;
85 return g_locale_to_utf8 (s, -1, NULL, NULL, NULL);
89 set_property (GladeXML *xml, Property property, const char *text)
93 widget = glade_xml_get_widget (xml, properties_info[property].label_id);
94 g_return_if_fail (GTK_IS_LABEL (widget));
96 gtk_label_set_text (GTK_LABEL (widget), text ? text : "");
100 ev_properties_new (EvDocumentInfo *info)
106 /* Create a new GladeXML object from XML file glade_file */
107 xml = glade_xml_new (DATADIR "/evince-properties.glade", NULL, NULL);
108 g_return_val_if_fail (xml != NULL, NULL);
110 dialog = glade_xml_get_widget (xml, "properties_dialog");
111 g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL);
113 if (info->fields_mask & EV_DOCUMENT_INFO_TITLE) {
114 set_property (xml, TITLE_PROPERTY, info->title);
116 if (info->fields_mask & EV_DOCUMENT_INFO_SUBJECT) {
117 set_property (xml, SUBJECT_PROPERTY, info->subject);
119 if (info->fields_mask & EV_DOCUMENT_INFO_AUTHOR) {
120 set_property (xml, AUTHOR_PROPERTY, info->author);
122 if (info->fields_mask & EV_DOCUMENT_INFO_KEYWORDS) {
123 set_property (xml, KEYWORDS_PROPERTY, info->keywords);
125 if (info->fields_mask & EV_DOCUMENT_INFO_PRODUCER) {
126 set_property (xml, PRODUCER_PROPERTY, info->producer);
128 if (info->fields_mask & EV_DOCUMENT_INFO_CREATOR) {
129 set_property (xml, CREATOR_PROPERTY, info->creator);
131 if (info->fields_mask & EV_DOCUMENT_INFO_CREATION_DATE) {
132 text = ev_properties_format_date ((GTime) info->creation_date);
133 set_property (xml, CREATION_DATE_PROPERTY, text);
136 if (info->fields_mask & EV_DOCUMENT_INFO_MOD_DATE) {
137 text = ev_properties_format_date ((GTime) info->modified_date);
138 set_property (xml, MOD_DATE_PROPERTY, text);
141 if (info->fields_mask & EV_DOCUMENT_INFO_FORMAT) {
142 char **format_str = g_strsplit (info->format, "-", 2);
144 text = g_strdup_printf (_("%s"), format_str[1]);
145 set_property (xml, FORMAT_PROPERTY, text);
148 g_strfreev (format_str);
150 if (info->fields_mask & EV_DOCUMENT_INFO_N_PAGES) {
151 text = g_strdup_printf (_("%d"), info->n_pages);
152 set_property (xml, N_PAGES_PROPERTY, text);
155 if (info->fields_mask & EV_DOCUMENT_INFO_LINEARIZED) {
156 set_property (xml, LINEARIZED_PROPERTY, info->linearized);
158 if (info->fields_mask & EV_DOCUMENT_INFO_SECURITY) {
159 set_property (xml, SECURITY_PROPERTY, info->security);
162 return GTK_DIALOG (dialog);