Commit 9bea3859 authored by Alexander Larsson's avatar Alexander Larsson Committed by Alexander Larsson

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
parent 36f7ed30
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
2006-06-07 Bastien Nocera <hadess@hadess.net>
* configure.in: Update the ATK requirements (#344148)
......
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
2006-06-07 Bastien Nocera <hadess@hadess.net>
* configure.in: Update the ATK requirements (#344148)
......
......@@ -156,7 +156,7 @@ do_printing (GtkWidget *do_widget)
g_signal_connect (G_OBJECT (operation), "end-print",
G_CALLBACK (end_print), data);
gtk_print_operation_run (operation, GTK_WINDOW (do_widget), &error);
gtk_print_operation_run (operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW (do_widget), &error);
g_object_unref (operation);
......
......@@ -2697,14 +2697,12 @@ gtk_print_operation_set_n_pages
gtk_print_operation_set_current_page
gtk_print_operation_set_use_full_page
gtk_print_operation_set_unit
gtk_print_operation_set_show_dialog
gtk_print_operation_set_pdf_target
gtk_print_operation_set_track_print_status
gtk_print_operation_set_show_progress
gtk_print_operation_set_show_preview
gtk_print_operation_set_custom_tab_label
gtk_print_operation_get_error
gtk_print_operation_run
gtk_print_operation_run_async
gtk_print_operation_get_status
gtk_print_operation_get_status_string
gtk_print_operation_is_finished
......
......@@ -27,7 +27,9 @@ G_BEGIN_DECLS
struct _GtkPrintOperationPrivate
{
GtkPrintOperationAction action;
GtkPrintStatus status;
GError *error;
gchar *status_string;
GtkPageSetup *default_page_setup;
GtkPrintSettings *print_settings;
......@@ -37,11 +39,10 @@ struct _GtkPrintOperationPrivate
GtkUnit unit;
gchar *pdf_target;
guint use_full_page : 1;
guint show_dialog : 1;
guint show_preview : 1;
guint track_print_status : 1;
guint show_progress : 1;
guint cancelled : 1;
guint allow_async : 1;
guint is_sync : 1;
guint print_pages_idle_id;
......@@ -84,13 +85,15 @@ struct _GtkPrintOperationPrivate
typedef void (* GtkPrintOperationPrintFunc) (GtkPrintOperation *op,
GtkWindow *parent,
gboolean is_preview);
gboolean do_print,
GtkPrintOperationResult result);
GtkPrintOperationResult _gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *operation,
gboolean show_dialog,
GtkWindow *parent,
gboolean *do_print,
GError **error);
gboolean *do_print);
void _gtk_print_operation_platform_backend_run_dialog_async (GtkPrintOperation *op,
gboolean show_dialog,
GtkWindow *parent,
GtkPrintOperationPrintFunc print_cb);
void _gtk_print_operation_platform_backend_launch_preview (GtkPrintOperation *op,
......
......@@ -350,7 +350,6 @@ typedef struct
{
GtkPrintOperation *op;
gboolean do_print;
GError **error;
GtkPrintOperationResult result;
GtkPrintOperationPrintFunc print_cb;
GDestroyNotify destroy;
......@@ -391,7 +390,7 @@ finish_print (PrintResponseData *rdata,
GtkPrintOperationUnix *op_unix;
cairo_t *cr;
op_unix = g_new0 (GtkPrintOperationUnix, 1);
op_unix = g_new0 (GtkPrintOperationUnix, 1);
priv->platform_data = op_unix;
priv->free_platform_data = (GDestroyNotify) op_unix_free;
op_unix->parent = rdata->parent;
......@@ -404,9 +403,10 @@ finish_print (PrintResponseData *rdata,
op_unix->job = job;
gtk_print_job_set_track_print_status (job, priv->track_print_status);
op_unix->surface = gtk_print_job_get_surface (job, rdata->error);
op_unix->surface = gtk_print_job_get_surface (job, &priv->error);
if (op_unix->surface == NULL)
{
rdata->result = GTK_PRINT_OPERATION_RESULT_ERROR;
rdata->do_print = FALSE;
goto out;
}
......@@ -435,12 +435,7 @@ finish_print (PrintResponseData *rdata,
}
out:
if (rdata->print_cb)
{
if (rdata->do_print)
rdata->print_cb (op, rdata->parent, is_preview);
else
_gtk_print_operation_set_status (op, GTK_PRINT_STATUS_FINISHED_ABORTED, NULL);
}
rdata->print_cb (op, rdata->do_print, rdata->parent, rdata->result);
if (rdata->destroy)
rdata->destroy (rdata);
......@@ -504,10 +499,7 @@ found_printer (GtkPrinter *printer,
if (printer != NULL)
{
if (priv->show_preview)
rdata->result = GTK_PRINT_OPERATION_RESULT_PREVIEW;
else
rdata->result = GTK_PRINT_OPERATION_RESULT_APPLY;
rdata->result = GTK_PRINT_OPERATION_RESULT_APPLY;
rdata->do_print = TRUE;
......@@ -536,6 +528,7 @@ found_printer (GtkPrinter *printer,
void
_gtk_print_operation_platform_backend_run_dialog_async (GtkPrintOperation *op,
gboolean show_dialog,
GtkWindow *parent,
GtkPrintOperationPrintFunc print_cb)
{
......@@ -547,13 +540,12 @@ _gtk_print_operation_platform_backend_run_dialog_async (GtkPrintOperation
rdata->op = g_object_ref (op);
rdata->do_print = FALSE;
rdata->result = GTK_PRINT_OPERATION_RESULT_CANCEL;
rdata->error = NULL;
rdata->print_cb = print_cb;
rdata->parent = parent;
rdata->loop = NULL;
rdata->destroy = print_response_data_free;
if (op->priv->show_dialog)
if (show_dialog)
{
pd = get_print_dialog (op, parent);
gtk_window_set_modal (GTK_WINDOW (pd), TRUE);
......@@ -608,9 +600,9 @@ _gtk_print_operation_platform_backend_resize_preview_surface (GtkPrintOperation
GtkPrintOperationResult
_gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *op,
gboolean show_dialog,
GtkWindow *parent,
gboolean *do_print,
GError **error)
gboolean *do_print)
{
GtkWidget *pd;
PrintResponseData rdata;
......@@ -620,13 +612,12 @@ _gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *op,
rdata.op = op;
rdata.do_print = FALSE;
rdata.result = GTK_PRINT_OPERATION_RESULT_CANCEL;
rdata.error = error;
rdata.print_cb = NULL;
rdata.destroy = NULL;
rdata.parent = parent;
rdata.loop = NULL;
if (op->priv->show_dialog)
if (show_dialog)
{
pd = get_print_dialog (op, parent);
......
This diff is collapsed.
......@@ -56,6 +56,22 @@ typedef enum {
GTK_PRINT_STATUS_FINISHED_ABORTED
} GtkPrintStatus;
typedef enum {
GTK_PRINT_OPERATION_RESULT_ERROR,
GTK_PRINT_OPERATION_RESULT_APPLY,
GTK_PRINT_OPERATION_RESULT_CANCEL,
GTK_PRINT_OPERATION_RESULT_PREVIEW,
GTK_PRINT_OPERATION_RESULT_IN_PROGRESS
} GtkPrintOperationResult;
typedef enum {
GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
GTK_PRINT_OPERATION_ACTION_PRINT,
GTK_PRINT_OPERATION_ACTION_PREVIEW,
GTK_PRINT_OPERATION_ACTION_EXPORT,
} GtkPrintOperationAction;
struct _GtkPrintOperation
{
GObject parent_instance;
......@@ -67,6 +83,8 @@ struct _GtkPrintOperationClass
{
GObjectClass parent_class;
void (*done) (GtkPrintOperation *operation,
GtkPrintOperationResult result);
void (*begin_print) (GtkPrintOperation *operation,
GtkPrintContext *context);
gboolean (*paginate) (GtkPrintOperation *operation,
......@@ -102,13 +120,6 @@ struct _GtkPrintOperationClass
void (*_gtk_reserved7) (void);
};
typedef enum {
GTK_PRINT_OPERATION_RESULT_ERROR,
GTK_PRINT_OPERATION_RESULT_APPLY,
GTK_PRINT_OPERATION_RESULT_CANCEL,
GTK_PRINT_OPERATION_RESULT_PREVIEW
} GtkPrintOperationResult;
#define GTK_PRINT_ERROR gtk_print_error_quark ()
typedef enum
......@@ -138,23 +149,21 @@ void gtk_print_operation_set_use_full_page (GtkPrintOper
gboolean full_page);
void gtk_print_operation_set_unit (GtkPrintOperation *op,
GtkUnit unit);
void gtk_print_operation_set_show_dialog (GtkPrintOperation *op,
gboolean show_dialog);
void gtk_print_operation_set_show_preview (GtkPrintOperation *op,
gboolean show_preview);
void gtk_print_operation_set_pdf_target (GtkPrintOperation *op,
const gchar *filename);
void gtk_print_operation_set_track_print_status (GtkPrintOperation *op,
gboolean track_status);
void gtk_print_operation_set_show_progress (GtkPrintOperation *op,
gboolean show_progress);
void gtk_print_operation_set_allow_async (GtkPrintOperation *op,
gboolean allow_async);
void gtk_print_operation_set_custom_tab_label (GtkPrintOperation *op,
const gchar *label);
GtkPrintOperationResult gtk_print_operation_run (GtkPrintOperation *op,
GtkPrintOperationAction action,
GtkWindow *parent,
GError **error);
void gtk_print_operation_run_preview (GtkPrintOperation *op,
GtkWindow *parent);
GError * gtk_print_operation_get_error (GtkPrintOperation *op);
GtkPrintStatus gtk_print_operation_get_status (GtkPrintOperation *op);
G_CONST_RETURN gchar * gtk_print_operation_get_status_string (GtkPrintOperation *op);
gboolean gtk_print_operation_is_finished (GtkPrintOperation *op);
......
......@@ -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
......
......@@ -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;
}
......@@ -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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment