[gnome-control-center] printers: Remove printers asynchronously
- From: Felipe Borges <felipeborges src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] printers: Remove printers asynchronously
- Date: Fri, 26 May 2017 12:29:58 +0000 (UTC)
commit 5aca01cd65d18a401a07aea382c051aa0080ea16
Author: Felipe Borges <felipeborges gnome org>
Date: Wed May 10 13:06:58 2017 +0200
printers: Remove printers asynchronously
Introduce pp_printer_delete_async ()
https://bugzilla.gnome.org/show_bug.cgi?id=693187
panels/printers/pp-printer-entry.c | 17 +++++-
panels/printers/pp-printer.c | 108 ++++++++++++++++++++++++++++++++++++
panels/printers/pp-printer.h | 9 +++
3 files changed, 133 insertions(+), 1 deletions(-)
---
diff --git a/panels/printers/pp-printer-entry.c b/panels/printers/pp-printer-entry.c
index 88384c4..a5851a7 100644
--- a/panels/printers/pp-printer-entry.c
+++ b/panels/printers/pp-printer-entry.c
@@ -530,10 +530,25 @@ clean_heads (GtkButton *button,
}
static void
+remove_printer_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ pp_printer_delete_finish (PP_PRINTER (source_object), res, NULL);
+ g_object_unref (source_object);
+}
+
+static void
remove_printer (GtkButton *button,
PpPrinterEntry *self)
{
- printer_delete (self->printer_name);
+ PpPrinter *printer;
+
+ printer = pp_printer_new (self->printer_name);
+ pp_printer_delete_async (printer,
+ NULL,
+ remove_printer_cb,
+ NULL);
}
static void
diff --git a/panels/printers/pp-printer.c b/panels/printers/pp-printer.c
index a7def7c..63a76a5 100644
--- a/panels/printers/pp-printer.c
+++ b/panels/printers/pp-printer.c
@@ -368,3 +368,111 @@ pp_printer_get_jobs_finish (PpPrinter *printer,
return g_task_propagate_pointer (G_TASK (res), error);
}
+
+static void
+pp_printer_delete_dbus_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GVariant *output;
+ gboolean result = FALSE;
+ GError *error = NULL;
+ GTask *task = user_data;
+ gchar *printer_name;
+
+ output = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object),
+ res,
+ &error);
+ g_object_unref (source_object);
+
+ if (output != NULL)
+ {
+ const gchar *ret_error;
+
+ g_object_get (g_task_get_source_object (task), "printer-name", &printer_name, NULL);
+
+ g_variant_get (output, "(&s)", &ret_error);
+ if (ret_error[0] != '\0')
+ g_warning ("cups-pk-helper: removing of printer %s failed: %s", printer_name, ret_error);
+ else
+ result = TRUE;
+
+ g_task_return_boolean (task, result);
+
+ g_free (printer_name);
+ g_variant_unref (output);
+ }
+ else
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+
+ g_task_return_boolean (task, FALSE);
+ }
+}
+
+static void
+pp_printer_delete_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GDBusConnection *bus;
+ GError *error = NULL;
+ GTask *task = user_data;
+ gchar *printer_name;
+
+ bus = g_bus_get_finish (res, &error);
+ if (bus != NULL)
+ {
+ g_object_get (g_task_get_source_object (task),
+ "printer-name", &printer_name,
+ NULL);
+
+ g_dbus_connection_call (bus,
+ MECHANISM_BUS,
+ "/",
+ MECHANISM_BUS,
+ "PrinterDelete",
+ g_variant_new ("(s)", printer_name),
+ G_VARIANT_TYPE ("(s)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ g_task_get_cancellable (task),
+ pp_printer_delete_dbus_cb,
+ task);
+
+ g_free (printer_name);
+ }
+ else
+ {
+ g_warning ("Failed to get system bus: %s", error->message);
+ g_error_free (error);
+ g_task_return_boolean (task, FALSE);
+ }
+}
+
+void
+pp_printer_delete_async (PpPrinter *printer,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GTask *task;
+
+ task = g_task_new (G_OBJECT (printer), cancellable, callback, user_data);
+
+ g_bus_get (G_BUS_TYPE_SYSTEM,
+ cancellable,
+ pp_printer_delete_cb,
+ task);
+}
+
+gboolean
+pp_printer_delete_finish (PpPrinter *printer,
+ GAsyncResult *res,
+ GError **error)
+{
+ g_return_val_if_fail (g_task_is_valid (res, printer), FALSE);
+
+ return g_task_propagate_boolean (G_TASK (res), error);
+}
diff --git a/panels/printers/pp-printer.h b/panels/printers/pp-printer.h
index e3e7729..230f941 100644
--- a/panels/printers/pp-printer.h
+++ b/panels/printers/pp-printer.h
@@ -46,6 +46,15 @@ gboolean pp_printer_rename_finish (PpPrinter *printer,
GAsyncResult *res,
GError **error);
+void pp_printer_delete_async (PpPrinter *printer,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+gboolean pp_printer_delete_finish (PpPrinter *printer,
+ GAsyncResult *res,
+ GError **error);
+
void pp_printer_get_jobs_async (PpPrinter *printer,
gboolean myjobs,
gint which_jobs,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]