printers: Make call of DevicesGet cancellable
Pass a GCancellable object to g_dbus_proxy_call() for DevicesGet method. This assures that g-c-c won't crash when user cancels addition of new printer before the call is finished (rhbz#691931).
This commit is contained in:
parent
eb623389fc
commit
6e479859ed
1 changed files with 140 additions and 119 deletions
|
@ -112,6 +112,8 @@ struct _PpNewPrinterDialog {
|
|||
|
||||
UserResponseCallback user_callback;
|
||||
gpointer user_data;
|
||||
|
||||
GCancellable *cancellable;
|
||||
};
|
||||
|
||||
static void
|
||||
|
@ -202,7 +204,7 @@ devices_get_cb (GObject *source_object,
|
|||
GAsyncResult *res,
|
||||
gpointer user_data)
|
||||
{
|
||||
PpNewPrinterDialog *pp = (PpNewPrinterDialog *) user_data;
|
||||
PpNewPrinterDialog *pp = user_data;
|
||||
GHashTable *devices = NULL;
|
||||
GtkWidget *widget = NULL;
|
||||
GVariant *dg_output = NULL;
|
||||
|
@ -214,6 +216,8 @@ devices_get_cb (GObject *source_object,
|
|||
res,
|
||||
&error);
|
||||
|
||||
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
||||
{
|
||||
if (dg_output && g_variant_n_children (dg_output) == 2)
|
||||
{
|
||||
GVariant *devices_variant = NULL;
|
||||
|
@ -343,7 +347,14 @@ devices_get_cb (GObject *source_object,
|
|||
gtk_spinner_stop (GTK_SPINNER (widget));
|
||||
gtk_widget_set_sensitive (widget, FALSE);
|
||||
|
||||
if (pp->cancellable != NULL)
|
||||
{
|
||||
g_object_unref (pp->cancellable);
|
||||
pp->cancellable = NULL;
|
||||
}
|
||||
|
||||
g_clear_error (&error);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -385,12 +396,14 @@ devices_get (PpNewPrinterDialog *pp)
|
|||
gtk_spinner_start (GTK_SPINNER (widget));
|
||||
gtk_widget_set_sensitive (widget, TRUE);
|
||||
|
||||
pp->cancellable = g_cancellable_new ();
|
||||
|
||||
g_dbus_proxy_call (proxy,
|
||||
"DevicesGet",
|
||||
dg_input,
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
60000,
|
||||
NULL,
|
||||
pp->cancellable,
|
||||
devices_get_cb,
|
||||
pp);
|
||||
|
||||
|
@ -1101,6 +1114,8 @@ pp_new_printer_dialog_new (GtkWindow *parent,
|
|||
pp->user_callback = user_callback;
|
||||
pp->user_data = user_data;
|
||||
|
||||
pp->cancellable = NULL;
|
||||
|
||||
/* connect signals */
|
||||
g_signal_connect (pp->dialog, "delete-event", G_CALLBACK (gtk_widget_hide_on_delete), NULL);
|
||||
|
||||
|
@ -1145,6 +1160,12 @@ pp_new_printer_dialog_free (PpNewPrinterDialog *pp)
|
|||
g_object_unref (pp->builder);
|
||||
pp->builder = NULL;
|
||||
|
||||
if (pp->cancellable)
|
||||
{
|
||||
g_cancellable_cancel (pp->cancellable);
|
||||
g_object_unref (pp->cancellable);
|
||||
}
|
||||
|
||||
g_free (pp);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue