summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDan Nicholson <dbn.lists@gmail.com>2013-02-12 06:29:47 -0800
committerDan Nicholson <dbn.lists@gmail.com>2013-02-12 06:29:47 -0800
commitfe4d2d43436d2562b9cebe02d68246aa4449f93c (patch)
tree9492526bc6c6bb1d2c9bcc0d32c5a398c65202b2 /src
parent06e7ec064faa2a41a6665f335294c16775592eef (diff)
Add a print button to the toolbar
Print the document from the toolbar or via Ctrl-p using the ev-print-operation backend. This is different than the Print dialog from the browser, which has a NPAPI interface to pass back a block of PostScript. That doesn't seem to be working from firefox, but this usage is probably what people typically want anyway (print the document rather than just what appears on the web page).
Diffstat (limited to 'src')
-rw-r--r--src/evbp-viewer.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/evbp-viewer.c b/src/evbp-viewer.c
index 1c7ad70..1f19f6a 100644
--- a/src/evbp-viewer.c
+++ b/src/evbp-viewer.c
@@ -170,6 +170,58 @@ evbp_viewer_open_evince(GtkAction *action, EvbpViewer *viewer)
}
static void
+evbp_print_done_cb(EvPrintOperation *print, GtkPrintOperationResult result,
+ gpointer data)
+{
+ EvbpViewer *viewer = data;
+
+ /* FIXME: handle storing print settings */
+ if (result == GTK_PRINT_OPERATION_RESULT_ERROR) {
+ GtkWidget *dialog;
+ GError *error = NULL;
+
+ ev_print_operation_get_error(print, &error);
+ dialog = gtk_message_dialog_new(GTK_WINDOW(viewer),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "Failed to print document");
+ gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
+ error->message);
+ g_error_free(error);
+ g_signal_connect(dialog, "response", G_CALLBACK(gtk_widget_destroy),
+ NULL);
+ gtk_widget_show(dialog);
+ }
+}
+
+static void
+evbp_viewer_print(GtkAction *action, EvbpViewer *viewer)
+{
+ EvPrintOperation *print;
+ const gchar *title;
+ gint current_page;
+ GtkWindow *parent;
+
+ print = ev_print_operation_new(viewer->document);
+ if (!print) {
+ g_warning("Printing is not supported for this document\n");
+ return;
+ }
+ g_signal_connect(print, "done", G_CALLBACK(evbp_print_done_cb), viewer);
+
+ /* setup the print job with a reasonable title if possible */
+ title = ev_document_get_title(viewer->document);
+ if (title)
+ ev_print_operation_set_job_name(print, title);
+ current_page = ev_document_model_get_page(viewer->model);
+ ev_print_operation_set_current_page(print, current_page);
+
+ parent = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(viewer)));
+ ev_print_operation_run(print, GTK_WINDOW(parent));
+}
+
+static void
evbp_viewer_previous_page(GtkAction *action, EvbpViewer *viewer)
{
ev_view_previous_page(EV_VIEW(viewer->view));
@@ -329,6 +381,10 @@ static const GtkActionEntry action_entries[] = {
"_Open in Evince", NULL,
"Open the document in the Evince viewer",
G_CALLBACK(evbp_viewer_open_evince) },
+ { "Print", GTK_STOCK_PRINT,
+ "_Print", "<control>p",
+ "Print the document",
+ G_CALLBACK(evbp_viewer_print) },
{ "GoPreviousPage", GTK_STOCK_GO_UP,
"_Previous Page", "<control>Page_Up",
"Go to the previous page",
@@ -364,6 +420,7 @@ static const gchar ui_string[] =
" <toolbar name=\"ViewerToolbar\">\n"
" <toolitem name=\"SaveCopy\" action =\"SaveCopy\"/>\n"
" <toolitem name=\"OpenInEvince\" action =\"OpenInEvince\"/>\n"
+ " <toolitem name=\"Print\" action=\"Print\"/>\n"
" <separator/>\n"
" <toolitem name=\"GoPreviousPage\" action=\"GoPreviousPage\"/>\n"
" <toolitem name=\"GoNextPage\" action=\"GoNextPage\"/>\n"