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);
194 gtk_widget_show (label);
196 gtk_widget_hide (label);
201 job_fonts_finished_cb (EvJob *job, EvProperties *properties)
203 EvDocumentFonts *document_fonts = EV_DOCUMENT_FONTS (job->document);
206 progress = ev_document_fonts_get_progress (document_fonts);
207 update_progress_label (properties->fonts_progress_label, progress);
209 if (EV_JOB_FONTS (job)->scan_completed) {
210 g_signal_handlers_disconnect_by_func
211 (job, job_fonts_finished_cb, properties);
216 model = gtk_tree_view_get_model
217 (GTK_TREE_VIEW (properties->fonts_treeview));
218 ev_document_doc_mutex_lock ();
219 ev_document_fonts_fill_model (document_fonts, model);
220 ev_document_doc_mutex_unlock ();
221 new_job = ev_job_fonts_new (job->document);
222 ev_job_queue_add_job (job, EV_JOB_PRIORITY_LOW);
223 g_object_unref (new_job);
228 setup_fonts_view (EvProperties *properties)
230 GtkTreeView *tree_view = GTK_TREE_VIEW (properties->fonts_treeview);
231 GtkListStore *list_store;
234 list_store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING);
235 gtk_tree_view_set_model (tree_view, GTK_TREE_MODEL (list_store));
237 job = ev_job_fonts_new (properties->document);
238 g_signal_connect_object (job, "finished",
239 G_CALLBACK (job_fonts_finished_cb),
241 ev_job_queue_add_job (job, EV_JOB_PRIORITY_LOW);
242 g_object_unref (job);
246 ev_properties_set_document (EvProperties *properties,
247 EvDocument *document)
249 EvPageCache *page_cache;
250 GladeXML *xml = properties->xml;
251 const EvDocumentInfo *info;
254 properties->document = document;
256 page_cache = ev_page_cache_get (document);
257 info = ev_page_cache_get_info (page_cache);
259 if (info->fields_mask & EV_DOCUMENT_INFO_TITLE) {
260 set_property (xml, TITLE_PROPERTY, info->title);
262 if (info->fields_mask & EV_DOCUMENT_INFO_SUBJECT) {
263 set_property (xml, SUBJECT_PROPERTY, info->subject);
265 if (info->fields_mask & EV_DOCUMENT_INFO_AUTHOR) {
266 set_property (xml, AUTHOR_PROPERTY, info->author);
268 if (info->fields_mask & EV_DOCUMENT_INFO_KEYWORDS) {
269 set_property (xml, KEYWORDS_PROPERTY, info->keywords);
271 if (info->fields_mask & EV_DOCUMENT_INFO_PRODUCER) {
272 set_property (xml, PRODUCER_PROPERTY, info->producer);
274 if (info->fields_mask & EV_DOCUMENT_INFO_CREATOR) {
275 set_property (xml, CREATOR_PROPERTY, info->creator);
277 if (info->fields_mask & EV_DOCUMENT_INFO_CREATION_DATE) {
278 text = ev_properties_format_date (info->creation_date);
279 set_property (xml, CREATION_DATE_PROPERTY, text);
282 if (info->fields_mask & EV_DOCUMENT_INFO_MOD_DATE) {
283 text = ev_properties_format_date (info->modified_date);
284 set_property (xml, MOD_DATE_PROPERTY, text);
287 if (info->fields_mask & EV_DOCUMENT_INFO_FORMAT) {
288 char **format_str = g_strsplit (info->format, "-", 2);
290 text = g_strdup_printf (_("%s"), format_str[1]);
291 set_property (xml, FORMAT_PROPERTY, text);
294 g_strfreev (format_str);
296 if (info->fields_mask & EV_DOCUMENT_INFO_N_PAGES) {
297 text = g_strdup_printf (_("%d"), info->n_pages);
298 set_property (xml, N_PAGES_PROPERTY, text);
301 if (info->fields_mask & EV_DOCUMENT_INFO_LINEARIZED) {
302 set_property (xml, LINEARIZED_PROPERTY, info->linearized);
304 if (info->fields_mask & EV_DOCUMENT_INFO_SECURITY) {
305 set_property (xml, SECURITY_PROPERTY, info->security);
308 if (EV_IS_DOCUMENT_FONTS (document)) {
309 gtk_widget_show (properties->font_page);
310 setup_fonts_view (properties);
312 gtk_widget_hide (properties->font_page);
319 EvProperties *properties;
321 properties = g_object_new (EV_TYPE_PROPERTIES, NULL);
327 ev_properties_show (EvProperties *properties, GtkWidget *parent)
329 gtk_window_set_transient_for (GTK_WINDOW (properties->dialog),
330 GTK_WINDOW (parent));
331 g_signal_connect (properties->dialog, "response",
332 G_CALLBACK (gtk_widget_destroy), NULL);
333 gtk_widget_show (properties->dialog);