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"
26 #include "ev-document-fonts.h"
28 #include "ev-job-queue.h"
29 #include "ev-page-cache.h"
31 #include <glib/gi18n.h>
33 #include <glade/glade.h>
51 CREATION_DATE_PROPERTY,
65 static const PropertyInfo properties_info[] = {
66 { TITLE_PROPERTY, "title" },
67 { SUBJECT_PROPERTY, "subject" },
68 { AUTHOR_PROPERTY, "author" },
69 { KEYWORDS_PROPERTY, "keywords" },
70 { PRODUCER_PROPERTY, "producer" },
71 { CREATOR_PROPERTY, "creator" },
72 { CREATION_DATE_PROPERTY, "created" },
73 { MOD_DATE_PROPERTY, "modified" },
74 { N_PAGES_PROPERTY, "pages" },
75 { LINEARIZED_PROPERTY, "optimized" },
76 { FORMAT_PROPERTY, "version" },
77 { SECURITY_PROPERTY, "security" }
80 struct _EvProperties {
81 GObject base_instance;
86 GtkWidget *fonts_treeview;
87 GtkWidget *fonts_progress_label;
93 struct _EvPropertiesClass {
94 GObjectClass base_class;
97 G_DEFINE_TYPE (EvProperties, ev_properties, G_TYPE_OBJECT)
100 ev_properties_dispose (GObject *object)
102 EvProperties *properties = EV_PROPERTIES (object);
104 if (properties->xml) {
105 g_object_unref (properties->xml);
106 properties->xml = NULL;
111 ev_properties_class_init (EvPropertiesClass *properties_class)
113 GObjectClass *g_object_class = G_OBJECT_CLASS (properties_class);
115 g_object_class->dispose = ev_properties_dispose;
119 dialog_destroy_cb (GtkWidget *dialog, EvProperties *properties)
121 g_object_unref (properties);
125 ev_properties_init (EvProperties *properties)
128 GtkCellRenderer *renderer;
129 GtkTreeViewColumn *column;
131 /* Create a new GladeXML object from XML file glade_file */
132 xml = glade_xml_new (DATADIR "/evince-properties.glade", NULL, NULL);
133 properties->xml = xml;
134 g_assert (xml != NULL);
136 properties->dialog = glade_xml_get_widget (xml, "properties_dialog");
137 properties->fonts_treeview = glade_xml_get_widget (xml, "fonts_treeview");
138 properties->fonts_progress_label = glade_xml_get_widget (xml, "font_progress_label");
139 properties->font_page = glade_xml_get_widget (xml, "fonts_page");
141 column = gtk_tree_view_column_new ();
142 gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column), TRUE);
143 gtk_tree_view_append_column (GTK_TREE_VIEW (properties->fonts_treeview), column);
145 renderer = gtk_cell_renderer_text_new ();
146 gtk_tree_view_column_pack_start (GTK_TREE_VIEW_COLUMN (column), renderer, FALSE);
147 gtk_tree_view_column_set_title (GTK_TREE_VIEW_COLUMN (column), _("Name"));
148 gtk_tree_view_column_set_attributes (GTK_TREE_VIEW_COLUMN (column), renderer,
149 "text", EV_DOCUMENT_FONTS_COLUMN_NAME,
152 g_signal_connect (properties->dialog, "destroy",
153 G_CALLBACK (dialog_destroy_cb), properties);
156 /* Returns a locale specific date and time representation */
158 ev_properties_format_date (GTime utime)
160 time_t time = (time_t) utime;
163 const char *fmt_hack = "%c";
166 if (!localtime_r (&time, &t)) return NULL;
168 len = strftime (s, sizeof (s), fmt_hack, &t);
169 if (len == 0 || s[0] == '\0') return NULL;
171 return g_locale_to_utf8 (s, -1, NULL, NULL, NULL);
175 set_property (GladeXML *xml, Property property, const char *text)
179 widget = glade_xml_get_widget (xml, properties_info[property].label_id);
180 g_return_if_fail (GTK_IS_LABEL (widget));
182 gtk_label_set_text (GTK_LABEL (widget), text ? text : "");
186 update_progress_label (GtkWidget *label, double progress)
190 progress_text = g_strdup_printf (_("Gathering font information... %3d%%"),
191 (int) (progress * 100));
192 gtk_label_set_text (GTK_LABEL (label), progress_text);
193 g_free (progress_text);
195 gtk_label_set_text (GTK_LABEL (label), "");
200 job_fonts_finished_cb (EvJob *job, EvProperties *properties)
202 EvDocumentFonts *document_fonts = EV_DOCUMENT_FONTS (job->document);
205 progress = ev_document_fonts_get_progress (document_fonts);
206 update_progress_label (properties->fonts_progress_label, progress);
208 if (EV_JOB_FONTS (job)->scan_completed) {
209 g_signal_handlers_disconnect_by_func
210 (job, job_fonts_finished_cb, properties);
215 model = gtk_tree_view_get_model
216 (GTK_TREE_VIEW (properties->fonts_treeview));
217 ev_document_fonts_fill_model (document_fonts, model);
218 new_job = ev_job_fonts_new (job->document);
219 ev_job_queue_add_job (job, EV_JOB_PRIORITY_LOW);
220 g_object_unref (new_job);
225 setup_fonts_view (EvProperties *properties)
227 GtkTreeView *tree_view = GTK_TREE_VIEW (properties->fonts_treeview);
228 GtkListStore *list_store;
231 list_store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING);
232 gtk_tree_view_set_model (tree_view, GTK_TREE_MODEL (list_store));
234 job = ev_job_fonts_new (properties->document);
235 g_signal_connect_object (job, "finished",
236 G_CALLBACK (job_fonts_finished_cb),
238 ev_job_queue_add_job (job, EV_JOB_PRIORITY_LOW);
239 g_object_unref (job);
243 ev_properties_set_document (EvProperties *properties,
244 EvDocument *document)
246 EvPageCache *page_cache;
247 GladeXML *xml = properties->xml;
248 const EvDocumentInfo *info;
251 properties->document = document;
253 page_cache = ev_page_cache_get (document);
254 info = ev_page_cache_get_info (page_cache);
256 if (info->fields_mask & EV_DOCUMENT_INFO_TITLE) {
257 set_property (xml, TITLE_PROPERTY, info->title);
259 if (info->fields_mask & EV_DOCUMENT_INFO_SUBJECT) {
260 set_property (xml, SUBJECT_PROPERTY, info->subject);
262 if (info->fields_mask & EV_DOCUMENT_INFO_AUTHOR) {
263 set_property (xml, AUTHOR_PROPERTY, info->author);
265 if (info->fields_mask & EV_DOCUMENT_INFO_KEYWORDS) {
266 set_property (xml, KEYWORDS_PROPERTY, info->keywords);
268 if (info->fields_mask & EV_DOCUMENT_INFO_PRODUCER) {
269 set_property (xml, PRODUCER_PROPERTY, info->producer);
271 if (info->fields_mask & EV_DOCUMENT_INFO_CREATOR) {
272 set_property (xml, CREATOR_PROPERTY, info->creator);
274 if (info->fields_mask & EV_DOCUMENT_INFO_CREATION_DATE) {
275 text = ev_properties_format_date (info->creation_date);
276 set_property (xml, CREATION_DATE_PROPERTY, text);
279 if (info->fields_mask & EV_DOCUMENT_INFO_MOD_DATE) {
280 text = ev_properties_format_date (info->modified_date);
281 set_property (xml, MOD_DATE_PROPERTY, text);
284 if (info->fields_mask & EV_DOCUMENT_INFO_FORMAT) {
285 char **format_str = g_strsplit (info->format, "-", 2);
287 text = g_strdup_printf (_("%s"), format_str[1]);
288 set_property (xml, FORMAT_PROPERTY, text);
291 g_strfreev (format_str);
293 if (info->fields_mask & EV_DOCUMENT_INFO_N_PAGES) {
294 text = g_strdup_printf (_("%d"), info->n_pages);
295 set_property (xml, N_PAGES_PROPERTY, text);
298 if (info->fields_mask & EV_DOCUMENT_INFO_LINEARIZED) {
299 set_property (xml, LINEARIZED_PROPERTY, info->linearized);
301 if (info->fields_mask & EV_DOCUMENT_INFO_SECURITY) {
302 set_property (xml, SECURITY_PROPERTY, info->security);
305 if (EV_IS_DOCUMENT_FONTS (document)) {
306 gtk_widget_show (properties->font_page);
307 setup_fonts_view (properties);
309 gtk_widget_hide (properties->font_page);
316 EvProperties *properties;
318 properties = g_object_new (EV_TYPE_PROPERTIES, NULL);
324 ev_properties_show (EvProperties *properties, GtkWidget *parent)
326 gtk_window_set_transient_for (GTK_WINDOW (properties->dialog),
327 GTK_WINDOW (parent));
328 g_signal_connect (properties->dialog, "response",
329 G_CALLBACK (gtk_widget_destroy), NULL);
330 gtk_widget_show (properties->dialog);