[gnome-control-center] printers: Remove nesting on a GVariant iteration
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] printers: Remove nesting on a GVariant iteration
- Date: Mon, 30 Mar 2020 03:29:13 +0000 (UTC)
commit fe91d17b43368caf0ee54a8e7cdbab06045423fa
Author: Robert Ancell <robert ancell canonical com>
Date: Thu Nov 21 22:26:59 2019 +1300
printers: Remove nesting on a GVariant iteration
panels/printers/pp-new-printer.c | 60 +++++++++++++++++++++-------------------
1 file changed, 31 insertions(+), 29 deletions(-)
---
diff --git a/panels/printers/pp-new-printer.c b/panels/printers/pp-new-printer.c
index a44c6bf1b..1c325b46e 100644
--- a/panels/printers/pp-new-printer.c
+++ b/panels/printers/pp-new-printer.c
@@ -466,7 +466,7 @@ printer_add_real_async (PpNewPrinter *self)
static PPDName *
get_ppd_item_from_output (GVariant *output)
{
- PPDName *ppd_item = NULL;
+ g_autoptr(GVariant) array = NULL;
gint j;
static const char * const match_levels[] = {
"exact-cmd",
@@ -475,40 +475,42 @@ get_ppd_item_from_output (GVariant *output)
"generic",
"none"};
- if (output)
+ if (output == NULL)
+ return NULL;
+
+ g_variant_get (output, "(@a(ss))", &array);
+ for (j = 0; j < G_N_ELEMENTS (match_levels); j++)
{
- g_autoptr(GVariant) array = NULL;
+ g_autoptr(GVariantIter) iter = NULL;
+ const gchar *driver, *match;
- g_variant_get (output, "(@a(ss))", &array);
- for (j = 0; j < G_N_ELEMENTS (match_levels) && !ppd_item; j++)
+ g_variant_get (array, "a(ss)", &iter);
+ while (g_variant_iter_next (iter, "(&s&s)", &driver, &match))
{
- g_autoptr(GVariantIter) iter = NULL;
- const gchar *driver, *match;
-
- g_variant_get (array, "a(ss)", &iter);
- while (g_variant_iter_next (iter, "(&s&s)", &driver, &match) && !ppd_item)
- {
- if (g_str_equal (match, match_levels[j]))
- {
- ppd_item = g_new0 (PPDName, 1);
- ppd_item->ppd_name = g_strdup (driver);
-
- if (g_strcmp0 (match, "exact-cmd") == 0)
- ppd_item->ppd_match_level = PPD_EXACT_CMD_MATCH;
- else if (g_strcmp0 (match, "exact") == 0)
- ppd_item->ppd_match_level = PPD_EXACT_MATCH;
- else if (g_strcmp0 (match, "close") == 0)
- ppd_item->ppd_match_level = PPD_CLOSE_MATCH;
- else if (g_strcmp0 (match, "generic") == 0)
- ppd_item->ppd_match_level = PPD_GENERIC_MATCH;
- else if (g_strcmp0 (match, "none") == 0)
- ppd_item->ppd_match_level = PPD_NO_MATCH;
- }
- }
+ PPDName *ppd_item;
+
+ if (!g_str_equal (match, match_levels[j]))
+ continue;
+
+ ppd_item = g_new0 (PPDName, 1);
+ ppd_item->ppd_name = g_strdup (driver);
+
+ if (g_strcmp0 (match, "exact-cmd") == 0)
+ ppd_item->ppd_match_level = PPD_EXACT_CMD_MATCH;
+ else if (g_strcmp0 (match, "exact") == 0)
+ ppd_item->ppd_match_level = PPD_EXACT_MATCH;
+ else if (g_strcmp0 (match, "close") == 0)
+ ppd_item->ppd_match_level = PPD_CLOSE_MATCH;
+ else if (g_strcmp0 (match, "generic") == 0)
+ ppd_item->ppd_match_level = PPD_GENERIC_MATCH;
+ else if (g_strcmp0 (match, "none") == 0)
+ ppd_item->ppd_match_level = PPD_NO_MATCH;
+
+ return ppd_item;
}
}
- return ppd_item;
+ return NULL;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]