2
* Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2, or (at your option)
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
25
LINKS_ACTION_TYPE_COLUMN,
38
GtkWidget *action_view;
39
GtkWidget *timer_label;
45
pgd_links_free (PgdLinksDemo *demo)
51
g_object_unref (demo->doc);
56
g_object_unref (demo->model);
64
pgd_links_get_links (GtkWidget *button,
72
gtk_list_store_clear (demo->model);
73
pgd_action_view_set_action (demo->action_view, NULL);
75
page = poppler_document_get_page (demo->doc, demo->page);
79
timer = g_timer_new ();
80
mapping = poppler_page_get_link_mapping (page);
83
n_links = g_list_length (mapping);
87
str = g_strdup_printf ("<i>%d links found in %.4f seconds</i>",
88
n_links, g_timer_elapsed (timer, NULL));
89
gtk_label_set_markup (GTK_LABEL (demo->timer_label), str);
92
gtk_label_set_markup (GTK_LABEL (demo->timer_label), "<i>No links found</i>");
95
g_timer_destroy (timer);
97
for (l = mapping; l; l = g_list_next (l)) {
98
PopplerLinkMapping *lmapping;
99
PopplerAction *action;
100
GEnumValue *enum_value;
102
gchar *x1, *y1, *x2, *y2;
104
lmapping = (PopplerLinkMapping *)l->data;
105
action = poppler_action_copy (lmapping->action);
106
enum_value = g_enum_get_value ((GEnumClass *) g_type_class_ref (POPPLER_TYPE_ACTION_TYPE), action->type);
108
x1 = g_strdup_printf ("%.2f", lmapping->area.x1);
109
y1 = g_strdup_printf ("%.2f", lmapping->area.y1);
110
x2 = g_strdup_printf ("%.2f", lmapping->area.x2);
111
y2 = g_strdup_printf ("%.2f", lmapping->area.y2);
113
gtk_list_store_append (demo->model, &iter);
114
gtk_list_store_set (demo->model, &iter,
115
LINKS_ACTION_TYPE_COLUMN, enum_value->value_name,
120
LINKS_ACTION_COLUMN, action,
127
g_object_weak_ref (G_OBJECT (demo->model),
128
(GWeakNotify)poppler_action_free,
132
poppler_page_free_link_mapping (mapping);
133
g_object_unref (page);
137
pgd_links_page_selector_value_changed (GtkSpinButton *spinbutton,
140
demo->page = (gint)gtk_spin_button_get_value (spinbutton) - 1;
144
pgd_links_selection_changed (GtkTreeSelection *treeselection,
150
if (gtk_tree_selection_get_selected (treeselection, &model, &iter)) {
151
PopplerAction *action;
153
gtk_tree_model_get (model, &iter,
154
LINKS_ACTION_COLUMN, &action,
156
pgd_action_view_set_action (demo->action_view, action);
161
pgd_links_create_widget (PopplerDocument *document)
166
GtkWidget *hbox, *page_selector;
169
GtkWidget *swindow, *treeview;
170
GtkTreeSelection *selection;
171
GtkCellRenderer *renderer;
175
demo = g_new0 (PgdLinksDemo, 1);
177
demo->doc = g_object_ref (document);
179
n_pages = poppler_document_get_n_pages (document);
181
vbox = gtk_vbox_new (FALSE, 12);
183
hbox = gtk_hbox_new (FALSE, 6);
185
label = gtk_label_new ("Page:");
186
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
187
gtk_widget_show (label);
189
page_selector = gtk_spin_button_new_with_range (1, n_pages, 1);
190
g_signal_connect (G_OBJECT (page_selector), "value-changed",
191
G_CALLBACK (pgd_links_page_selector_value_changed),
193
gtk_box_pack_start (GTK_BOX (hbox), page_selector, FALSE, TRUE, 0);
194
gtk_widget_show (page_selector);
196
str = g_strdup_printf ("of %d", n_pages);
197
label = gtk_label_new (str);
198
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
199
gtk_widget_show (label);
202
button = gtk_button_new_with_label ("Get Links");
203
g_signal_connect (G_OBJECT (button), "clicked",
204
G_CALLBACK (pgd_links_get_links),
206
gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
207
gtk_widget_show (button);
209
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
210
gtk_widget_show (hbox);
212
demo->timer_label = gtk_label_new (NULL);
213
gtk_label_set_markup (GTK_LABEL (demo->timer_label), "<i>No links found</i>");
214
g_object_set (G_OBJECT (demo->timer_label), "xalign", 1.0, NULL);
215
gtk_box_pack_start (GTK_BOX (vbox), demo->timer_label, FALSE, TRUE, 0);
216
gtk_widget_show (demo->timer_label);
218
hpaned = gtk_hpaned_new ();
220
demo->action_view = pgd_action_view_new (document);
222
swindow = gtk_scrolled_window_new (NULL, NULL);
223
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
224
GTK_POLICY_AUTOMATIC,
225
GTK_POLICY_AUTOMATIC);
227
demo->model = gtk_list_store_new (N_COLUMNS,
228
G_TYPE_STRING, G_TYPE_STRING,
229
G_TYPE_STRING, G_TYPE_STRING,
230
G_TYPE_STRING, G_TYPE_POINTER);
231
treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (demo->model));
233
renderer = gtk_cell_renderer_text_new ();
234
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
237
"text", LINKS_ACTION_TYPE_COLUMN,
240
renderer = gtk_cell_renderer_text_new ();
241
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
244
"text", LINKS_X1_COLUMN,
246
renderer = gtk_cell_renderer_text_new ();
247
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
250
"text", LINKS_Y1_COLUMN,
252
renderer = gtk_cell_renderer_text_new ();
253
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
256
"text", LINKS_X2_COLUMN,
258
renderer = gtk_cell_renderer_text_new ();
259
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
262
"text", LINKS_Y2_COLUMN,
265
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
266
g_signal_connect (G_OBJECT (selection), "changed",
267
G_CALLBACK (pgd_links_selection_changed),
270
gtk_container_add (GTK_CONTAINER (swindow), treeview);
271
gtk_widget_show (treeview);
273
gtk_paned_add1 (GTK_PANED (hpaned), swindow);
274
gtk_widget_show (swindow);
276
gtk_paned_add2 (GTK_PANED (hpaned), demo->action_view);
277
gtk_widget_show (demo->action_view);
279
gtk_paned_set_position (GTK_PANED (hpaned), 300);
281
gtk_box_pack_start (GTK_BOX (vbox), hpaned, TRUE, TRUE, 0);
282
gtk_widget_show (hpaned);
284
g_object_weak_ref (G_OBJECT (vbox),
285
(GWeakNotify)pgd_links_free,