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 "config.h"
22 #include "info.h"
23 #include "utils.h"
24
pgd_info_add_permissions(GtkGrid * table,PopplerPermissions permissions,gint * row)25 static void pgd_info_add_permissions(GtkGrid *table, PopplerPermissions permissions, gint *row)
26 {
27 GtkWidget *label, *hbox, *vbox;
28 GtkWidget *checkbox;
29
30 label = gtk_label_new(nullptr);
31 g_object_set(G_OBJECT(label), "xalign", 0.0, NULL);
32 gtk_label_set_markup(GTK_LABEL(label), "<b>Permissions:</b>");
33 gtk_grid_attach(GTK_GRID(table), label, 0, *row, 1, 1);
34 gtk_widget_show(label);
35
36 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
37 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
38
39 checkbox = gtk_check_button_new_with_label("Print");
40 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), (permissions & POPPLER_PERMISSIONS_OK_TO_PRINT));
41 gtk_box_pack_start(GTK_BOX(hbox), checkbox, FALSE, TRUE, 0);
42 gtk_widget_show(checkbox);
43
44 checkbox = gtk_check_button_new_with_label("Copy");
45 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), (permissions & POPPLER_PERMISSIONS_OK_TO_COPY));
46 gtk_box_pack_start(GTK_BOX(hbox), checkbox, FALSE, TRUE, 0);
47 gtk_widget_show(checkbox);
48
49 checkbox = gtk_check_button_new_with_label("Modify");
50 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), (permissions & POPPLER_PERMISSIONS_OK_TO_MODIFY));
51 gtk_box_pack_start(GTK_BOX(hbox), checkbox, FALSE, TRUE, 0);
52 gtk_widget_show(checkbox);
53
54 checkbox = gtk_check_button_new_with_label("Add notes");
55 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), (permissions & POPPLER_PERMISSIONS_OK_TO_ADD_NOTES));
56 gtk_box_pack_start(GTK_BOX(hbox), checkbox, FALSE, TRUE, 0);
57 gtk_widget_show(checkbox);
58
59 checkbox = gtk_check_button_new_with_label("Fill forms");
60 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), (permissions & POPPLER_PERMISSIONS_OK_TO_FILL_FORM));
61 gtk_box_pack_start(GTK_BOX(hbox), checkbox, FALSE, TRUE, 0);
62 gtk_widget_show(checkbox);
63
64 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
65 gtk_widget_show(hbox);
66
67 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
68
69 checkbox = gtk_check_button_new_with_label("Extract contents");
70 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), (permissions & POPPLER_PERMISSIONS_OK_TO_EXTRACT_CONTENTS));
71 gtk_box_pack_start(GTK_BOX(hbox), checkbox, FALSE, TRUE, 0);
72 gtk_widget_show(checkbox);
73
74 checkbox = gtk_check_button_new_with_label("Assemble");
75 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), (permissions & POPPLER_PERMISSIONS_OK_TO_ASSEMBLE));
76 gtk_box_pack_start(GTK_BOX(hbox), checkbox, FALSE, TRUE, 0);
77 gtk_widget_show(checkbox);
78
79 checkbox = gtk_check_button_new_with_label("Print at high resolution");
80 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox), (permissions & POPPLER_PERMISSIONS_OK_TO_PRINT_HIGH_RESOLUTION));
81 gtk_box_pack_start(GTK_BOX(hbox), checkbox, FALSE, TRUE, 0);
82 gtk_widget_show(checkbox);
83
84 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
85 gtk_widget_show(hbox);
86
87 gtk_grid_attach(GTK_GRID(table), vbox, 1, *row, 1, 1);
88 gtk_widget_show(vbox);
89
90 *row += 1;
91 }
92
pgd_info_add_metadata(GtkGrid * table,const gchar * metadata,gint * row)93 static void pgd_info_add_metadata(GtkGrid *table, const gchar *metadata, gint *row)
94 {
95 GtkWidget *label;
96 GtkWidget *textview, *swindow;
97 GtkTextBuffer *buffer;
98
99 label = gtk_label_new(nullptr);
100 g_object_set(G_OBJECT(label), "xalign", 0.0, NULL);
101 gtk_label_set_markup(GTK_LABEL(label), "<b>Metadata:</b>");
102 gtk_grid_attach(GTK_GRID(table), label, 0, *row, 1, 1);
103 gtk_widget_show(label);
104
105 swindow = gtk_scrolled_window_new(nullptr, nullptr);
106 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
107
108 textview = gtk_text_view_new();
109 gtk_text_view_set_editable(GTK_TEXT_VIEW(textview), FALSE);
110 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
111 if (metadata)
112 gtk_text_buffer_set_text(buffer, metadata, -1);
113
114 gtk_container_add(GTK_CONTAINER(swindow), textview);
115 gtk_widget_show(textview);
116
117 gtk_grid_attach(GTK_GRID(table), swindow, 1, *row, 1, 1);
118 gtk_widget_set_hexpand(swindow, TRUE);
119 gtk_widget_set_vexpand(swindow, TRUE);
120 gtk_widget_show(swindow);
121
122 *row += 1;
123 }
124
pgd_info_create_widget(PopplerDocument * document)125 GtkWidget *pgd_info_create_widget(PopplerDocument *document)
126 {
127 GtkWidget *vbox;
128 GtkWidget *label;
129 GtkWidget *frame, *table;
130 gchar *str;
131 gchar *title, *format, *author, *subject;
132 gchar *keywords, *creator, *producer;
133 gchar *metadata;
134 gchar *perm_id;
135 gchar *up_id;
136 gboolean linearized;
137 GDateTime *creation_date, *mod_date;
138 GEnumValue *enum_value;
139 PopplerBackend backend;
140 PopplerPageLayout layout;
141 PopplerPageMode mode;
142 PopplerPermissions permissions;
143 PopplerViewerPreferences view_prefs;
144 gint row = 0;
145
146 g_object_get(document, "title", &title, "format", &format, "author", &author, "subject", &subject, "keywords", &keywords, "creation-datetime", &creation_date, "mod-datetime", &mod_date, "creator", &creator, "producer", &producer,
147 "linearized", &linearized, "page-mode", &mode, "page-layout", &layout, "permissions", &permissions, "viewer-preferences", &view_prefs, "metadata", &metadata, NULL);
148
149 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 12);
150
151 backend = poppler_get_backend();
152 enum_value = g_enum_get_value((GEnumClass *)g_type_class_ref(POPPLER_TYPE_BACKEND), backend);
153 str = g_strdup_printf("<span weight='bold' size='larger'>Poppler %s (%s)</span>", poppler_get_version(), enum_value->value_name);
154 label = gtk_label_new(nullptr);
155 gtk_label_set_markup(GTK_LABEL(label), str);
156 g_free(str);
157 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 12);
158 gtk_widget_show(label);
159
160 frame = gtk_frame_new(nullptr);
161 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE);
162 label = gtk_label_new(nullptr);
163 gtk_label_set_markup(GTK_LABEL(label), "<b>Document properties</b>");
164 gtk_frame_set_label_widget(GTK_FRAME(frame), label);
165 gtk_widget_show(label);
166
167 table = gtk_grid_new();
168 gtk_widget_set_margin_top(table, 5);
169 gtk_widget_set_margin_bottom(table, 5);
170 #if GTK_CHECK_VERSION(3, 12, 0)
171 gtk_widget_set_margin_start(table, 12);
172 gtk_widget_set_margin_end(table, 5);
173 #else
174 gtk_widget_set_margin_left(table, 12);
175 gtk_widget_set_margin_right(table, 5);
176 #endif
177 gtk_grid_set_column_spacing(GTK_GRID(table), 6);
178 gtk_grid_set_row_spacing(GTK_GRID(table), 6);
179
180 pgd_table_add_property(GTK_GRID(table), "<b>Format:</b>", format, &row);
181 g_free(format);
182
183 pgd_table_add_property(GTK_GRID(table), "<b>Title:</b>", title, &row);
184 g_free(title);
185
186 pgd_table_add_property(GTK_GRID(table), "<b>Author:</b>", author, &row);
187 g_free(author);
188
189 pgd_table_add_property(GTK_GRID(table), "<b>Subject:</b>", subject, &row);
190 g_free(subject);
191
192 pgd_table_add_property(GTK_GRID(table), "<b>Keywords:</b>", keywords, &row);
193 g_free(keywords);
194
195 pgd_table_add_property(GTK_GRID(table), "<b>Creator:</b>", creator, &row);
196 g_free(creator);
197
198 pgd_table_add_property(GTK_GRID(table), "<b>Producer:</b>", producer, &row);
199 g_free(producer);
200
201 pgd_table_add_property(GTK_GRID(table), "<b>Linearized:</b>", linearized ? "Yes" : "No", &row);
202
203 str = g_date_time_format(creation_date, "%c");
204 pgd_table_add_property(GTK_GRID(table), "<b>Creation Date:</b>", str, &row);
205 g_clear_pointer(&creation_date, g_date_time_unref);
206 g_free(str);
207
208 str = g_date_time_format(mod_date, "%c");
209 pgd_table_add_property(GTK_GRID(table), "<b>Modification Date:</b>", str, &row);
210 g_clear_pointer(&mod_date, g_date_time_unref);
211 g_free(str);
212
213 enum_value = g_enum_get_value((GEnumClass *)g_type_class_peek(POPPLER_TYPE_PAGE_MODE), mode);
214 pgd_table_add_property(GTK_GRID(table), "<b>Page Mode:</b>", enum_value->value_name, &row);
215
216 enum_value = g_enum_get_value((GEnumClass *)g_type_class_peek(POPPLER_TYPE_PAGE_LAYOUT), layout);
217 pgd_table_add_property(GTK_GRID(table), "<b>Page Layout:</b>", enum_value->value_name, &row);
218
219 if (poppler_document_get_id(document, &perm_id, &up_id)) {
220 str = g_strndup(perm_id, 32);
221 g_free(perm_id);
222 pgd_table_add_property(GTK_GRID(table), "<b>Permanent ID:</b>", str, &row);
223 g_free(str);
224 str = g_strndup(up_id, 32);
225 g_free(up_id);
226 pgd_table_add_property(GTK_GRID(table), "<b>Update ID:</b>", str, &row);
227 g_free(str);
228 }
229
230 pgd_info_add_permissions(GTK_GRID(table), permissions, &row);
231
232 pgd_info_add_metadata(GTK_GRID(table), metadata, &row);
233 g_free(metadata);
234
235 /* TODO: view_prefs */
236
237 gtk_container_add(GTK_CONTAINER(frame), table);
238 gtk_widget_show(table);
239
240 gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
241 gtk_widget_show(frame);
242
243 return vbox;
244 }
245