/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */ /* this file is part of evince, a gnome document viewer * * Copyright (C) 2005 Red Hat, Inc * * Evince is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Evince is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "ev-properties.h" #include "ev-document-fonts.h" #include "ev-jobs.h" #include "ev-job-queue.h" #include #include #include #include #include enum { FONT_NAME_COL, NUM_COLS }; typedef enum { TITLE_PROPERTY, SUBJECT_PROPERTY, AUTHOR_PROPERTY, KEYWORDS_PROPERTY, PRODUCER_PROPERTY, CREATOR_PROPERTY, CREATION_DATE_PROPERTY, MOD_DATE_PROPERTY, N_PAGES_PROPERTY, LINEARIZED_PROPERTY, FORMAT_PROPERTY, SECURITY_PROPERTY } Property; typedef struct { Property property; const char *label_id; } PropertyInfo; static const PropertyInfo properties_info[] = { { TITLE_PROPERTY, "title" }, { SUBJECT_PROPERTY, "subject" }, { AUTHOR_PROPERTY, "author" }, { KEYWORDS_PROPERTY, "keywords" }, { PRODUCER_PROPERTY, "producer" }, { CREATOR_PROPERTY, "creator" }, { CREATION_DATE_PROPERTY, "created" }, { MOD_DATE_PROPERTY, "modified" }, { N_PAGES_PROPERTY, "pages" }, { LINEARIZED_PROPERTY, "optimized" }, { FORMAT_PROPERTY, "version" }, { SECURITY_PROPERTY, "security" } }; /* Returns a locale specific date and time representation */ static char * ev_properties_format_date (GTime utime) { time_t time = (time_t) utime; struct tm t; char s[256]; const char *fmt_hack = "%c"; size_t len; if (!localtime_r (&time, &t)) return NULL; len = strftime (s, sizeof (s), fmt_hack, &t); if (len == 0 || s[0] == '\0') return NULL; return g_locale_to_utf8 (s, -1, NULL, NULL, NULL); } static void set_property (GladeXML *xml, Property property, const char *text) { GtkWidget *widget; widget = glade_xml_get_widget (xml, properties_info[property].label_id); g_return_if_fail (GTK_IS_LABEL (widget)); gtk_label_set_text (GTK_LABEL (widget), text ? text : ""); } static void update_progress_label (GtkWidget *label, double progress) { if (progress > 0) { char *progress_text; progress_text = g_strdup_printf (_("Gathering font information... %3d%%"), (int) (progress * 100)); gtk_label_set_text (GTK_LABEL (label), progress_text); g_free (progress_text); } else { gtk_label_set_text (GTK_LABEL (label), ""); } } static void job_fonts_finished_cb (EvJob *job, GtkTreeView *tree_view) { EvDocumentFonts *document_fonts = EV_DOCUMENT_FONTS (job->document); GtkWidget *progress_label; double progress; progress_label = g_object_get_data (G_OBJECT (tree_view), "progress_label"); progress = ev_document_fonts_get_progress (document_fonts); update_progress_label (progress_label, progress); if (EV_JOB_FONTS (job)->scan_completed) { g_signal_handlers_disconnect_by_func (job, job_fonts_finished_cb, tree_view); } else { EvJob *new_job; ev_document_fonts_fill_model (document_fonts, gtk_tree_view_get_model (tree_view)); new_job = ev_job_fonts_new (job->document); ev_job_queue_add_job (job, EV_JOB_PRIORITY_LOW); g_object_unref (new_job); } } static void setup_fonts_view (GladeXML *xml, EvDocument *document) { GtkCellRenderer *renderer; GtkTreeViewColumn *column; GtkListStore *list_store; EvJob *job; GtkWidget *tree_view; GtkWidget *progress_label; tree_view = glade_xml_get_widget (xml, "fonts_treeview"); progress_label = glade_xml_get_widget (xml, "font_progress_label"); column = gtk_tree_view_column_new (); gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column), TRUE); gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column); renderer = gtk_cell_renderer_text_new (); gtk_tree_view_column_pack_start (GTK_TREE_VIEW_COLUMN (column), renderer, FALSE); gtk_tree_view_column_set_title (GTK_TREE_VIEW_COLUMN (column), _("Name")); gtk_tree_view_column_set_attributes (GTK_TREE_VIEW_COLUMN (column), renderer, "text", EV_DOCUMENT_FONTS_COLUMN_NAME, NULL); list_store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING); gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), GTK_TREE_MODEL (list_store)); job = ev_job_fonts_new (document); g_object_set_data (G_OBJECT (tree_view), "progress_label", progress_label); g_signal_connect_object (job, "finished", G_CALLBACK (job_fonts_finished_cb), tree_view, 0); ev_job_queue_add_job (job, EV_JOB_PRIORITY_LOW); g_object_unref (job); } GtkDialog * ev_properties_new (EvDocument *document, const EvDocumentInfo *info) { GladeXML *xml; GtkWidget *dialog; char *text; /* Create a new GladeXML object from XML file glade_file */ xml = glade_xml_new (DATADIR "/evince-properties.glade", NULL, NULL); g_return_val_if_fail (xml != NULL, NULL); dialog = glade_xml_get_widget (xml, "properties_dialog"); g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL); if (info->fields_mask & EV_DOCUMENT_INFO_TITLE) { set_property (xml, TITLE_PROPERTY, info->title); } if (info->fields_mask & EV_DOCUMENT_INFO_SUBJECT) { set_property (xml, SUBJECT_PROPERTY, info->subject); } if (info->fields_mask & EV_DOCUMENT_INFO_AUTHOR) { set_property (xml, AUTHOR_PROPERTY, info->author); } if (info->fields_mask & EV_DOCUMENT_INFO_KEYWORDS) { set_property (xml, KEYWORDS_PROPERTY, info->keywords); } if (info->fields_mask & EV_DOCUMENT_INFO_PRODUCER) { set_property (xml, PRODUCER_PROPERTY, info->producer); } if (info->fields_mask & EV_DOCUMENT_INFO_CREATOR) { set_property (xml, CREATOR_PROPERTY, info->creator); } if (info->fields_mask & EV_DOCUMENT_INFO_CREATION_DATE) { text = ev_properties_format_date (info->creation_date); set_property (xml, CREATION_DATE_PROPERTY, text); g_free (text); } if (info->fields_mask & EV_DOCUMENT_INFO_MOD_DATE) { text = ev_properties_format_date (info->modified_date); set_property (xml, MOD_DATE_PROPERTY, text); g_free (text); } if (info->fields_mask & EV_DOCUMENT_INFO_FORMAT) { char **format_str = g_strsplit (info->format, "-", 2); text = g_strdup_printf (_("%s"), format_str[1]); set_property (xml, FORMAT_PROPERTY, text); g_free (text); g_strfreev (format_str); } if (info->fields_mask & EV_DOCUMENT_INFO_N_PAGES) { text = g_strdup_printf (_("%d"), info->n_pages); set_property (xml, N_PAGES_PROPERTY, text); g_free (text); } if (info->fields_mask & EV_DOCUMENT_INFO_LINEARIZED) { set_property (xml, LINEARIZED_PROPERTY, info->linearized); } if (info->fields_mask & EV_DOCUMENT_INFO_SECURITY) { set_property (xml, SECURITY_PROPERTY, info->security); } if (EV_IS_DOCUMENT_FONTS (document)) { setup_fonts_view (xml, document); } else { gtk_widget_hide (glade_xml_get_widget (xml, "fonts_page")); } return GTK_DIALOG (dialog); }