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-fonts.h"
26 #include "ev-document-fonts.h"
28 #include "ev-job-queue.h"
30 #include <glib/gi18n.h>
31 #include <gtk/gtktreeview.h>
32 #include <glade/glade.h>
34 struct _EvPropertiesFonts {
35 GtkVBox base_instance;
39 GtkWidget *fonts_treeview;
40 GtkWidget *fonts_progress_label;
45 struct _EvPropertiesFontsClass {
46 GtkVBoxClass base_class;
49 G_DEFINE_TYPE (EvPropertiesFonts, ev_properties_fonts, GTK_TYPE_VBOX)
52 ev_properties_fonts_dispose (GObject *object)
54 EvPropertiesFonts *properties = EV_PROPERTIES_FONTS (object);
56 if (properties->xml) {
57 g_object_unref (properties->xml);
58 properties->xml = NULL;
63 ev_properties_fonts_class_init (EvPropertiesFontsClass *properties_class)
65 GObjectClass *g_object_class = G_OBJECT_CLASS (properties_class);
67 g_object_class->dispose = ev_properties_fonts_dispose;
71 font_cell_data_func (GtkTreeViewColumn *col, GtkCellRenderer *renderer,
72 GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
78 gtk_tree_model_get(model, iter,
79 EV_DOCUMENT_FONTS_COLUMN_NAME, &name,
80 EV_DOCUMENT_FONTS_COLUMN_DETAILS, &details,
84 markup = g_strdup_printf ("<b><big>%s</big></b>\n<small>%s</small>",
87 markup = g_strdup_printf ("<b><big>%s</big></b>", name);
90 g_object_set (renderer, "markup", markup, NULL);
98 ev_properties_fonts_init (EvPropertiesFonts *properties)
101 GtkCellRenderer *renderer;
102 GtkTreeViewColumn *column;
104 /* Create a new GladeXML object from XML file glade_file */
105 xml = glade_xml_new (DATADIR "/evince-properties.glade", "fonts_page_root", NULL);
106 properties->xml = xml;
107 g_assert (xml != NULL);
109 gtk_box_pack_start (GTK_BOX (properties),
110 glade_xml_get_widget (xml, "fonts_page_root"),
113 properties->fonts_treeview = glade_xml_get_widget (xml, "fonts_treeview");
114 properties->fonts_progress_label = glade_xml_get_widget (xml, "font_progress_label");
116 column = gtk_tree_view_column_new ();
117 gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column), TRUE);
118 gtk_tree_view_append_column (GTK_TREE_VIEW (properties->fonts_treeview), column);
120 renderer = GTK_CELL_RENDERER (g_object_new (GTK_TYPE_CELL_RENDERER_TEXT,
122 gtk_tree_view_column_pack_start (GTK_TREE_VIEW_COLUMN (column), renderer, FALSE);
123 gtk_tree_view_column_set_title (GTK_TREE_VIEW_COLUMN (column), _("Font"));
124 gtk_tree_view_column_set_cell_data_func (column, renderer,
130 update_progress_label (GtkWidget *label, double progress)
134 progress_text = g_strdup_printf (_("Gathering font information... %3d%%"),
135 (int) (progress * 100));
136 gtk_label_set_text (GTK_LABEL (label), progress_text);
137 g_free (progress_text);
138 gtk_widget_show (label);
140 gtk_widget_hide (label);
145 job_fonts_finished_cb (EvJob *job, EvPropertiesFonts *properties)
147 EvDocumentFonts *document_fonts = EV_DOCUMENT_FONTS (job->document);
150 progress = ev_document_fonts_get_progress (document_fonts);
151 update_progress_label (properties->fonts_progress_label, progress);
153 if (EV_JOB_FONTS (job)->scan_completed) {
154 g_signal_handlers_disconnect_by_func
155 (job, job_fonts_finished_cb, properties);
160 model = gtk_tree_view_get_model
161 (GTK_TREE_VIEW (properties->fonts_treeview));
162 ev_document_doc_mutex_lock ();
163 ev_document_fonts_fill_model (document_fonts, model);
164 ev_document_doc_mutex_unlock ();
165 new_job = ev_job_fonts_new (job->document);
166 ev_job_queue_add_job (job, EV_JOB_PRIORITY_LOW);
167 g_object_unref (new_job);
172 ev_properties_fonts_set_document (EvPropertiesFonts *properties,
173 EvDocument *document)
175 GtkTreeView *tree_view = GTK_TREE_VIEW (properties->fonts_treeview);
176 GtkListStore *list_store;
179 properties->document = document;
181 list_store = gtk_list_store_new (EV_DOCUMENT_FONTS_COLUMN_NUM_COLUMNS,
182 G_TYPE_STRING, G_TYPE_STRING);
183 gtk_tree_view_set_model (tree_view, GTK_TREE_MODEL (list_store));
185 job = ev_job_fonts_new (properties->document);
186 g_signal_connect_object (job, "finished",
187 G_CALLBACK (job_fonts_finished_cb),
189 ev_job_queue_add_job (job, EV_JOB_PRIORITY_LOW);
190 g_object_unref (job);
194 ev_properties_fonts_new ()
196 EvPropertiesFonts *properties;
198 properties = g_object_new (EV_TYPE_PROPERTIES_FONTS, NULL);
200 return GTK_WIDGET (properties);