23 #if GTKUNIXPRINT_ENABLED
24 #include <gtk/gtkunixprint.h>
26 #include <glib/gi18n.h>
49 #if GTKUNIXPRINT_ENABLED
65 #define MIN_SCALE 0.05409
75 screen = gtk_window_get_screen (GTK_WINDOW (window));
79 #if GTKUNIXPRINT_ENABLED
86 dialog = gtk_message_dialog_new (GTK_WINDOW (window),
88 GTK_DIALOG_DESTROY_WITH_PARENT,
91 "%s",
_(
"Failed to print document"));
92 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
93 "%s", error->message);
94 gtk_dialog_run (GTK_DIALOG (dialog));
95 gtk_widget_destroy (dialog);
103 gtk_widget_destroy (GTK_WIDGET (window));
141 gtk_toggle_action_get_active (action) ?
150 gtk_toggle_action_get_active (action) ?
160 gtk_widget_grab_focus (GTK_WIDGET (window->
view));
167 GtkAction *page_action;
169 page_action = gtk_action_group_get_action (window->
action_group,
174 #if GTKUNIXPRINT_ENABLED
176 ev_previewer_window_print_finished (GtkPrintJob *print_job,
181 ev_previewer_window_error_dialog_run (window, error);
184 g_object_unref (print_job);
185 gtk_widget_destroy (GTK_WIDGET (window));
192 GError *error = NULL;
200 if (gtk_print_job_set_source_file (job, window->
source_file, &error)) {
201 gtk_print_job_send (job,
202 (GtkPrintJobCompleteFunc)ev_previewer_window_print_finished,
205 ev_previewer_window_error_dialog_run (window, error);
206 g_error_free (error);
209 gtk_widget_hide (GTK_WIDGET (window));
215 if (window->printer) {
216 ev_previewer_window_do_print (window);
218 GError *error = NULL;
222 GTK_PRINT_ERROR_GENERAL,
223 _(
"The selected printer ā%sā could not be found"),
226 ev_previewer_window_error_dialog_run (window, error);
227 g_error_free (error);
232 ev_previewer_window_enumerate_printers (GtkPrinter *printer,
235 const gchar *printer_name;
237 printer_name = gtk_print_settings_get_printer (window->
print_settings);
239 && strcmp (printer_name, gtk_printer_get_name (printer)) == 0) ||
240 (!printer_name && gtk_printer_is_default (printer))) {
242 g_object_unref (window->printer);
243 window->printer = g_object_ref (printer);
252 ev_previewer_window_print (GtkAction *action,
259 gtk_enumerate_printers ((GtkPrinterFunc)ev_previewer_window_enumerate_printers,
261 (GDestroyNotify)ev_previewer_window_enumerate_finished,
267 {
"FileCloseWindow", GTK_STOCK_CLOSE, NULL,
"<control>W",
270 {
"GoPreviousPage", GTK_STOCK_GO_UP, N_(
"_Previous Page"),
"<control>Page_Up",
271 N_(
"Go to the previous page"),
273 {
"GoNextPage", GTK_STOCK_GO_DOWN, N_(
"_Next Page"),
"<control>Page_Down",
274 N_(
"Go to the next page"),
276 {
"ViewZoomIn", GTK_STOCK_ZOOM_IN, NULL,
"<control>plus",
277 N_(
"Enlarge the document"),
279 {
"ViewZoomOut", GTK_STOCK_ZOOM_OUT, NULL,
"<control>minus",
280 N_(
"Shrink the document"),
282 #if GTKUNIXPRINT_ENABLED
284 {
"PreviewPrint", GTK_STOCK_PRINT, N_(
"Print"), NULL,
285 N_(
"Print this document"),
286 G_CALLBACK (ev_previewer_window_print) }
291 {
"p", GTK_STOCK_GO_UP,
"",
"p", NULL,
293 {
"n", GTK_STOCK_GO_DOWN,
"",
"n", NULL,
295 {
"Plus", GTK_STOCK_ZOOM_IN, NULL,
"plus", NULL,
297 {
"CtrlEqual", GTK_STOCK_ZOOM_IN, NULL,
"<control>equal", NULL,
299 {
"Equal", GTK_STOCK_ZOOM_IN, NULL,
"equal", NULL,
301 {
"Minus", GTK_STOCK_ZOOM_OUT, NULL,
"minus", NULL,
303 {
"KpPlus", GTK_STOCK_ZOOM_IN, NULL,
"KP_Add", NULL,
305 {
"KpMinus", GTK_STOCK_ZOOM_OUT, NULL,
"KP_Subtract", NULL,
307 {
"CtrlKpPlus", GTK_STOCK_ZOOM_IN, NULL,
"<control>KP_Add", NULL,
309 {
"CtrlKpMinus", GTK_STOCK_ZOOM_OUT, NULL,
"<control>KP_Subtract", NULL,
311 {
"FocusPageSelector", NULL,
"",
"<control>l", NULL,
318 N_(
"Make the current document fill the window"),
321 N_(
"Make the current document fill the window width"),
327 GdkEventFocus *event,
331 gtk_action_group_set_sensitive (window->
accels_group, event->in);
345 action = gtk_action_group_get_action (window->
action_group,
"GoPreviousPage");
346 gtk_action_set_sensitive (GTK_ACTION (action), new_page > 0 );
348 action = gtk_action_group_get_action (window->
action_group,
"GoNextPage");
349 gtk_action_set_sensitive (GTK_ACTION (action), new_page < n_pages - 1);
360 action = gtk_action_group_get_action (window->
action_group,
"ViewFitPage");
361 g_signal_handlers_block_by_func (action,
364 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
366 g_signal_handlers_unblock_by_func (action,
370 action = gtk_action_group_get_action (window->
action_group,
"ViewFitWidth");
371 g_signal_handlers_block_by_func (action,
374 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
376 g_signal_handlers_unblock_by_func (action,
388 window->
document = g_object_ref (document);
390 g_signal_connect (model,
"notify::sizing-mode",
402 gtk_ui_manager_ensure_update (window->
ui_manager);
404 actions = gtk_action_group_list_actions (window->
action_group);
405 g_list_foreach (actions, (GFunc)gtk_action_connect_accelerator, NULL);
406 g_list_free (actions);
415 g_object_unref (window->
model);
416 window->
model = NULL;
449 #if GTKUNIXPRINT_ENABLED
450 if (window->printer) {
451 g_object_unref (window->printer);
452 window->printer = NULL;
466 G_OBJECT_CLASS (ev_previewer_window_parent_class)->dispose (
object);
472 gtk_window_set_default_size (GTK_WINDOW (window), 600, 600);
485 window->
model = g_value_dup_object (value);
488 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, prop_id, pspec);
494 const char *resource_path,
500 data = g_resources_lookup_data (resource_path, 0, error);
504 retval = gtk_css_provider_load_from_data (provider,
505 g_bytes_get_data (data, NULL),
506 g_bytes_get_size (data),
508 g_bytes_unref (data);
515 guint n_construct_properties,
516 GObjectConstructParam *construct_params)
523 GError *error = NULL;
525 GtkCssProvider *css_provider;
527 object = G_OBJECT_CLASS (ev_previewer_window_parent_class)->constructor (type,
528 n_construct_properties,
536 g_signal_connect_swapped (window->
model,
"notify::document",
540 window->
action_group = gtk_action_group_new (
"PreviewerActions");
541 gtk_action_group_set_translation_domain (window->
action_group, NULL);
542 gtk_action_group_add_actions (window->
action_group, action_entries,
543 G_N_ELEMENTS (action_entries),
545 gtk_action_group_add_toggle_actions (window->
action_group, toggle_action_entries,
546 G_N_ELEMENTS (toggle_action_entries),
551 "name",
"PageSelector",
553 "tooltip",
_(
"Select Page"),
554 "icon_name",
"text-x-generic",
555 "visible_overflown",
FALSE,
558 g_signal_connect (action,
"activate_link",
561 gtk_action_group_add_action (window->
action_group, action);
562 g_object_unref (action);
564 window->
accels_group = gtk_action_group_new (
"PreviewerAccelerators");
565 gtk_action_group_add_actions (window->
accels_group, accel_entries,
566 G_N_ELEMENTS (accel_entries),
570 css_provider = gtk_css_provider_new ();
572 "/org/gnome/evince/previewer/ui/evince-previewer.css",
574 g_assert_no_error (error);
575 gtk_style_context_add_provider_for_screen (gtk_widget_get_screen (GTK_WIDGET (window)),
576 GTK_STYLE_PROVIDER (css_provider),
577 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
578 g_object_unref (css_provider);
581 gtk_ui_manager_insert_action_group (window->
ui_manager,
583 gtk_ui_manager_insert_action_group (window->
ui_manager,
585 gtk_window_add_accel_group (GTK_WINDOW (window),
586 gtk_ui_manager_get_accel_group (window->
ui_manager));
588 gtk_ui_manager_add_ui_from_resource (window->
ui_manager,
"/org/gnome/evince/previewer/ui/previewer.xml", &error);
589 g_assert_no_error (error);
598 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
600 toolbar = gtk_ui_manager_get_widget (window->
ui_manager,
"/PreviewToolbar");
601 gtk_style_context_add_class (gtk_widget_get_style_context (toolbar),
602 GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
603 gtk_box_pack_start (GTK_BOX (vbox), toolbar,
FALSE,
FALSE, 0);
604 gtk_widget_show (toolbar);
606 window->
swindow = gtk_scrolled_window_new (NULL, NULL);
609 g_signal_connect_object (window->
view,
"focus_in_event",
612 g_signal_connect_object (window->
view,
"focus_out_event",
618 g_signal_connect_object (window->
model,
"page-changed",
622 gtk_container_add (GTK_CONTAINER (window->
swindow), GTK_WIDGET (window->
view));
623 gtk_widget_show (GTK_WIDGET (window->
view));
626 gtk_widget_show (window->
swindow);
628 gtk_container_add (GTK_CONTAINER (window), vbox);
629 gtk_widget_show (vbox);
638 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
644 g_object_class_install_property (gobject_class,
646 g_param_spec_object (
"model",
648 "The document model",
651 G_PARAM_CONSTRUCT_ONLY));
659 "application", g_application_get_default (),
675 if (print_settings && g_file_test (print_settings, G_FILE_TEST_IS_REGULAR)) {
677 GError *error = NULL;
679 key_file = g_key_file_new ();
680 g_key_file_load_from_file (key_file,
682 G_KEY_FILE_KEEP_COMMENTS |
683 G_KEY_FILE_KEEP_TRANSLATIONS,
686 GtkPrintSettings *psettings;
687 GtkPageSetup *psetup;
690 psettings = gtk_print_settings_new_from_key_file (key_file,
693 window->
print_settings = psettings ? psettings : gtk_print_settings_new ();
695 psetup = gtk_page_setup_new_from_key_file (key_file,
700 job_name = g_key_file_get_string (key_file,
701 "Print Job",
"title",
705 gtk_window_set_title (GTK_WINDOW (window), job_name);
710 g_error_free (error);
713 g_key_file_free (key_file);
722 const gchar *source_file)