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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include <glib/gi18n.h>
28 #include "ev-document-fonts.h"
29 #include "ev-job-scheduler.h"
31 #include "ev-properties-fonts.h"
33 struct _EvPropertiesFonts {
34 GtkVBox base_instance;
36 GtkWidget *fonts_treeview;
37 GtkWidget *fonts_progress_label;
43 struct _EvPropertiesFontsClass {
44 GtkVBoxClass base_class;
48 job_fonts_finished_cb (EvJob *job, EvPropertiesFonts *properties);
50 G_DEFINE_TYPE (EvPropertiesFonts, ev_properties_fonts, GTK_TYPE_VBOX)
53 ev_properties_fonts_dispose (GObject *object)
55 EvPropertiesFonts *properties = EV_PROPERTIES_FONTS (object);
57 if (properties->fonts_job) {
58 g_signal_handlers_disconnect_by_func (properties->fonts_job,
59 job_fonts_finished_cb,
61 ev_job_cancel (properties->fonts_job);
63 g_object_unref (properties->fonts_job);
64 properties->fonts_job = NULL;
67 G_OBJECT_CLASS (ev_properties_fonts_parent_class)->dispose (object);
71 ev_properties_fonts_class_init (EvPropertiesFontsClass *properties_class)
73 GObjectClass *g_object_class = G_OBJECT_CLASS (properties_class);
75 g_object_class->dispose = ev_properties_fonts_dispose;
79 font_cell_data_func (GtkTreeViewColumn *col, GtkCellRenderer *renderer,
80 GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
86 gtk_tree_model_get (model, iter,
87 EV_DOCUMENT_FONTS_COLUMN_NAME, &name,
88 EV_DOCUMENT_FONTS_COLUMN_DETAILS, &details,
92 markup = g_strdup_printf ("<b><big>%s</big></b>\n<small>%s</small>",
95 markup = g_strdup_printf ("<b><big>%s</big></b>", name);
98 g_object_set (renderer, "markup", markup, NULL);
106 ev_properties_fonts_init (EvPropertiesFonts *properties)
109 GtkCellRenderer *renderer;
110 GtkTreeViewColumn *column;
112 gtk_container_set_border_width (GTK_CONTAINER (properties), 12);
113 gtk_box_set_spacing (GTK_BOX (properties), 6);
115 swindow = gtk_scrolled_window_new (NULL, NULL);
116 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
117 GTK_POLICY_AUTOMATIC,
118 GTK_POLICY_AUTOMATIC);
119 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swindow),
122 properties->fonts_treeview = gtk_tree_view_new ();
123 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (properties->fonts_treeview),
125 column = gtk_tree_view_column_new ();
126 gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column), TRUE);
127 gtk_tree_view_append_column (GTK_TREE_VIEW (properties->fonts_treeview),
130 renderer = GTK_CELL_RENDERER (g_object_new (GTK_TYPE_CELL_RENDERER_TEXT,
132 gtk_tree_view_column_pack_start (GTK_TREE_VIEW_COLUMN (column),
134 gtk_tree_view_column_set_title (GTK_TREE_VIEW_COLUMN (column),
136 gtk_tree_view_column_set_cell_data_func (column, renderer,
140 gtk_container_add (GTK_CONTAINER (swindow), properties->fonts_treeview);
141 gtk_widget_show (properties->fonts_treeview);
143 gtk_box_pack_start (GTK_BOX (properties), swindow,
145 gtk_widget_show (swindow);
147 properties->fonts_progress_label = gtk_label_new (NULL);
148 g_object_set (G_OBJECT (properties->fonts_progress_label),
151 gtk_box_pack_start (GTK_BOX (properties),
152 properties->fonts_progress_label,
154 gtk_widget_show (properties->fonts_progress_label);
158 update_progress_label (GtkWidget *label, double progress)
162 progress_text = g_strdup_printf (_("Gathering font information… %3d%%"),
163 (int) (progress * 100));
164 gtk_label_set_text (GTK_LABEL (label), progress_text);
165 g_free (progress_text);
166 gtk_widget_show (label);
168 gtk_widget_hide (label);
173 job_fonts_finished_cb (EvJob *job, EvPropertiesFonts *properties)
175 g_signal_handlers_disconnect_by_func (job, job_fonts_finished_cb, properties);
176 g_object_unref (properties->fonts_job);
177 properties->fonts_job = NULL;
181 job_fonts_updated_cb (EvJobFonts *job, gdouble progress, EvPropertiesFonts *properties)
184 EvDocumentFonts *document_fonts = EV_DOCUMENT_FONTS (properties->document);
186 update_progress_label (properties->fonts_progress_label, progress);
188 model = gtk_tree_view_get_model (GTK_TREE_VIEW (properties->fonts_treeview));
189 /* Documen lock is already held by the jop */
190 ev_document_fonts_fill_model (document_fonts, model);
194 ev_properties_fonts_set_document (EvPropertiesFonts *properties,
195 EvDocument *document)
197 GtkTreeView *tree_view = GTK_TREE_VIEW (properties->fonts_treeview);
198 GtkListStore *list_store;
200 properties->document = document;
202 list_store = gtk_list_store_new (EV_DOCUMENT_FONTS_COLUMN_NUM_COLUMNS,
203 G_TYPE_STRING, G_TYPE_STRING);
204 gtk_tree_view_set_model (tree_view, GTK_TREE_MODEL (list_store));
206 properties->fonts_job = ev_job_fonts_new (properties->document);
207 g_signal_connect (properties->fonts_job, "updated",
208 G_CALLBACK (job_fonts_updated_cb),
210 g_signal_connect (properties->fonts_job, "finished",
211 G_CALLBACK (job_fonts_finished_cb),
213 ev_job_scheduler_push_job (properties->fonts_job, EV_JOB_PRIORITY_NONE);
217 ev_properties_fonts_new ()
219 EvPropertiesFonts *properties;
221 properties = g_object_new (EV_TYPE_PROPERTIES_FONTS, NULL);
223 return GTK_WIDGET (properties);