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