[gnome-control-center] Printers: Use g_error_free() instead of g_clear_error ()
- From: Marek KaÅÃk <mkasik src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] Printers: Use g_error_free() instead of g_clear_error ()
- Date: Mon, 23 Jan 2012 15:41:00 +0000 (UTC)
commit 5e4e429cd04f5b46619a4363d620ad649b6fc740
Author: Marek Kasik <mkasik redhat com>
Date: Mon Jan 23 16:40:36 2012 +0100
Printers: Use g_error_free() instead of g_clear_error ()
Replace g_clear_error() with more appropriate g_error_free()
where suitable. (#658581)
panels/printers/cc-printers-panel.c | 63 ++--
panels/printers/pp-new-printer-dialog.c | 841 +++++++++++++++++--------------
panels/printers/pp-utils.c | 830 +++++++++++++++---------------
3 files changed, 907 insertions(+), 827 deletions(-)
---
diff --git a/panels/printers/cc-printers-panel.c b/panels/printers/cc-printers-panel.c
index cdfda89..c5a7967 100644
--- a/panels/printers/cc-printers-panel.c
+++ b/panels/printers/cc-printers-panel.c
@@ -377,7 +377,6 @@ attach_to_cups_notifier (gpointer data)
priv->subscription_renewal_id =
g_timeout_add_seconds (RENEW_INTERVAL, renew_subscription, self);
- error = NULL;
priv->cups_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
0,
NULL,
@@ -387,9 +386,10 @@ attach_to_cups_notifier (gpointer data)
NULL,
&error);
- if (error)
+ if (!priv->cups_proxy)
{
g_warning ("%s", error->message);
+ g_error_free (error);
return;
}
@@ -1550,6 +1550,7 @@ job_process_cb (GtkButton *button,
CcPrintersPanel *self = (CcPrintersPanel*) user_data;
DBusGProxy *proxy;
GtkWidget *widget;
+ gboolean result = TRUE;
GError *error = NULL;
char *ret_error = NULL;
int id = -1;
@@ -1574,45 +1575,46 @@ job_process_cb (GtkButton *button,
if ((GtkButton*) gtk_builder_get_object (priv->builder,
"job-cancel-button") ==
button)
- dbus_g_proxy_call (proxy, "JobCancelPurge", &error,
- G_TYPE_INT, id,
- G_TYPE_BOOLEAN, FALSE,
- G_TYPE_INVALID,
- G_TYPE_STRING, &ret_error,
- G_TYPE_INVALID);
+ result = dbus_g_proxy_call (proxy, "JobCancelPurge", &error,
+ G_TYPE_INT, id,
+ G_TYPE_BOOLEAN, FALSE,
+ G_TYPE_INVALID,
+ G_TYPE_STRING, &ret_error,
+ G_TYPE_INVALID);
else if ((GtkButton*) gtk_builder_get_object (priv->builder,
"job-hold-button") ==
button)
- dbus_g_proxy_call (proxy, "JobSetHoldUntil", &error,
- G_TYPE_INT, id,
- G_TYPE_STRING, "indefinite",
- G_TYPE_INVALID,
- G_TYPE_STRING, &ret_error,
- G_TYPE_INVALID);
+ result = dbus_g_proxy_call (proxy, "JobSetHoldUntil", &error,
+ G_TYPE_INT, id,
+ G_TYPE_STRING, "indefinite",
+ G_TYPE_INVALID,
+ G_TYPE_STRING, &ret_error,
+ G_TYPE_INVALID);
else if ((GtkButton*) gtk_builder_get_object (priv->builder,
"job-release-button") ==
button)
- dbus_g_proxy_call (proxy, "JobSetHoldUntil", &error,
- G_TYPE_INT, id,
- G_TYPE_STRING, "no-hold",
- G_TYPE_INVALID,
- G_TYPE_STRING, &ret_error,
- G_TYPE_INVALID);
+ result = dbus_g_proxy_call (proxy, "JobSetHoldUntil", &error,
+ G_TYPE_INT, id,
+ G_TYPE_STRING, "no-hold",
+ G_TYPE_INVALID,
+ G_TYPE_STRING, &ret_error,
+ G_TYPE_INVALID);
g_object_unref (proxy);
- if (error || (ret_error && ret_error[0] != '\0'))
+ if (!result || (ret_error && ret_error[0] != '\0'))
{
- if (error)
- g_warning ("%s", error->message);
+ if (!result)
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
if (ret_error && ret_error[0] != '\0')
g_warning ("%s", ret_error);
}
else
actualize_jobs_list (self);
-
- g_clear_error (&error);
}
widget = (GtkWidget*)
@@ -2173,7 +2175,7 @@ test_page_cb (GtkButton *button,
gchar *printer_uri = NULL;
gchar *filename = NULL;
gchar *resource = NULL;
- ipp_t *response;
+ ipp_t *response = NULL;
ipp_t *request;
if ((datadir = getenv ("CUPS_DATADIR")) != NULL)
@@ -2455,6 +2457,7 @@ cc_printers_panel_init (CcPrintersPanel *self)
http_t *http;
gchar *objects[] = { "main-vbox", NULL };
GtkStyleContext *context;
+ guint builder_result;
priv = self->priv = PRINTERS_PANEL_PRIVATE (self);
@@ -2486,11 +2489,11 @@ cc_printers_panel_init (CcPrintersPanel *self)
priv->permission = NULL;
priv->lockdown_settings = NULL;
- gtk_builder_add_objects_from_file (priv->builder,
- DATADIR"/printers.ui",
- objects, &error);
+ builder_result = gtk_builder_add_objects_from_file (priv->builder,
+ DATADIR"/printers.ui",
+ objects, &error);
- if (error)
+ if (builder_result == 0)
{
/* Translators: The XML file containing user interface can not be loaded */
g_warning (_("Could not load ui: %s"), error->message);
diff --git a/panels/printers/pp-new-printer-dialog.c b/panels/printers/pp-new-printer-dialog.c
index bbe1f91..ef2c539 100644
--- a/panels/printers/pp-new-printer-dialog.c
+++ b/panels/printers/pp-new-printer-dialog.c
@@ -338,9 +338,16 @@ devices_get_cb (GObject *source_object,
res,
&error);
- if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ /* Do nothing if cancelled */
+ if (!dg_output && g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
{
- if (dg_output && g_variant_n_children (dg_output) == 2)
+ g_error_free (error);
+ return;
+ }
+
+ if (dg_output)
+ {
+ if (g_variant_n_children (dg_output) == 2)
{
GVariant *devices_variant = NULL;
@@ -372,237 +379,235 @@ devices_get_cb (GObject *source_object,
}
g_variant_unref (devices_variant);
}
- g_variant_unref (dg_output);
}
- g_object_unref (source_object);
+ g_variant_unref (dg_output);
+ }
+ else
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
+
+ g_object_unref (source_object);
+
+ if (ret_error && ret_error[0] != '\0')
+ g_warning ("%s", ret_error);
- if (error || (ret_error && ret_error[0] != '\0'))
+ free_devices (pp);
+ if (devices)
+ {
+ GList *keys;
+ GList *iter;
+ gchar *cut;
+ gint max_index = -1;
+ gint index;
+
+ keys = g_hash_table_get_keys (devices);
+ for (iter = keys; iter; iter = iter->next)
{
- if (error)
- g_warning ("%s", error->message);
+ index = -1;
- if (ret_error && ret_error[0] != '\0')
- g_warning ("%s", ret_error);
+ cut = g_strrstr ((gchar *)iter->data, ":");
+ if (cut)
+ index = atoi (cut + 1);
+
+ if (index > max_index)
+ max_index = index;
}
- free_devices (pp);
- if (devices)
+ if (max_index >= 0)
{
- GList *keys;
- GList *iter;
- gchar *cut;
- gint max_index = -1;
- gint index;
-
- keys = g_hash_table_get_keys (devices);
- for (iter = keys; iter; iter = iter->next)
- {
- index = -1;
+ pp->num_devices = max_index + 1;
+ pp->devices = g_new0 (CupsDevice, pp->num_devices);
- cut = g_strrstr ((gchar *)iter->data, ":");
- if (cut)
- index = atoi (cut + 1);
-
- if (index > max_index)
- max_index = index;
- }
+ g_hash_table_foreach (devices, store_device_parameter, pp);
- if (max_index >= 0)
+ /* Assign names to devices */
+ for (i = 0; i < pp->num_devices; i++)
{
- pp->num_devices = max_index + 1;
- pp->devices = g_new0 (CupsDevice, pp->num_devices);
+ gchar *name = NULL;
- g_hash_table_foreach (devices, store_device_parameter, pp);
-
- /* Assign names to devices */
- for (i = 0; i < pp->num_devices; i++)
+ if (pp->devices[i].device_id)
{
- gchar *name = NULL;
+ name = get_tag_value (pp->devices[i].device_id, "mdl");
+ if (!name)
+ name = get_tag_value (pp->devices[i].device_id, "model");
- if (pp->devices[i].device_id)
- {
- name = get_tag_value (pp->devices[i].device_id, "mdl");
- if (!name)
- name = get_tag_value (pp->devices[i].device_id, "model");
+ if (name)
+ name = g_strcanon (name, ALLOWED_CHARACTERS, '-');
+ }
- if (name)
- name = g_strcanon (name, ALLOWED_CHARACTERS, '-');
- }
+ if (!name &&
+ pp->devices[i].device_info)
+ {
+ name = g_strdup (pp->devices[i].device_info);
+ if (name)
+ name = g_strcanon (name, ALLOWED_CHARACTERS, '-');
+ }
- if (!name &&
- pp->devices[i].device_info)
+ name_index = 2;
+ already_present = FALSE;
+ num_dests = cupsGetDests (&dests);
+ do
+ {
+ if (already_present)
{
- name = g_strdup (pp->devices[i].device_info);
- if (name)
- name = g_strcanon (name, ALLOWED_CHARACTERS, '-');
+ new_name = g_strdup_printf ("%s-%d", name, name_index);
+ name_index++;
}
+ else
+ new_name = g_strdup (name);
- name_index = 2;
already_present = FALSE;
- num_dests = cupsGetDests (&dests);
- do
+ for (j = 0; j < num_dests; j++)
+ if (g_strcmp0 (dests[j].name, new_name) == 0)
+ already_present = TRUE;
+
+ if (already_present)
+ g_free (new_name);
+ else
{
- if (already_present)
- {
- new_name = g_strdup_printf ("%s-%d", name, name_index);
- name_index++;
- }
- else
- new_name = g_strdup (name);
+ g_free (name);
+ name = new_name;
+ }
+ } while (already_present);
+ cupsFreeDests (num_dests, dests);
- already_present = FALSE;
- for (j = 0; j < num_dests; j++)
- if (g_strcmp0 (dests[j].name, new_name) == 0)
- already_present = TRUE;
+ pp->devices[i].display_name = name;
+ }
- if (already_present)
- g_free (new_name);
- else
- {
- g_free (name);
- name = new_name;
- }
- } while (already_present);
- cupsFreeDests (num_dests, dests);
+ /* Set show bool
+ * Don't show duplicates.
+ * Show devices with device-id.
+ * Other preferences should apply here.
+ */
+ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ SCP_BUS,
+ SCP_PATH,
+ SCP_IFACE,
+ NULL,
+ &error);
- pp->devices[i].display_name = name;
- }
+ if (proxy)
+ {
+ GVariantBuilder device_list;
+ GVariantBuilder device_hash;
+ GVariant *input = NULL;
+ GVariant *output = NULL;
+ GVariant *array = NULL;
+ GVariant *subarray = NULL;
- /* Set show bool
- * Don't show duplicates.
- * Show devices with device-id.
- * Other preferences should apply here.
- */
- proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
- G_DBUS_PROXY_FLAGS_NONE,
- NULL,
- SCP_BUS,
- SCP_PATH,
- SCP_IFACE,
- NULL,
- &error);
+ g_variant_builder_init (&device_list, G_VARIANT_TYPE ("a{sv}"));
- if (proxy)
+ for (i = 0; i < pp->num_devices; i++)
{
- GVariantBuilder device_list;
- GVariantBuilder device_hash;
- GVariant *input = NULL;
- GVariant *output = NULL;
- GVariant *array = NULL;
- GVariant *subarray = NULL;
-
- g_variant_builder_init (&device_list, G_VARIANT_TYPE ("a{sv}"));
-
- for (i = 0; i < pp->num_devices; i++)
+ if (pp->devices[i].device_uri)
{
- if (pp->devices[i].device_uri)
- {
- g_variant_builder_init (&device_hash, G_VARIANT_TYPE ("a{ss}"));
-
- if (pp->devices[i].device_id)
- g_variant_builder_add (&device_hash,
- "{ss}",
- "device-id",
- pp->devices[i].device_id);
-
- if (pp->devices[i].device_make_and_model)
- g_variant_builder_add (&device_hash,
- "{ss}",
- "device-make-and-model",
- pp->devices[i].device_make_and_model);
-
- if (pp->devices[i].device_class)
- g_variant_builder_add (&device_hash,
- "{ss}",
- "device-class",
- pp->devices[i].device_class);
-
- g_variant_builder_add (&device_list,
- "{sv}",
- pp->devices[i].device_uri,
- g_variant_builder_end (&device_hash));
- }
+ g_variant_builder_init (&device_hash, G_VARIANT_TYPE ("a{ss}"));
+
+ if (pp->devices[i].device_id)
+ g_variant_builder_add (&device_hash,
+ "{ss}",
+ "device-id",
+ pp->devices[i].device_id);
+
+ if (pp->devices[i].device_make_and_model)
+ g_variant_builder_add (&device_hash,
+ "{ss}",
+ "device-make-and-model",
+ pp->devices[i].device_make_and_model);
+
+ if (pp->devices[i].device_class)
+ g_variant_builder_add (&device_hash,
+ "{ss}",
+ "device-class",
+ pp->devices[i].device_class);
+
+ g_variant_builder_add (&device_list,
+ "{sv}",
+ pp->devices[i].device_uri,
+ g_variant_builder_end (&device_hash));
}
+ }
- input = g_variant_new ("(v)", g_variant_builder_end (&device_list));
+ input = g_variant_new ("(v)", g_variant_builder_end (&device_list));
- output = g_dbus_proxy_call_sync (proxy,
- "GroupPhysicalDevices",
- input,
- G_DBUS_CALL_FLAGS_NONE,
- 60000,
- NULL,
- &error);
+ output = g_dbus_proxy_call_sync (proxy,
+ "GroupPhysicalDevices",
+ input,
+ G_DBUS_CALL_FLAGS_NONE,
+ 60000,
+ NULL,
+ &error);
- if (output && g_variant_n_children (output) == 1)
+ if (output && g_variant_n_children (output) == 1)
+ {
+ array = g_variant_get_child_value (output, 0);
+ if (array)
{
- array = g_variant_get_child_value (output, 0);
- if (array)
+ for (i = 0; i < g_variant_n_children (array); i++)
{
- for (i = 0; i < g_variant_n_children (array); i++)
+ subarray = g_variant_get_child_value (array, i);
+ if (subarray)
{
- subarray = g_variant_get_child_value (array, i);
- if (subarray)
- {
- device_uri = g_strdup (g_variant_get_string (
- g_variant_get_child_value (subarray, 0),
- NULL));
+ device_uri = g_strdup (g_variant_get_string (
+ g_variant_get_child_value (subarray, 0),
+ NULL));
- for (k = 0; k < pp->num_devices; k++)
- if (g_str_has_prefix (pp->devices[k].device_uri, device_uri))
- pp->devices[k].show = TRUE;
+ for (k = 0; k < pp->num_devices; k++)
+ if (g_str_has_prefix (pp->devices[k].device_uri, device_uri))
+ pp->devices[k].show = TRUE;
- g_free (device_uri);
- }
+ g_free (device_uri);
}
}
}
-
- if (output)
- g_variant_unref (output);
- g_variant_unref (input);
- g_object_unref (proxy);
}
- if (error)
- {
- if (proxy == NULL ||
- (error->domain == G_DBUS_ERROR &&
- (error->code == G_DBUS_ERROR_SERVICE_UNKNOWN ||
- error->code == G_DBUS_ERROR_UNKNOWN_METHOD)))
- g_warning ("Install system-config-printer which provides \
-DBus method \"GroupPhysicalDevices\" to group duplicates in device list.");
+ if (output)
+ g_variant_unref (output);
+ g_variant_unref (input);
+ g_object_unref (proxy);
+ }
- for (i = 0; i < pp->num_devices; i++)
- pp->devices[i].show = TRUE;
- }
+ if (error)
+ {
+ if (proxy == NULL ||
+ (error->domain == G_DBUS_ERROR &&
+ (error->code == G_DBUS_ERROR_SERVICE_UNKNOWN ||
+ error->code == G_DBUS_ERROR_UNKNOWN_METHOD)))
+ g_warning ("Install system-config-printer which provides \
+DBus method \"GroupPhysicalDevices\" to group duplicates in device list.");
for (i = 0; i < pp->num_devices; i++)
- if (!pp->devices[i].device_id)
- pp->devices[i].show = FALSE;
+ pp->devices[i].show = TRUE;
}
- g_hash_table_destroy (devices);
- actualize_devices_list (pp);
+ for (i = 0; i < pp->num_devices; i++)
+ if (!pp->devices[i].device_id)
+ pp->devices[i].show = FALSE;
}
- widget = (GtkWidget*)
- gtk_builder_get_object (pp->builder, "get-devices-status-label");
- gtk_label_set_text (GTK_LABEL (widget), " ");
+ g_hash_table_destroy (devices);
+ actualize_devices_list (pp);
+ }
- widget = (GtkWidget*)
- gtk_builder_get_object (pp->builder, "spinner");
- gtk_spinner_stop (GTK_SPINNER (widget));
- gtk_widget_set_sensitive (widget, FALSE);
- gtk_widget_hide (widget);
+ widget = (GtkWidget*)
+ gtk_builder_get_object (pp->builder, "get-devices-status-label");
+ gtk_label_set_text (GTK_LABEL (widget), " ");
- if (pp->cancellable != NULL)
- {
- g_object_unref (pp->cancellable);
- pp->cancellable = NULL;
- }
+ widget = (GtkWidget*)
+ gtk_builder_get_object (pp->builder, "spinner");
+ gtk_spinner_stop (GTK_SPINNER (widget));
+ gtk_widget_set_sensitive (widget, FALSE);
+ gtk_widget_hide (widget);
- g_clear_error (&error);
+ if (pp->cancellable != NULL)
+ {
+ g_object_unref (pp->cancellable);
+ pp->cancellable = NULL;
}
}
@@ -627,54 +632,59 @@ devices_get (PpNewPrinterDialog *pp)
NULL,
&error);
- if (proxy)
+ if (!proxy)
{
- if (pp->show_warning)
- {
- widget = (GtkWidget*)
- gtk_builder_get_object (pp->builder, "local-devices-notebook");
- gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), WARNING_TAB);
-
- widget = (GtkWidget*)
- gtk_builder_get_object (pp->builder, "network-devices-notebook");
- gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), WARNING_TAB);
- }
-
- in_include = g_variant_builder_new (G_VARIANT_TYPE ("as"));
- in_exclude = g_variant_builder_new (G_VARIANT_TYPE ("as"));
-
- dg_input = g_variant_new ("(iiasas)",
- 0,
- 60,
- in_include,
- in_exclude);
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ pp->searching = FALSE;
+ return;
+ }
+ if (pp->show_warning)
+ {
widget = (GtkWidget*)
- gtk_builder_get_object (pp->builder, "get-devices-status-label");
- gtk_label_set_text (GTK_LABEL (widget), _("Getting devices..."));
+ gtk_builder_get_object (pp->builder, "local-devices-notebook");
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), WARNING_TAB);
widget = (GtkWidget*)
- gtk_builder_get_object (pp->builder, "spinner");
- gtk_spinner_start (GTK_SPINNER (widget));
- gtk_widget_set_sensitive (widget, TRUE);
- gtk_widget_show (widget);
-
- pp->cancellable = g_cancellable_new ();
-
- g_dbus_proxy_call (proxy,
- "DevicesGet",
- dg_input,
- G_DBUS_CALL_FLAGS_NONE,
- 60000,
- pp->cancellable,
- devices_get_cb,
- pp);
-
- g_variant_builder_unref (in_exclude);
- g_variant_builder_unref (in_include);
- g_variant_unref (dg_input);
+ gtk_builder_get_object (pp->builder, "network-devices-notebook");
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), WARNING_TAB);
}
+ in_include = g_variant_builder_new (G_VARIANT_TYPE ("as"));
+ in_exclude = g_variant_builder_new (G_VARIANT_TYPE ("as"));
+
+ dg_input = g_variant_new ("(iiasas)",
+ 0,
+ 60,
+ in_include,
+ in_exclude);
+
+ widget = (GtkWidget*)
+ gtk_builder_get_object (pp->builder, "get-devices-status-label");
+ gtk_label_set_text (GTK_LABEL (widget), _("Getting devices..."));
+
+ widget = (GtkWidget*)
+ gtk_builder_get_object (pp->builder, "spinner");
+ gtk_spinner_start (GTK_SPINNER (widget));
+ gtk_widget_set_sensitive (widget, TRUE);
+ gtk_widget_show (widget);
+
+ pp->cancellable = g_cancellable_new ();
+
+ g_dbus_proxy_call (proxy,
+ "DevicesGet",
+ dg_input,
+ G_DBUS_CALL_FLAGS_NONE,
+ 60000,
+ pp->cancellable,
+ devices_get_cb,
+ pp);
+
+ g_variant_builder_unref (in_exclude);
+ g_variant_builder_unref (in_include);
+ g_variant_unref (dg_input);
+
pp->searching = FALSE;
}
@@ -770,7 +780,6 @@ service_enable (gchar *service_name,
GVariant *input = NULL;
GVariant *output = NULL;
GError *error = NULL;
- gint result;
proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_NONE,
@@ -781,27 +790,36 @@ service_enable (gchar *service_name,
NULL,
&error);
- if (proxy)
+ if (!proxy)
{
- input = g_variant_new ("(si)",
- service_name,
- service_timeout);
-
- output = g_dbus_proxy_call_sync (proxy,
- "enableService",
- input,
- G_DBUS_CALL_FLAGS_NONE,
- 60000,
- NULL,
- &error);
-
- if (output && g_variant_n_children (output) == 1)
- g_variant_get (output, "(i)", &result);
-
- if (output)
- g_variant_unref (output);
- g_variant_unref (input);
- g_object_unref (proxy);
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ input = g_variant_new ("(si)",
+ service_name,
+ service_timeout);
+
+ output = g_dbus_proxy_call_sync (proxy,
+ "enableService",
+ input,
+ G_DBUS_CALL_FLAGS_NONE,
+ 60000,
+ NULL,
+ &error);
+
+ g_variant_unref (input);
+ g_object_unref (proxy);
+
+ if (output)
+ {
+ g_variant_unref (output);
+ }
+ else
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
}
}
@@ -812,7 +830,6 @@ service_disable (gchar *service_name)
GVariant *input = NULL;
GVariant *output = NULL;
GError *error = NULL;
- gint result;
proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_NONE,
@@ -823,25 +840,34 @@ service_disable (gchar *service_name)
NULL,
&error);
- if (proxy)
+ if (!proxy)
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ input = g_variant_new ("(s)", service_name);
+
+ output = g_dbus_proxy_call_sync (proxy,
+ "disableService",
+ input,
+ G_DBUS_CALL_FLAGS_NONE,
+ 60000,
+ NULL,
+ &error);
+
+ g_variant_unref (input);
+ g_object_unref (proxy);
+
+ if (output)
{
- input = g_variant_new ("(s)", service_name);
-
- output = g_dbus_proxy_call_sync (proxy,
- "disableService",
- input,
- G_DBUS_CALL_FLAGS_NONE,
- 60000,
- NULL,
- &error);
-
- if (output && g_variant_n_children (output) == 1)
- g_variant_get (output, "(i)", &result);
-
- if (output)
- g_variant_unref (output);
- g_variant_unref (input);
- g_object_unref (proxy);
+ g_variant_unref (output);
+ }
+ else
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
}
}
@@ -863,26 +889,38 @@ service_enabled (gchar *service_name)
NULL,
&error);
- if (proxy)
+ if (!proxy)
{
- input = g_variant_new ("(s)",
- service_name);
-
- output = g_dbus_proxy_call_sync (proxy,
- "queryService",
- input,
- G_DBUS_CALL_FLAGS_NONE,
- 60000,
- NULL,
- &error);
-
- if (output && g_variant_n_children (output) == 1)
- g_variant_get (output, "(i)", &query_result);
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
- if (output)
- g_variant_unref (output);
- g_variant_unref (input);
- g_object_unref (proxy);
+ input = g_variant_new ("(s)",
+ service_name);
+
+ output = g_dbus_proxy_call_sync (proxy,
+ "queryService",
+ input,
+ G_DBUS_CALL_FLAGS_NONE,
+ 60000,
+ NULL,
+ &error);
+
+ g_variant_unref (input);
+ g_object_unref (proxy);
+
+ if (output)
+ {
+ if (g_variant_n_children (output) == 1)
+ g_variant_get (output, "(i)", &query_result);
+ g_variant_unref (output);
+ }
+ else
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ return FALSE;
}
if (query_result > 0)
@@ -911,26 +949,35 @@ dbus_method_available (gchar *name,
NULL,
NULL);
- if (proxy)
+ if (!proxy)
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ output = g_dbus_proxy_call_sync (proxy,
+ method,
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ 60000,
+ NULL,
+ &error);
+
+ g_object_unref (proxy);
+
+ if (output)
{
- output = g_dbus_proxy_call_sync (proxy,
- method,
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- 60000,
- NULL,
- &error);
-
- if (error &&
- error->domain == G_DBUS_ERROR &&
+ g_variant_unref (output);
+ result = TRUE;
+ }
+ else
+ {
+ if (error->domain == G_DBUS_ERROR &&
error->code == G_DBUS_ERROR_SERVICE_UNKNOWN)
result = FALSE;
else
result = TRUE;
-
- if (output)
- g_variant_unref (output);
- g_object_unref (proxy);
}
return result;
@@ -1112,8 +1159,8 @@ search_address_cb (GtkToggleButton *togglebutton,
}
else
{
- if (error)
- g_warning ("%s", error->message);
+ g_warning ("%s", error->message);
+ g_error_free (error);
}
g_free (command);
@@ -1539,6 +1586,7 @@ new_printer_add_button_cb (GtkButton *button,
if (ppd_file_name)
{
DBusGProxy *proxy;
+ gboolean result;
GError *error = NULL;
char *ret_error = NULL;
@@ -1548,29 +1596,30 @@ new_printer_add_button_cb (GtkButton *button,
TRUE);
if (proxy)
{
- dbus_g_proxy_call (proxy, "PrinterAddWithPpdFile", &error,
- G_TYPE_STRING, pp->devices[device_id].display_name,
- G_TYPE_STRING, pp->devices[device_id].device_uri,
- G_TYPE_STRING, ppd_file_name,
- G_TYPE_STRING, pp->devices[device_id].device_info,
- G_TYPE_STRING, pp->devices[device_id].device_location,
- G_TYPE_INVALID,
- G_TYPE_STRING, &ret_error,
- G_TYPE_INVALID);
-
- if (error || (ret_error && ret_error[0] != '\0'))
+ result = dbus_g_proxy_call (proxy, "PrinterAddWithPpdFile", &error,
+ G_TYPE_STRING, pp->devices[device_id].display_name,
+ G_TYPE_STRING, pp->devices[device_id].device_uri,
+ G_TYPE_STRING, ppd_file_name,
+ G_TYPE_STRING, pp->devices[device_id].device_info,
+ G_TYPE_STRING, pp->devices[device_id].device_location,
+ G_TYPE_INVALID,
+ G_TYPE_STRING, &ret_error,
+ G_TYPE_INVALID);
+
+ if (!result)
{
+ g_warning ("%s", error->message);
+ g_error_free (error);
dialog_response = GTK_RESPONSE_REJECT;
+ }
- if (error)
- g_warning ("%s", error->message);
-
- if (ret_error && ret_error[0] != '\0')
- g_warning ("%s", ret_error);
-
- g_clear_error (&error);
+ if (ret_error && ret_error[0] != '\0')
+ {
+ g_warning ("%s", ret_error);
+ dialog_response = GTK_RESPONSE_REJECT;
}
- else
+
+ if (result && (!ret_error || ret_error[0] == '\0'))
success = TRUE;
g_object_unref (proxy);
@@ -1599,6 +1648,7 @@ new_printer_add_button_cb (GtkButton *button,
{
/* Try PackageKit to install printer driver */
DBusGProxy *proxy;
+ gboolean result;
GError *error = NULL;
proxy = get_dbus_proxy (PACKAGE_KIT_BUS,
@@ -1614,7 +1664,7 @@ new_printer_add_button_cb (GtkButton *button,
device_ids[0] = pp->devices[device_id].device_id;
device_ids[1] = NULL;
- dbus_g_proxy_call_with_timeout (proxy,
+ result = dbus_g_proxy_call_with_timeout (proxy,
"InstallPrinterDrivers",
3600000,
&error,
@@ -1630,10 +1680,11 @@ new_printer_add_button_cb (GtkButton *button,
g_object_unref (proxy);
- if (error)
- g_warning ("%s", error->message);
-
- g_clear_error (&error);
+ if (!result)
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
if (ppd_name)
{
@@ -1654,6 +1705,7 @@ new_printer_add_button_cb (GtkButton *button,
if (ppd_name && ppd_name->ppd_name)
{
DBusGProxy *proxy;
+ gboolean result;
GError *error = NULL;
char *ret_error = NULL;
@@ -1663,27 +1715,27 @@ new_printer_add_button_cb (GtkButton *button,
TRUE);
if (proxy)
{
- dbus_g_proxy_call (proxy, "PrinterAdd", &error,
- G_TYPE_STRING, pp->devices[device_id].display_name,
- G_TYPE_STRING, pp->devices[device_id].device_uri,
- G_TYPE_STRING, ppd_name->ppd_name,
- G_TYPE_STRING, pp->devices[device_id].device_info,
- G_TYPE_STRING, pp->devices[device_id].device_location,
- G_TYPE_INVALID,
- G_TYPE_STRING, &ret_error,
- G_TYPE_INVALID);
-
- if (error || (ret_error && ret_error[0] != '\0'))
+ result = dbus_g_proxy_call (proxy, "PrinterAdd", &error,
+ G_TYPE_STRING, pp->devices[device_id].display_name,
+ G_TYPE_STRING, pp->devices[device_id].device_uri,
+ G_TYPE_STRING, ppd_name->ppd_name,
+ G_TYPE_STRING, pp->devices[device_id].device_info,
+ G_TYPE_STRING, pp->devices[device_id].device_location,
+ G_TYPE_INVALID,
+ G_TYPE_STRING, &ret_error,
+ G_TYPE_INVALID);
+
+ if (!result)
{
+ g_warning ("%s", error->message);
+ g_error_free (error);
dialog_response = GTK_RESPONSE_REJECT;
+ }
- if (error)
- g_warning ("%s", error->message);
-
- if (ret_error && ret_error[0] != '\0')
- g_warning ("%s", ret_error);
-
- g_clear_error (&error);
+ if (ret_error && ret_error[0] != '\0')
+ {
+ g_warning ("%s", ret_error);
+ dialog_response = GTK_RESPONSE_REJECT;
}
g_object_unref (proxy);
@@ -1705,6 +1757,7 @@ new_printer_add_button_cb (GtkButton *button,
{
const char *ppd_file_name = NULL;
DBusGProxy *proxy;
+ gboolean result;
GError *error = NULL;
char *ret_error = NULL;
ppd_file_t *ppd_file = NULL;
@@ -1784,22 +1837,24 @@ new_printer_add_button_cb (GtkButton *button,
if (value)
{
- dbus_g_proxy_call (proxy, "PrinterAddOptionDefault", &error,
- G_TYPE_STRING, pp->devices[device_id].display_name,
- G_TYPE_STRING, "PageSize",
- G_TYPE_STRV, value,
- G_TYPE_INVALID,
- G_TYPE_STRING, &ret_error,
- G_TYPE_INVALID);
-
- if (error)
+ result = dbus_g_proxy_call (proxy, "PrinterAddOptionDefault", &error,
+ G_TYPE_STRING, pp->devices[device_id].display_name,
+ G_TYPE_STRING, "PageSize",
+ G_TYPE_STRV, value,
+ G_TYPE_INVALID,
+ G_TYPE_STRING, &ret_error,
+ G_TYPE_INVALID);
+
+ if (!result)
{
g_warning ("%s", error->message);
- g_clear_error (&error);
+ g_error_free (error);
}
if (ret_error && ret_error[0] != '\0')
- g_warning ("%s", ret_error);
+ {
+ g_warning ("%s", ret_error);
+ }
g_strfreev (value);
}
@@ -1852,7 +1907,6 @@ new_printer_add_button_cb (GtkButton *button,
GList *executables = NULL;
GList *packages = NULL;
- g_clear_error (&error);
error = NULL;
proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
@@ -1877,26 +1931,28 @@ new_printer_add_button_cb (GtkButton *button,
NULL,
&error);
- if (output && g_variant_n_children (output) == 1)
+ g_variant_unref (input);
+ g_object_unref (proxy);
+
+ if (output)
{
- array = g_variant_get_child_value (output, 0);
- if (array)
+ if (g_variant_n_children (output) == 1)
{
- for (i = 0; i < g_variant_n_children (array); i++)
+ array = g_variant_get_child_value (output, 0);
+ if (array)
{
- executables = g_list_append (
- executables,
- g_strdup (g_variant_get_string (
- g_variant_get_child_value (array, i),
- NULL)));
+ for (i = 0; i < g_variant_n_children (array); i++)
+ {
+ executables = g_list_append (
+ executables,
+ g_strdup (g_variant_get_string (
+ g_variant_get_child_value (array, i),
+ NULL)));
+ }
}
}
+ g_variant_unref (output);
}
-
- if (output)
- g_variant_unref (output);
- g_variant_unref (input);
- g_object_unref (proxy);
}
if (proxy == NULL ||
@@ -1904,8 +1960,11 @@ new_printer_add_button_cb (GtkButton *button,
error->domain == G_DBUS_ERROR &&
(error->code == G_DBUS_ERROR_SERVICE_UNKNOWN ||
error->code == G_DBUS_ERROR_UNKNOWN_METHOD)))
- g_warning ("Install system-config-printer which provides \
+ {
+ g_warning ("Install system-config-printer which provides \
DBus method \"MissingExecutables\" to find missing executables and filters.");
+ g_error_free (error);
+ }
executables = g_list_sort (executables, (GCompareFunc) g_strcmp0);
executables = glist_uniq (executables);
@@ -1937,8 +1996,7 @@ DBus method \"MissingExecutables\" to find missing executables and filters.");
NULL,
&error);
- if (error)
- g_warning ("%s", error->message);
+ g_variant_unref (input);
if (output)
{
@@ -1951,15 +2009,22 @@ DBus method \"MissingExecutables\" to find missing executables and filters.");
&package);
if (!installed)
packages = g_list_append (packages, g_strdup (package));
+ g_variant_unref (output);
+ }
+ else
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
}
-
- if (output)
- g_variant_unref (output);
- g_variant_unref (input);
}
g_object_unref (proxy);
}
+ else
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
g_list_free_full (executables, g_free);
}
@@ -2007,14 +2072,23 @@ DBus method \"MissingExecutables\" to find missing executables and filters.");
NULL,
&error);
- if (error)
- g_warning ("%s", error->message);
-
- if (output)
- g_variant_unref (output);
g_variant_unref (input);
-
g_object_unref (proxy);
+
+ if (output)
+ {
+ g_variant_unref (output);
+ }
+ else
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
+ }
+ else
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
}
g_list_free_full (packages, g_free);
@@ -2049,17 +2123,18 @@ pp_new_printer_dialog_new (GtkWindow *parent,
GtkWidget *widget;
GError *error = NULL;
gchar *objects[] = { "dialog", "main-vbox", NULL };
+ guint builder_result;
pp = g_new0 (PpNewPrinterDialog, 1);
pp->builder = gtk_builder_new ();
pp->parent = GTK_WIDGET (parent);
- gtk_builder_add_objects_from_file (pp->builder,
- DATADIR"/new-printer-dialog.ui",
- objects, &error);
+ builder_result = gtk_builder_add_objects_from_file (pp->builder,
+ DATADIR"/new-printer-dialog.ui",
+ objects, &error);
- if (error)
+ if (builder_result == 0)
{
g_warning ("Could not load ui: %s", error->message);
g_error_free (error);
diff --git a/panels/printers/pp-utils.c b/panels/printers/pp-utils.c
index d2a95c4..0846fc5 100644
--- a/panels/printers/pp-utils.c
+++ b/panels/printers/pp-utils.c
@@ -44,15 +44,14 @@ get_dbus_proxy (const gchar *name,
{
DBusGConnection *bus;
DBusGProxy *proxy;
- GError *error;
+ GError *error = NULL;
- error = NULL;
if (system_bus)
bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
else
bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
- if (bus == NULL)
+ if (!bus)
{
if (system_bus)
/* Translators: Program cannot connect to DBus' system bus */
@@ -64,14 +63,13 @@ get_dbus_proxy (const gchar *name,
return NULL;
}
- error = NULL;
-
proxy = dbus_g_proxy_new_for_name (bus, name, path, iface);
return proxy;
}
-gchar *get_tag_value (const gchar *tag_string, const gchar *tag_name)
+gchar *
+get_tag_value (const gchar *tag_string, const gchar *tag_name)
{
gchar **tag_string_splitted = NULL;
gchar *tag_value = NULL;
@@ -927,6 +925,7 @@ get_ppd_name (gchar *device_id,
g_warning ("You should install system-config-printer which provides \
DBus method \"GetBestDrivers\". Using fallback solution for now.");
+ g_error_free (error);
mfg = get_tag_value (device_id, "mfg");
if (!mfg)
@@ -1290,55 +1289,59 @@ execute_maintenance_command (const char *printer_name,
GError *error = NULL;
ipp_t *request = NULL;
ipp_t *response = NULL;
- char uri[HTTP_MAX_URI + 1];
+ gchar *file_name = NULL;
+ char *uri;
int fd = -1;
http = httpConnectEncrypt (cupsServer (),
ippPort (),
cupsEncryption ());
- if (http)
- {
- request = ippNewRequest (IPP_PRINT_JOB);
+ if (!http)
+ return NULL;
- g_snprintf (uri,
- sizeof (uri),
- "ipp://localhost/printers/%s",
- printer_name);
+ request = ippNewRequest (IPP_PRINT_JOB);
- ippAddString (request,
- IPP_TAG_OPERATION,
- IPP_TAG_URI,
- "printer-uri",
- NULL,
- uri);
+ uri = g_strdup_printf ("ipp://localhost/printers/%s", printer_name);
- ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name",
- NULL, title);
+ ippAddString (request,
+ IPP_TAG_OPERATION,
+ IPP_TAG_URI,
+ "printer-uri",
+ NULL,
+ uri);
- ippAddString (request, IPP_TAG_JOB, IPP_TAG_MIMETYPE, "document-format",
- NULL, "application/vnd.cups-command");
+ g_free (uri);
- gchar *file_name = NULL;
- fd = g_file_open_tmp ("ccXXXXXX", &file_name, &error);
+ ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name",
+ NULL, title);
- if (fd != -1 && !error)
- {
- FILE *file;
+ ippAddString (request, IPP_TAG_JOB, IPP_TAG_MIMETYPE, "document-format",
+ NULL, "application/vnd.cups-command");
- file = fdopen (fd, "w");
- fprintf (file, "#CUPS-COMMAND\n");
- fprintf (file, "%s\n", command);
- fclose (file);
+ fd = g_file_open_tmp ("ccXXXXXX", &file_name, &error);
- response = cupsDoFileRequest (http, request, "/", file_name);
- g_unlink (file_name);
- }
+ if (fd != -1)
+ {
+ FILE *file;
- g_free (file_name);
- httpClose (http);
+ file = fdopen (fd, "w");
+ fprintf (file, "#CUPS-COMMAND\n");
+ fprintf (file, "%s\n", command);
+ fclose (file);
+
+ response = cupsDoFileRequest (http, request, "/", file_name);
+ g_unlink (file_name);
+ }
+ else
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
}
+ g_free (file_name);
+ httpClose (http);
+
return response;
}
@@ -1350,60 +1353,67 @@ ccGetAllowedUsers (gchar ***allowed_users, const char *printer_name)
ipp_t *request = NULL;
gchar **users = NULL;
ipp_t *response;
- char uri[HTTP_MAX_URI + 1];
+ char *uri;
int num_allowed_users = 0;
http = httpConnectEncrypt (cupsServer (),
ippPort (),
cupsEncryption ());
- if (http)
+ if (!http)
{
- request = ippNewRequest (IPP_GET_PRINTER_ATTRIBUTES);
+ *allowed_users = NULL;
+ return 0;
+ }
- g_snprintf (uri, sizeof (uri), "ipp://localhost/printers/%s", printer_name);
- ippAddString (request,
- IPP_TAG_OPERATION,
- IPP_TAG_URI,
- "printer-uri",
- NULL,
- uri);
- ippAddStrings (request,
- IPP_TAG_OPERATION,
- IPP_TAG_KEYWORD,
- "requested-attributes",
- 1,
- NULL,
- attrs);
+ request = ippNewRequest (IPP_GET_PRINTER_ATTRIBUTES);
- response = cupsDoRequest (http, request, "/");
- if (response)
- {
- ipp_attribute_t *attr = NULL;
- ipp_attribute_t *allowed = NULL;
+ uri = g_strdup_printf ("ipp://localhost/printers/%s", printer_name);
- for (attr = response->attrs; attr != NULL; attr = attr->next)
- {
- if (attr->group_tag == IPP_TAG_PRINTER &&
- attr->value_tag == IPP_TAG_NAME &&
- !g_strcmp0 (attr->name, "requesting-user-name-allowed"))
- allowed = attr;
- }
+ ippAddString (request,
+ IPP_TAG_OPERATION,
+ IPP_TAG_URI,
+ "printer-uri",
+ NULL,
+ uri);
- if (allowed && allowed->num_values > 0)
- {
- int i;
+ g_free (uri);
- num_allowed_users = allowed->num_values;
- users = g_new (gchar*, num_allowed_users);
+ ippAddStrings (request,
+ IPP_TAG_OPERATION,
+ IPP_TAG_KEYWORD,
+ "requested-attributes",
+ 1,
+ NULL,
+ attrs);
- for (i = 0; i < num_allowed_users; i ++)
- users[i] = g_strdup (allowed->values[i].string.text);
- }
- ippDelete(response);
+ response = cupsDoRequest (http, request, "/");
+ if (response)
+ {
+ ipp_attribute_t *attr = NULL;
+ ipp_attribute_t *allowed = NULL;
+
+ for (attr = response->attrs; attr != NULL; attr = attr->next)
+ {
+ if (attr->group_tag == IPP_TAG_PRINTER &&
+ attr->value_tag == IPP_TAG_NAME &&
+ !g_strcmp0 (attr->name, "requesting-user-name-allowed"))
+ allowed = attr;
}
- httpClose (http);
- }
+
+ if (allowed && allowed->num_values > 0)
+ {
+ int i;
+
+ num_allowed_users = allowed->num_values;
+ users = g_new (gchar*, num_allowed_users);
+
+ for (i = 0; i < num_allowed_users; i ++)
+ users[i] = g_strdup (allowed->values[i].string.text);
+ }
+ ippDelete(response);
+ }
+ httpClose (http);
*allowed_users = users;
return num_allowed_users;
@@ -1578,6 +1588,7 @@ printer_rename (const gchar *old_name,
gboolean printer_paused = FALSE;
gboolean default_printer = FALSE;
gboolean printer_shared = FALSE;
+ gboolean call_result;
GError *error = NULL;
http_t *http;
gchar **sheets = NULL;
@@ -1745,7 +1756,6 @@ printer_rename (const gchar *old_name,
if (proxy)
{
-
if (printer_type & CUPS_PRINTER_CLASS)
{
if (member_names)
@@ -1753,24 +1763,26 @@ printer_rename (const gchar *old_name,
class_add_printer (new_name, member_names[i]);
}
else
- dbus_g_proxy_call (proxy, "PrinterAddWithPpdFile", &error,
- G_TYPE_STRING, new_name,
- G_TYPE_STRING, device_uri,
- G_TYPE_STRING, ppd_filename,
- G_TYPE_STRING, printer_info,
- G_TYPE_STRING, printer_location,
- G_TYPE_INVALID,
- G_TYPE_STRING, &ret_error,
- G_TYPE_INVALID);
-
- if (error)
{
- g_warning ("%s", error->message);
- g_clear_error (&error);
- }
+ call_result = dbus_g_proxy_call (proxy, "PrinterAddWithPpdFile", &error,
+ G_TYPE_STRING, new_name,
+ G_TYPE_STRING, device_uri,
+ G_TYPE_STRING, ppd_filename,
+ G_TYPE_STRING, printer_info,
+ G_TYPE_STRING, printer_location,
+ G_TYPE_INVALID,
+ G_TYPE_STRING, &ret_error,
+ G_TYPE_INVALID);
+
+ if (!call_result)
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
- if (ret_error && ret_error[0] != '\0')
- g_warning ("%s", ret_error);
+ if (ret_error && ret_error[0] != '\0')
+ g_warning ("%s", ret_error);
+ }
g_object_unref (proxy);
}
@@ -1818,43 +1830,42 @@ printer_set_location (const gchar *printer_name,
const gchar *location)
{
DBusGProxy *proxy;
- gboolean result = TRUE;
+ gboolean result;
GError *error = NULL;
char *ret_error = NULL;
- if (printer_name && location)
- {
- proxy = get_dbus_proxy (MECHANISM_BUS,
- "/",
- MECHANISM_BUS,
- TRUE);
+ if (!printer_name || !location)
+ return TRUE;
- if (proxy)
- {
- dbus_g_proxy_call (proxy, "PrinterSetLocation", &error,
- G_TYPE_STRING, printer_name,
- G_TYPE_STRING, location,
- G_TYPE_INVALID,
- G_TYPE_STRING, &ret_error,
- G_TYPE_INVALID);
-
- if (error)
- {
- g_warning ("%s", error->message);
- g_clear_error (&error);
- result = FALSE;
- }
+ proxy = get_dbus_proxy (MECHANISM_BUS,
+ "/",
+ MECHANISM_BUS,
+ TRUE);
- if (ret_error && ret_error[0] != '\0')
- {
- g_warning ("%s", ret_error);
- result = FALSE;
- }
+ if (!proxy)
+ return TRUE;
- g_object_unref (proxy);
- }
+ result = dbus_g_proxy_call (proxy, "PrinterSetLocation", &error,
+ G_TYPE_STRING, printer_name,
+ G_TYPE_STRING, location,
+ G_TYPE_INVALID,
+ G_TYPE_STRING, &ret_error,
+ G_TYPE_INVALID);
+
+ if (!result)
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
+
+ if (ret_error && ret_error[0] != '\0')
+ {
+ g_warning ("%s", ret_error);
+ result = FALSE;
}
+ g_object_unref (proxy);
+
return result;
}
@@ -1864,44 +1875,43 @@ printer_set_accepting_jobs (const gchar *printer_name,
const gchar *reason)
{
DBusGProxy *proxy;
- gboolean result = TRUE;
+ gboolean result;
GError *error = NULL;
char *ret_error = NULL;
- if (printer_name)
- {
- proxy = get_dbus_proxy (MECHANISM_BUS,
- "/",
- MECHANISM_BUS,
- TRUE);
+ if (!printer_name)
+ return TRUE;
- if (proxy)
- {
- dbus_g_proxy_call (proxy, "PrinterSetAcceptJobs", &error,
- G_TYPE_STRING, printer_name,
- G_TYPE_BOOLEAN, accepting_jobs,
- G_TYPE_STRING, reason,
- G_TYPE_INVALID,
- G_TYPE_STRING, &ret_error,
- G_TYPE_INVALID);
-
- if (error)
- {
- g_warning ("%s", error->message);
- g_clear_error (&error);
- result = FALSE;
- }
+ proxy = get_dbus_proxy (MECHANISM_BUS,
+ "/",
+ MECHANISM_BUS,
+ TRUE);
- if (ret_error && ret_error[0] != '\0')
- {
- g_warning ("%s", ret_error);
- result = FALSE;
- }
+ if (!proxy)
+ return TRUE;
- g_object_unref (proxy);
- }
+ result = dbus_g_proxy_call (proxy, "PrinterSetAcceptJobs", &error,
+ G_TYPE_STRING, printer_name,
+ G_TYPE_BOOLEAN, accepting_jobs,
+ G_TYPE_STRING, reason,
+ G_TYPE_INVALID,
+ G_TYPE_STRING, &ret_error,
+ G_TYPE_INVALID);
+
+ if (!result)
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
}
+ if (ret_error && ret_error[0] != '\0')
+ {
+ g_warning ("%s", ret_error);
+ result = FALSE;
+ }
+
+ g_object_unref (proxy);
+
return result;
}
@@ -1910,43 +1920,42 @@ printer_set_enabled (const gchar *printer_name,
gboolean enabled)
{
DBusGProxy *proxy;
- gboolean result = TRUE;
+ gboolean result;
GError *error = NULL;
char *ret_error = NULL;
- if (printer_name)
- {
- proxy = get_dbus_proxy (MECHANISM_BUS,
- "/",
- MECHANISM_BUS,
- TRUE);
+ if (!printer_name)
+ return TRUE;
- if (proxy)
- {
- dbus_g_proxy_call (proxy, "PrinterSetEnabled", &error,
- G_TYPE_STRING, printer_name,
- G_TYPE_BOOLEAN, enabled,
- G_TYPE_INVALID,
- G_TYPE_STRING, &ret_error,
- G_TYPE_INVALID);
-
- if (error)
- {
- g_warning ("%s", error->message);
- g_clear_error (&error);
- result = FALSE;
- }
+ proxy = get_dbus_proxy (MECHANISM_BUS,
+ "/",
+ MECHANISM_BUS,
+ TRUE);
- if (ret_error && ret_error[0] != '\0')
- {
- g_warning ("%s", ret_error);
- result = FALSE;
- }
+ if (!proxy)
+ return TRUE;
- g_object_unref (proxy);
- }
+ result = dbus_g_proxy_call (proxy, "PrinterSetEnabled", &error,
+ G_TYPE_STRING, printer_name,
+ G_TYPE_BOOLEAN, enabled,
+ G_TYPE_INVALID,
+ G_TYPE_STRING, &ret_error,
+ G_TYPE_INVALID);
+
+ if (!result)
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
}
+ if (ret_error && ret_error[0] != '\0')
+ {
+ g_warning ("%s", ret_error);
+ result = FALSE;
+ }
+
+ g_object_unref (proxy);
+
return result;
}
@@ -1954,42 +1963,41 @@ gboolean
printer_delete (const gchar *printer_name)
{
DBusGProxy *proxy;
- gboolean result = TRUE;
+ gboolean result;
GError *error = NULL;
char *ret_error = NULL;
- if (printer_name)
- {
- proxy = get_dbus_proxy (MECHANISM_BUS,
- "/",
- MECHANISM_BUS,
- TRUE);
+ if (!printer_name)
+ return TRUE;
- if (proxy)
- {
- dbus_g_proxy_call (proxy, "PrinterDelete", &error,
- G_TYPE_STRING, printer_name,
- G_TYPE_INVALID,
- G_TYPE_STRING, &ret_error,
- G_TYPE_INVALID);
+ proxy = get_dbus_proxy (MECHANISM_BUS,
+ "/",
+ MECHANISM_BUS,
+ TRUE);
- if (error)
- {
- g_warning ("%s", error->message);
- g_clear_error (&error);
- result = FALSE;
- }
+ if (!proxy)
+ return TRUE;
- if (ret_error && ret_error[0] != '\0')
- {
- g_warning ("%s", ret_error);
- result = FALSE;
- }
+ result = dbus_g_proxy_call (proxy, "PrinterDelete", &error,
+ G_TYPE_STRING, printer_name,
+ G_TYPE_INVALID,
+ G_TYPE_STRING, &ret_error,
+ G_TYPE_INVALID);
- g_object_unref (proxy);
- }
+ if (!result)
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
}
+ if (ret_error && ret_error[0] != '\0')
+ {
+ g_warning ("%s", ret_error);
+ result = FALSE;
+ }
+
+ g_object_unref (proxy);
+
return result;
}
@@ -2002,56 +2010,55 @@ printer_set_default (const gchar *printer_name)
GError *error = NULL;
char *ret_error = NULL;
- if (printer_name)
- {
- cups_server = cupsServer ();
- if (g_ascii_strncasecmp (cups_server, "localhost", 9) == 0 ||
- g_ascii_strncasecmp (cups_server, "127.0.0.1", 9) == 0 ||
- g_ascii_strncasecmp (cups_server, "::1", 3) == 0 ||
- cups_server[0] == '/')
- {
- /* Clean .cups/lpoptions before setting
- * default printer on local CUPS server.
- */
- set_local_default_printer (NULL);
+ if (!printer_name)
+ return TRUE;
- proxy = get_dbus_proxy (MECHANISM_BUS,
- "/",
- MECHANISM_BUS,
- TRUE);
+ cups_server = cupsServer ();
+ if (g_ascii_strncasecmp (cups_server, "localhost", 9) == 0 ||
+ g_ascii_strncasecmp (cups_server, "127.0.0.1", 9) == 0 ||
+ g_ascii_strncasecmp (cups_server, "::1", 3) == 0 ||
+ cups_server[0] == '/')
+ {
+ /* Clean .cups/lpoptions before setting
+ * default printer on local CUPS server.
+ */
+ set_local_default_printer (NULL);
- if (proxy)
- {
- dbus_g_proxy_call (proxy, "PrinterSetDefault", &error,
- G_TYPE_STRING, printer_name,
- G_TYPE_INVALID,
- G_TYPE_STRING, &ret_error,
- G_TYPE_INVALID);
+ proxy = get_dbus_proxy (MECHANISM_BUS,
+ "/",
+ MECHANISM_BUS,
+ TRUE);
- if (error)
- {
- g_warning ("%s", error->message);
- g_clear_error (&error);
- result = FALSE;
- }
+ if (proxy)
+ {
+ result = dbus_g_proxy_call (proxy, "PrinterSetDefault", &error,
+ G_TYPE_STRING, printer_name,
+ G_TYPE_INVALID,
+ G_TYPE_STRING, &ret_error,
+ G_TYPE_INVALID);
- if (ret_error && ret_error[0] != '\0')
- {
- g_warning ("%s", ret_error);
- result = FALSE;
- }
+ if (!result)
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
- g_object_unref (proxy);
+ if (ret_error && ret_error[0] != '\0')
+ {
+ g_warning ("%s", ret_error);
+ result = FALSE;
}
- }
- else
- /* Store default printer to .cups/lpoptions
- * if we are connected to a remote CUPS server.
- */
- {
- set_local_default_printer (printer_name);
+
+ g_object_unref (proxy);
}
}
+ else
+ /* Store default printer to .cups/lpoptions
+ * if we are connected to a remote CUPS server.
+ */
+ {
+ set_local_default_printer (printer_name);
+ }
return result;
}
@@ -2061,43 +2068,42 @@ printer_set_shared (const gchar *printer_name,
gboolean shared)
{
DBusGProxy *proxy;
- gboolean result = TRUE;
+ gboolean result;
GError *error = NULL;
char *ret_error = NULL;
- if (printer_name)
- {
- proxy = get_dbus_proxy (MECHANISM_BUS,
- "/",
- MECHANISM_BUS,
- TRUE);
+ if (!printer_name)
+ return TRUE;
- if (proxy)
- {
- dbus_g_proxy_call (proxy, "PrinterSetShared", &error,
- G_TYPE_STRING, printer_name,
- G_TYPE_BOOLEAN, shared,
- G_TYPE_INVALID,
- G_TYPE_STRING, &ret_error,
- G_TYPE_INVALID);
-
- if (error)
- {
- g_warning ("%s", error->message);
- g_clear_error (&error);
- result = FALSE;
- }
+ proxy = get_dbus_proxy (MECHANISM_BUS,
+ "/",
+ MECHANISM_BUS,
+ TRUE);
- if (ret_error && ret_error[0] != '\0')
- {
- g_warning ("%s", ret_error);
- result = FALSE;
- }
+ if (!proxy)
+ return TRUE;
- g_object_unref (proxy);
- }
+ result = dbus_g_proxy_call (proxy, "PrinterSetShared", &error,
+ G_TYPE_STRING, printer_name,
+ G_TYPE_BOOLEAN, shared,
+ G_TYPE_INVALID,
+ G_TYPE_STRING, &ret_error,
+ G_TYPE_INVALID);
+
+ if (!result)
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
+
+ if (ret_error && ret_error[0] != '\0')
+ {
+ g_warning ("%s", ret_error);
+ result = FALSE;
}
+ g_object_unref (proxy);
+
return result;
}
@@ -2107,44 +2113,43 @@ printer_set_job_sheets (const gchar *printer_name,
const gchar *end_sheet)
{
DBusGProxy *proxy;
- gboolean result = TRUE;
+ gboolean result;
GError *error = NULL;
char *ret_error = NULL;
- if (printer_name && start_sheet && end_sheet)
- {
- proxy = get_dbus_proxy (MECHANISM_BUS,
- "/",
- MECHANISM_BUS,
- TRUE);
+ if (!printer_name || !start_sheet || !end_sheet)
+ return TRUE;
- if (proxy)
- {
- dbus_g_proxy_call (proxy, "PrinterSetJobSheets", &error,
- G_TYPE_STRING, printer_name,
- G_TYPE_STRING, start_sheet,
- G_TYPE_STRING, end_sheet,
- G_TYPE_INVALID,
- G_TYPE_STRING, &ret_error,
- G_TYPE_INVALID);
-
- if (error)
- {
- g_warning ("%s", error->message);
- g_clear_error (&error);
- result = FALSE;
- }
+ proxy = get_dbus_proxy (MECHANISM_BUS,
+ "/",
+ MECHANISM_BUS,
+ TRUE);
- if (ret_error && ret_error[0] != '\0')
- {
- g_warning ("%s", ret_error);
- result = FALSE;
- }
+ if (!proxy)
+ return TRUE;
- g_object_unref (proxy);
- }
+ result = dbus_g_proxy_call (proxy, "PrinterSetJobSheets", &error,
+ G_TYPE_STRING, printer_name,
+ G_TYPE_STRING, start_sheet,
+ G_TYPE_STRING, end_sheet,
+ G_TYPE_INVALID,
+ G_TYPE_STRING, &ret_error,
+ G_TYPE_INVALID);
+
+ if (!result)
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
}
+ if (ret_error && ret_error[0] != '\0')
+ {
+ g_warning ("%s", ret_error);
+ result = FALSE;
+ }
+
+ g_object_unref (proxy);
+
return result;
}
@@ -2154,51 +2159,50 @@ printer_set_policy (const gchar *printer_name,
gboolean error_policy)
{
DBusGProxy *proxy;
- gboolean result = TRUE;
+ gboolean result;
GError *error = NULL;
char *ret_error = NULL;
- if (printer_name && policy)
- {
- proxy = get_dbus_proxy (MECHANISM_BUS,
- "/",
- MECHANISM_BUS,
- TRUE);
+ if (!printer_name || !policy)
+ return TRUE;
- if (proxy)
- {
- if (error_policy)
- dbus_g_proxy_call (proxy, "PrinterSetErrorPolicy", &error,
- G_TYPE_STRING, printer_name,
- G_TYPE_STRING, policy,
- G_TYPE_INVALID,
- G_TYPE_STRING, &ret_error,
- G_TYPE_INVALID);
- else
- dbus_g_proxy_call (proxy, "PrinterSetOpPolicy", &error,
- G_TYPE_STRING, printer_name,
- G_TYPE_STRING, policy,
- G_TYPE_INVALID,
- G_TYPE_STRING, &ret_error,
- G_TYPE_INVALID);
-
- if (error)
- {
- g_warning ("%s", error->message);
- g_clear_error (&error);
- result = FALSE;
- }
+ proxy = get_dbus_proxy (MECHANISM_BUS,
+ "/",
+ MECHANISM_BUS,
+ TRUE);
- if (ret_error && ret_error[0] != '\0')
- {
- g_warning ("%s", ret_error);
- result = FALSE;
- }
+ if (!proxy)
+ return TRUE;
- g_object_unref (proxy);
- }
+ if (error_policy)
+ result = dbus_g_proxy_call (proxy, "PrinterSetErrorPolicy", &error,
+ G_TYPE_STRING, printer_name,
+ G_TYPE_STRING, policy,
+ G_TYPE_INVALID,
+ G_TYPE_STRING, &ret_error,
+ G_TYPE_INVALID);
+ else
+ result = dbus_g_proxy_call (proxy, "PrinterSetOpPolicy", &error,
+ G_TYPE_STRING, printer_name,
+ G_TYPE_STRING, policy,
+ G_TYPE_INVALID,
+ G_TYPE_STRING, &ret_error,
+ G_TYPE_INVALID);
+
+ if (!result)
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
}
+ if (ret_error && ret_error[0] != '\0')
+ {
+ g_warning ("%s", ret_error);
+ result = FALSE;
+ }
+
+ g_object_unref (proxy);
+
return result;
}
@@ -2208,51 +2212,50 @@ printer_set_users (const gchar *printer_name,
gboolean allowed)
{
DBusGProxy *proxy;
- gboolean result = TRUE;
+ gboolean result;
GError *error = NULL;
char *ret_error = NULL;
- if (printer_name && users)
- {
- proxy = get_dbus_proxy (MECHANISM_BUS,
- "/",
- MECHANISM_BUS,
- TRUE);
+ if (!printer_name || !users)
+ return TRUE;
- if (proxy)
- {
- if (allowed)
- dbus_g_proxy_call (proxy, "PrinterSetUsersAllowed", &error,
- G_TYPE_STRING, printer_name,
- G_TYPE_STRV, users,
- G_TYPE_INVALID,
- G_TYPE_STRING, &ret_error,
- G_TYPE_INVALID);
- else
- dbus_g_proxy_call (proxy, "PrinterSetUsersDenied", &error,
- G_TYPE_STRING, printer_name,
- G_TYPE_STRV, users,
- G_TYPE_INVALID,
- G_TYPE_STRING, &ret_error,
- G_TYPE_INVALID);
-
- if (error)
- {
- g_warning ("%s", error->message);
- g_clear_error (&error);
- result = FALSE;
- }
+ proxy = get_dbus_proxy (MECHANISM_BUS,
+ "/",
+ MECHANISM_BUS,
+ TRUE);
- if (ret_error && ret_error[0] != '\0')
- {
- g_warning ("%s", ret_error);
- result = FALSE;
- }
+ if (!proxy)
+ return TRUE;
- g_object_unref (proxy);
- }
+ if (allowed)
+ result = dbus_g_proxy_call (proxy, "PrinterSetUsersAllowed", &error,
+ G_TYPE_STRING, printer_name,
+ G_TYPE_STRV, users,
+ G_TYPE_INVALID,
+ G_TYPE_STRING, &ret_error,
+ G_TYPE_INVALID);
+ else
+ result = dbus_g_proxy_call (proxy, "PrinterSetUsersDenied", &error,
+ G_TYPE_STRING, printer_name,
+ G_TYPE_STRV, users,
+ G_TYPE_INVALID,
+ G_TYPE_STRING, &ret_error,
+ G_TYPE_INVALID);
+
+ if (!result)
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
+
+ if (ret_error && ret_error[0] != '\0')
+ {
+ g_warning ("%s", ret_error);
+ result = FALSE;
}
+ g_object_unref (proxy);
+
return result;
}
@@ -2261,43 +2264,42 @@ class_add_printer (const gchar *class_name,
const gchar *printer_name)
{
DBusGProxy *proxy;
- gboolean result = TRUE;
+ gboolean result;
GError *error = NULL;
char *ret_error = NULL;
- if (class_name && printer_name)
- {
- proxy = get_dbus_proxy (MECHANISM_BUS,
- "/",
- MECHANISM_BUS,
- TRUE);
+ if (!class_name || !printer_name)
+ return TRUE;
- if (proxy)
- {
- dbus_g_proxy_call (proxy, "ClassAddPrinter", &error,
- G_TYPE_STRING, class_name,
- G_TYPE_STRING, printer_name,
- G_TYPE_INVALID,
- G_TYPE_STRING, &ret_error,
- G_TYPE_INVALID);
-
- if (error)
- {
- g_warning ("%s", error->message);
- g_clear_error (&error);
- result = FALSE;
- }
+ proxy = get_dbus_proxy (MECHANISM_BUS,
+ "/",
+ MECHANISM_BUS,
+ TRUE);
- if (ret_error && ret_error[0] != '\0')
- {
- g_warning ("%s", ret_error);
- result = FALSE;
- }
+ if (!proxy)
+ return TRUE;
- g_object_unref (proxy);
- }
+ result = dbus_g_proxy_call (proxy, "ClassAddPrinter", &error,
+ G_TYPE_STRING, class_name,
+ G_TYPE_STRING, printer_name,
+ G_TYPE_INVALID,
+ G_TYPE_STRING, &ret_error,
+ G_TYPE_INVALID);
+
+ if (!result)
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
}
+ if (ret_error && ret_error[0] != '\0')
+ {
+ g_warning ("%s", ret_error);
+ result = FALSE;
+ }
+
+ g_object_unref (proxy);
+
return result;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]