diff options
author | Alexander Larsson <alexl@redhat.com> | 2006-06-07 15:09:03 +0000 |
---|---|---|
committer | Alexander Larsson <alexl@src.gnome.org> | 2006-06-07 15:09:03 +0000 |
commit | 9bea38595fcd9b4e9f55de3dcd5199dab930e713 (patch) | |
tree | 1c5d2d561965a275c566abc8f1a083cc5cf46976 /tests | |
parent | 36f7ed300ad786fc6ba88e9c7a7d771c689af06e (diff) | |
download | gdk-pixbuf-9bea38595fcd9b4e9f55de3dcd5199dab930e713.tar.gz |
Clean up APIs: Make async a setting instead of separate calls. Combine
2006-06-07 Alexander Larsson <alexl@redhat.com>
* gtk/gtk.symbols:
* gtk/gtkprintoperation-private.h:
* gtk/gtkprintoperation-unix.c:
* gtk/gtkprintoperation.[ch]:
Clean up APIs:
Make async a setting instead of separate calls.
Combine settings like show_dialog, show_preview and pdf_target into
an action enum that you pass to gtk_print_dialog_run().
* tests/print-editor.c:
* tests/testnouiprint.c:
* tests/testprint.c:
* demos/gtk-demo/printing.c:
Update to new APIs
Diffstat (limited to 'tests')
-rw-r--r-- | tests/print-editor.c | 96 | ||||
-rw-r--r-- | tests/testnouiprint.c | 3 | ||||
-rw-r--r-- | tests/testprint.c | 4 |
3 files changed, 54 insertions, 49 deletions
diff --git a/tests/print-editor.c b/tests/print-editor.c index b18cbe831..e8d6a0e5f 100644 --- a/tests/print-editor.c +++ b/tests/print-editor.c @@ -603,18 +603,57 @@ do_preview (GtkPrintOperation *op, return TRUE; } -/* FIXME had to move this to the heap, since previewing - * returns too early from the sync api - */ -PrintData *print_data; +static void +print_done (GtkPrintOperation *op, + GtkPrintOperationResult res, + PrintData *print_data) +{ + GError *error; + + if (res == GTK_PRINT_OPERATION_RESULT_ERROR) + { + + GtkWidget *error_dialog; + + error = gtk_print_operation_get_error (op); + + error_dialog = gtk_message_dialog_new (GTK_WINDOW (main_window), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + "Error printing file:\n%s", + error ? error->message : "no details"); + g_signal_connect (error_dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL); + gtk_widget_show (error_dialog); + } + else if (res == GTK_PRINT_OPERATION_RESULT_APPLY) + { + if (settings != NULL) + g_object_unref (settings); + settings = g_object_ref (gtk_print_operation_get_print_settings (op)); + } + + g_free (print_data->text); + g_free (print_data->font); + g_free (print_data); + + if (!gtk_print_operation_is_finished (op)) + { + g_object_ref (op); + active_prints = g_list_append (active_prints, op); + update_statusbar (); + + /* This ref is unref:ed when we get the final state change */ + g_signal_connect (op, "status_changed", + G_CALLBACK (status_changed_cb), NULL); + } +} static void do_print (GtkAction *action) { - GtkWidget *error_dialog; GtkPrintOperation *print; - GtkPrintOperationResult res; - GError *error; + PrintData *print_data; print_data = g_new0 (PrintData, 1); @@ -637,49 +676,16 @@ do_print (GtkAction *action) g_signal_connect (print, "custom_widget_apply", G_CALLBACK (custom_widget_apply), print_data); g_signal_connect (print, "preview", G_CALLBACK (do_preview), print_data); - error = NULL; + g_signal_connect (print, "done", G_CALLBACK (print_done), print_data); -#if 1 - res = gtk_print_operation_run (print, GTK_WINDOW (main_window), &error); + gtk_print_operation_set_pdf_target (print, "test.pdf"); - if (res == GTK_PRINT_OPERATION_RESULT_ERROR) - { - error_dialog = gtk_message_dialog_new (GTK_WINDOW (main_window), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - "Error printing file:\n%s", - error ? error->message : "no details"); - g_signal_connect (error_dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL); - gtk_widget_show (error_dialog); - g_error_free (error); - } - else if (res == GTK_PRINT_OPERATION_RESULT_APPLY) - { - if (settings != NULL) - g_object_unref (settings); - settings = g_object_ref (gtk_print_operation_get_print_settings (print)); - } - - if (!gtk_print_operation_is_finished (print)) - { - g_object_ref (print); - active_prints = g_list_append (active_prints, print); - update_statusbar (); - - /* This ref is unref:ed when we get the final state change */ - g_signal_connect (print, "status_changed", - G_CALLBACK (status_changed_cb), NULL); - } -#else - gtk_print_operation_run_async (print, GTK_WINDOW (main_window)); +#if 0 + gtk_print_operation_set_allow_async (print, TRUE); #endif + gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PREVIEW, GTK_WINDOW (main_window), NULL); g_object_unref (print); -#if 0 - g_free (print_data.text); - g_free (print_data.font); -#endif } static void diff --git a/tests/testnouiprint.c b/tests/testnouiprint.c index cf73fd03e..585c5ddbe 100644 --- a/tests/testnouiprint.c +++ b/tests/testnouiprint.c @@ -99,9 +99,8 @@ main (int argc, char **argv) gtk_print_operation_set_print_settings (print, settings); gtk_print_operation_set_n_pages (print, 1); gtk_print_operation_set_unit (print, GTK_UNIT_MM); - gtk_print_operation_set_show_dialog (print, FALSE); g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), NULL); - res = gtk_print_operation_run (print, NULL, NULL); + res = gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT, NULL, NULL); return 0; } diff --git a/tests/testprint.c b/tests/testprint.c index 5ff3489e7..2394d12b1 100644 --- a/tests/testprint.c +++ b/tests/testprint.c @@ -111,13 +111,13 @@ main (int argc, char **argv) gtk_print_operation_set_pdf_target (print, "test.pdf"); g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), NULL); g_signal_connect (print, "request_page_setup", G_CALLBACK (request_page_setup), NULL); - res = gtk_print_operation_run (print, NULL, NULL); + res = gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_EXPORT, NULL, NULL); /* Test subclassing of GtkPrintOperation */ print_file = test_print_file_operation_new ("testprint.c"); test_print_file_operation_set_font_size (print_file, 12.0); gtk_print_operation_set_pdf_target (GTK_PRINT_OPERATION (print_file), "test2.pdf"); - res = gtk_print_operation_run (GTK_PRINT_OPERATION (print_file), NULL, NULL); + res = gtk_print_operation_run (GTK_PRINT_OPERATION (print_file), GTK_PRINT_OPERATION_ACTION_EXPORT, NULL, NULL); return 0; } |