]> www.fi.muni.cz Git - evince.git/blob - shell/ev-properties-fonts.c
*** empty log message ***
[evince.git] / shell / ev-properties-fonts.c
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
3  *
4  *  Copyright (C) 2005 Red Hat, Inc
5  *
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.
10  *
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.
15  *
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.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include "ev-properties-fonts.h"
26 #include "ev-document-fonts.h"
27 #include "ev-jobs.h"
28 #include "ev-job-queue.h"
29
30 #include <glib/gi18n.h>
31 #include <gtk/gtktreeview.h>
32 #include <glade/glade.h>
33
34 enum
35 {
36         FONT_NAME_COL,
37         NUM_COLS
38 };
39
40 struct _EvPropertiesFonts {
41         GtkVBox base_instance;
42
43         GladeXML *xml;
44
45         GtkWidget *fonts_treeview;
46         GtkWidget *fonts_progress_label;
47
48         EvDocument *document;
49 };
50
51 struct _EvPropertiesFontsClass {
52         GtkVBoxClass base_class;
53 };
54
55 G_DEFINE_TYPE (EvPropertiesFonts, ev_properties_fonts, GTK_TYPE_VBOX)
56
57 static void
58 ev_properties_fonts_dispose (GObject *object)
59 {
60         EvPropertiesFonts *properties = EV_PROPERTIES_FONTS (object);
61
62         if (properties->xml) {
63                 g_object_unref (properties->xml);
64                 properties->xml = NULL;
65         }
66 }
67
68 static void
69 ev_properties_fonts_class_init (EvPropertiesFontsClass *properties_class)
70 {
71         GObjectClass *g_object_class = G_OBJECT_CLASS (properties_class);
72
73         g_object_class->dispose = ev_properties_fonts_dispose;
74 }
75
76 static void
77 ev_properties_fonts_init (EvPropertiesFonts *properties)
78 {
79         GladeXML *xml;
80         GtkCellRenderer *renderer;
81         GtkTreeViewColumn *column;
82
83         /* Create a new GladeXML object from XML file glade_file */
84         xml = glade_xml_new (DATADIR "/evince-properties.glade", "fonts_page_root", NULL);
85         properties->xml = xml;
86         g_assert (xml != NULL);
87
88         gtk_box_pack_start (GTK_BOX (properties),
89                             glade_xml_get_widget (xml, "fonts_page_root"),
90                             TRUE, TRUE, 0);
91
92         properties->fonts_treeview = glade_xml_get_widget (xml, "fonts_treeview");
93         properties->fonts_progress_label = glade_xml_get_widget (xml, "font_progress_label");
94
95         column = gtk_tree_view_column_new ();
96         gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column), TRUE);
97         gtk_tree_view_append_column (GTK_TREE_VIEW (properties->fonts_treeview), column);
98
99         renderer = gtk_cell_renderer_text_new ();
100         gtk_tree_view_column_pack_start (GTK_TREE_VIEW_COLUMN (column), renderer, FALSE);
101         gtk_tree_view_column_set_title (GTK_TREE_VIEW_COLUMN (column), _("Name"));
102         gtk_tree_view_column_set_attributes (GTK_TREE_VIEW_COLUMN (column), renderer,
103                                              "text", EV_DOCUMENT_FONTS_COLUMN_NAME,
104                                              NULL);
105 }
106
107 static void
108 update_progress_label (GtkWidget *label, double progress)
109 {
110         if (progress > 0) {
111                 char *progress_text;
112                 progress_text = g_strdup_printf (_("Gathering font information... %3d%%"),
113                                                  (int) (progress * 100));
114                 gtk_label_set_text (GTK_LABEL (label), progress_text);
115                 g_free (progress_text);
116                 gtk_widget_show (label);
117         } else {
118                 gtk_widget_hide (label);
119         }
120 }
121
122 static void
123 job_fonts_finished_cb (EvJob *job, EvPropertiesFonts *properties)
124 {       
125         EvDocumentFonts *document_fonts = EV_DOCUMENT_FONTS (job->document);
126         double progress;
127
128         progress = ev_document_fonts_get_progress (document_fonts);
129         update_progress_label (properties->fonts_progress_label, progress);
130
131         if (EV_JOB_FONTS (job)->scan_completed) {
132                 g_signal_handlers_disconnect_by_func
133                                 (job, job_fonts_finished_cb, properties);
134         } else {
135                 GtkTreeModel *model;
136                 EvJob *new_job;
137
138                 model = gtk_tree_view_get_model
139                                 (GTK_TREE_VIEW (properties->fonts_treeview));
140                 ev_document_doc_mutex_lock ();
141                 ev_document_fonts_fill_model (document_fonts, model);
142                 ev_document_doc_mutex_unlock ();
143                 new_job = ev_job_fonts_new (job->document);
144                 ev_job_queue_add_job (job, EV_JOB_PRIORITY_LOW);
145                 g_object_unref (new_job);
146         }
147 }
148
149 void
150 ev_properties_fonts_set_document (EvPropertiesFonts *properties,
151                                   EvDocument        *document)
152 {
153         GtkTreeView *tree_view = GTK_TREE_VIEW (properties->fonts_treeview);
154         GtkListStore *list_store;
155         EvJob *job;
156
157         properties->document = document;
158
159         list_store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING);
160         gtk_tree_view_set_model (tree_view, GTK_TREE_MODEL (list_store));
161
162         job = ev_job_fonts_new (properties->document);
163         g_signal_connect_object (job, "finished",
164                                  G_CALLBACK (job_fonts_finished_cb),
165                                  properties, 0);
166         ev_job_queue_add_job (job, EV_JOB_PRIORITY_LOW);
167         g_object_unref (job);
168 }
169
170 GtkWidget *
171 ev_properties_fonts_new ()
172 {
173         EvPropertiesFonts *properties;
174
175         properties = g_object_new (EV_TYPE_PROPERTIES_FONTS, NULL);
176
177         return GTK_WIDGET (properties);
178 }