1 | /*
|
---|
2 | * Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
|
---|
3 | *
|
---|
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)
|
---|
7 | * any later version.
|
---|
8 | *
|
---|
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.
|
---|
13 | *
|
---|
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.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include <gtk/gtk.h>
|
---|
20 |
|
---|
21 | #include "transitions.h"
|
---|
22 |
|
---|
23 | enum {
|
---|
24 | TRANSITIONS_PAGE_COLUMN,
|
---|
25 | TRANSITIONS_TYPE_COLUMN,
|
---|
26 | TRANSITIONS_ALIGNMENT_COLUMN,
|
---|
27 | TRANSITIONS_DIRECTION_COLUMN,
|
---|
28 | TRANSITIONS_DURATION_COLUMN,
|
---|
29 | TRANSITIONS_ANGLE_COLUMN,
|
---|
30 | TRANSITIONS_SCALE_COLUMN,
|
---|
31 | TRANSITIONS_RECTANGULAR_COLUMN,
|
---|
32 | N_COLUMNS
|
---|
33 | };
|
---|
34 |
|
---|
35 | typedef struct {
|
---|
36 | PopplerDocument *doc;
|
---|
37 |
|
---|
38 | GtkWidget *treeview;
|
---|
39 | GtkWidget *progress;
|
---|
40 |
|
---|
41 | guint idle_id;
|
---|
42 | } PgdTransitionsDemo;
|
---|
43 |
|
---|
44 | static void
|
---|
45 | pgd_transitions_free (PgdTransitionsDemo *demo)
|
---|
46 | {
|
---|
47 | if (!demo)
|
---|
48 | return;
|
---|
49 |
|
---|
50 | if (demo->idle_id > 0) {
|
---|
51 | g_source_remove (demo->idle_id);
|
---|
52 | demo->idle_id = 0;
|
---|
53 | }
|
---|
54 |
|
---|
55 | if (demo->doc) {
|
---|
56 | g_object_unref (demo->doc);
|
---|
57 | demo->doc = NULL;
|
---|
58 | }
|
---|
59 |
|
---|
60 | g_free (demo);
|
---|
61 | }
|
---|
62 |
|
---|
63 | static const gchar *
|
---|
64 | transition_type_to_string (PopplerPageTransitionType type)
|
---|
65 | {
|
---|
66 | switch (type) {
|
---|
67 | case POPPLER_PAGE_TRANSITION_REPLACE:
|
---|
68 | return "Replace";
|
---|
69 | case POPPLER_PAGE_TRANSITION_SPLIT:
|
---|
70 | return "Split";
|
---|
71 | case POPPLER_PAGE_TRANSITION_BLINDS:
|
---|
72 | return "Blinds";
|
---|
73 | case POPPLER_PAGE_TRANSITION_BOX:
|
---|
74 | return "Box";
|
---|
75 | case POPPLER_PAGE_TRANSITION_WIPE:
|
---|
76 | return "Wipe";
|
---|
77 | case POPPLER_PAGE_TRANSITION_DISSOLVE:
|
---|
78 | return "Dissolve";
|
---|
79 | case POPPLER_PAGE_TRANSITION_GLITTER:
|
---|
80 | return "Glitter";
|
---|
81 | case POPPLER_PAGE_TRANSITION_FLY:
|
---|
82 | return "Fly";
|
---|
83 | case POPPLER_PAGE_TRANSITION_PUSH:
|
---|
84 | return "Push";
|
---|
85 | case POPPLER_PAGE_TRANSITION_COVER:
|
---|
86 | return "Cover";
|
---|
87 | case POPPLER_PAGE_TRANSITION_UNCOVER:
|
---|
88 | return "Uncover";
|
---|
89 | case POPPLER_PAGE_TRANSITION_FADE:
|
---|
90 | return "Fade";
|
---|
91 | }
|
---|
92 |
|
---|
93 | return "Unknown";
|
---|
94 | }
|
---|
95 |
|
---|
96 | static const gchar *
|
---|
97 | transition_alignment_to_string (PopplerPageTransitionAlignment alignment)
|
---|
98 | {
|
---|
99 | return alignment == POPPLER_PAGE_TRANSITION_HORIZONTAL ? "Horizontal" : "Vertical";
|
---|
100 | }
|
---|
101 |
|
---|
102 | static const gchar *
|
---|
103 | transition_direction_to_string (PopplerPageTransitionDirection direction)
|
---|
104 | {
|
---|
105 | return direction == POPPLER_PAGE_TRANSITION_INWARD ? "Inward" : "Outward";
|
---|
106 | }
|
---|
107 |
|
---|
108 | static void
|
---|
109 | pgd_transitions_update_progress (PgdTransitionsDemo *demo,
|
---|
110 | gint n_pages,
|
---|
111 | gint scanned)
|
---|
112 | {
|
---|
113 | gchar *str;
|
---|
114 |
|
---|
115 | str = g_strdup_printf ("Scanning transitions (%d%%)",
|
---|
116 | MIN (scanned * 100 / n_pages, 100));
|
---|
117 | gtk_progress_bar_set_text (GTK_PROGRESS_BAR (demo->progress), str);
|
---|
118 | gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (demo->progress),
|
---|
119 | MIN ((gdouble)scanned / n_pages, 1.0));
|
---|
120 | g_free (str);
|
---|
121 | }
|
---|
122 |
|
---|
123 | static gboolean
|
---|
124 | pgd_transitions_fill_model (PgdTransitionsDemo *demo)
|
---|
125 | {
|
---|
126 | GtkTreeModel *model;
|
---|
127 | gint i, n_pages;
|
---|
128 |
|
---|
129 | n_pages = poppler_document_get_n_pages (demo->doc);
|
---|
130 |
|
---|
131 | model = gtk_tree_view_get_model (GTK_TREE_VIEW (demo->treeview));
|
---|
132 | g_object_ref (model);
|
---|
133 |
|
---|
134 | for (i = 0; i < n_pages; i++) {
|
---|
135 | PopplerPage *page;
|
---|
136 | PopplerPageTransition *transition;
|
---|
137 |
|
---|
138 | pgd_transitions_update_progress (demo, n_pages, i);
|
---|
139 |
|
---|
140 | while (gtk_events_pending ())
|
---|
141 | gtk_main_iteration ();
|
---|
142 |
|
---|
143 | page = poppler_document_get_page (demo->doc, i);
|
---|
144 | if (!page)
|
---|
145 | continue;
|
---|
146 |
|
---|
147 | transition = poppler_page_get_transition (page);
|
---|
148 | if (transition) {
|
---|
149 | GtkTreeIter iter;
|
---|
150 | gchar *npage;
|
---|
151 | gchar *duration;
|
---|
152 | gchar *angle;
|
---|
153 | gchar *scale;
|
---|
154 |
|
---|
155 | npage = g_strdup_printf ("%d", i + 1);
|
---|
156 | duration = g_strdup_printf ("%d", transition->duration);
|
---|
157 | angle = g_strdup_printf ("%d", transition->angle);
|
---|
158 | scale = g_strdup_printf ("%.2f", transition->scale);
|
---|
159 |
|
---|
160 | gtk_list_store_append (GTK_LIST_STORE (model), &iter);
|
---|
161 | gtk_list_store_set (GTK_LIST_STORE (model), &iter,
|
---|
162 | TRANSITIONS_PAGE_COLUMN, npage,
|
---|
163 | TRANSITIONS_TYPE_COLUMN,
|
---|
164 | transition_type_to_string (transition->type),
|
---|
165 | TRANSITIONS_ALIGNMENT_COLUMN,
|
---|
166 | transition_alignment_to_string (transition->alignment),
|
---|
167 | TRANSITIONS_DIRECTION_COLUMN,
|
---|
168 | transition_direction_to_string (transition->direction),
|
---|
169 | TRANSITIONS_DURATION_COLUMN, duration,
|
---|
170 | TRANSITIONS_ANGLE_COLUMN, angle,
|
---|
171 | TRANSITIONS_SCALE_COLUMN, scale,
|
---|
172 | TRANSITIONS_RECTANGULAR_COLUMN,
|
---|
173 | transition->rectangular ? "Yes" : "No",
|
---|
174 | -1);
|
---|
175 | g_free (npage);
|
---|
176 | g_free (duration);
|
---|
177 | g_free (angle);
|
---|
178 | g_free (scale);
|
---|
179 |
|
---|
180 | poppler_page_transition_free (transition);
|
---|
181 | }
|
---|
182 |
|
---|
183 | g_object_unref (page);
|
---|
184 | }
|
---|
185 |
|
---|
186 | pgd_transitions_update_progress (demo, n_pages, n_pages);
|
---|
187 | g_object_unref (model);
|
---|
188 |
|
---|
189 | return FALSE;
|
---|
190 | }
|
---|
191 |
|
---|
192 | static void
|
---|
193 | pgd_transitions_scan_button_clicked (GtkButton *button,
|
---|
194 | PgdTransitionsDemo *demo)
|
---|
195 | {
|
---|
196 | if (demo->idle_id > 0)
|
---|
197 | g_source_remove (demo->idle_id);
|
---|
198 |
|
---|
199 | demo->idle_id = g_idle_add ((GSourceFunc)pgd_transitions_fill_model, demo);
|
---|
200 | }
|
---|
201 |
|
---|
202 | static GtkWidget *
|
---|
203 | pgd_transitions_create_list (GtkTreeModel *model)
|
---|
204 | {
|
---|
205 | GtkWidget *treeview;
|
---|
206 | GtkCellRenderer *renderer;
|
---|
207 |
|
---|
208 | treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
|
---|
209 | gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), TRUE);
|
---|
210 | gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)),
|
---|
211 | GTK_SELECTION_NONE);
|
---|
212 |
|
---|
213 | renderer = gtk_cell_renderer_text_new ();
|
---|
214 | gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
|
---|
215 | 0, "Page",
|
---|
216 | renderer,
|
---|
217 | "text", TRANSITIONS_PAGE_COLUMN,
|
---|
218 | NULL);
|
---|
219 | renderer = gtk_cell_renderer_text_new ();
|
---|
220 | gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
|
---|
221 | 1, "Type",
|
---|
222 | renderer,
|
---|
223 | "text", TRANSITIONS_TYPE_COLUMN,
|
---|
224 | NULL);
|
---|
225 | renderer = gtk_cell_renderer_text_new ();
|
---|
226 | gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
|
---|
227 | 2, "Alignment",
|
---|
228 | renderer,
|
---|
229 | "text", TRANSITIONS_ALIGNMENT_COLUMN,
|
---|
230 | NULL);
|
---|
231 | renderer = gtk_cell_renderer_text_new ();
|
---|
232 | gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
|
---|
233 | 3, "Direction",
|
---|
234 | renderer,
|
---|
235 | "text", TRANSITIONS_DIRECTION_COLUMN,
|
---|
236 | NULL);
|
---|
237 | renderer = gtk_cell_renderer_text_new ();
|
---|
238 | gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
|
---|
239 | 4, "Duration",
|
---|
240 | renderer,
|
---|
241 | "text", TRANSITIONS_DURATION_COLUMN,
|
---|
242 | NULL);
|
---|
243 | renderer = gtk_cell_renderer_text_new ();
|
---|
244 | gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
|
---|
245 | 5, "Angle",
|
---|
246 | renderer,
|
---|
247 | "text", TRANSITIONS_ANGLE_COLUMN,
|
---|
248 | NULL);
|
---|
249 | renderer = gtk_cell_renderer_text_new ();
|
---|
250 | gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
|
---|
251 | 6, "Scale",
|
---|
252 | renderer,
|
---|
253 | "text", TRANSITIONS_SCALE_COLUMN,
|
---|
254 | NULL);
|
---|
255 | renderer = gtk_cell_renderer_text_new ();
|
---|
256 | gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
|
---|
257 | 7, "Rectangular",
|
---|
258 | renderer,
|
---|
259 | "text", TRANSITIONS_RECTANGULAR_COLUMN,
|
---|
260 | NULL);
|
---|
261 | return treeview;
|
---|
262 | }
|
---|
263 |
|
---|
264 | GtkWidget *
|
---|
265 | pgd_transitions_create_widget (PopplerDocument *document)
|
---|
266 | {
|
---|
267 | PgdTransitionsDemo *demo;
|
---|
268 | GtkWidget *vbox;
|
---|
269 | GtkListStore *model;
|
---|
270 | GtkWidget *swindow;
|
---|
271 | GtkWidget *hbox, *button;
|
---|
272 |
|
---|
273 | demo = g_new0 (PgdTransitionsDemo, 1);
|
---|
274 |
|
---|
275 | demo->doc = g_object_ref (document);
|
---|
276 |
|
---|
277 | vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
|
---|
278 |
|
---|
279 | hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
|
---|
280 |
|
---|
281 | demo->progress = gtk_progress_bar_new ();
|
---|
282 | gtk_progress_bar_set_ellipsize (GTK_PROGRESS_BAR (demo->progress),
|
---|
283 | PANGO_ELLIPSIZE_END);
|
---|
284 | gtk_box_pack_start (GTK_BOX (hbox), demo->progress, TRUE, TRUE, 0);
|
---|
285 | gtk_widget_show (demo->progress);
|
---|
286 |
|
---|
287 | button = gtk_button_new_with_label ("Scan");
|
---|
288 | g_signal_connect (G_OBJECT (button), "clicked",
|
---|
289 | G_CALLBACK (pgd_transitions_scan_button_clicked),
|
---|
290 | (gpointer)demo);
|
---|
291 | gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
|
---|
292 | gtk_widget_show (button);
|
---|
293 |
|
---|
294 | gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 6);
|
---|
295 | gtk_widget_show (hbox);
|
---|
296 |
|
---|
297 | swindow = gtk_scrolled_window_new (NULL, NULL);
|
---|
298 | gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
|
---|
299 | GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
---|
300 |
|
---|
301 | model = gtk_list_store_new (N_COLUMNS,
|
---|
302 | G_TYPE_STRING, G_TYPE_STRING,
|
---|
303 | G_TYPE_STRING, G_TYPE_STRING,
|
---|
304 | G_TYPE_STRING, G_TYPE_STRING,
|
---|
305 | G_TYPE_STRING, G_TYPE_STRING);
|
---|
306 | demo->treeview = pgd_transitions_create_list (GTK_TREE_MODEL (model));
|
---|
307 | g_object_unref (model);
|
---|
308 |
|
---|
309 | gtk_container_add (GTK_CONTAINER (swindow), demo->treeview);
|
---|
310 | gtk_widget_show (demo->treeview);
|
---|
311 |
|
---|
312 | gtk_box_pack_start (GTK_BOX (vbox), swindow, TRUE, TRUE, 0);
|
---|
313 | gtk_widget_show (swindow);
|
---|
314 |
|
---|
315 | g_object_weak_ref (G_OBJECT (swindow),
|
---|
316 | (GWeakNotify)pgd_transitions_free,
|
---|
317 | (gpointer)demo);
|
---|
318 |
|
---|
319 | return vbox;
|
---|
320 | }
|
---|