printers: Remove nesting on a GVariant iteration

This commit is contained in:
Robert Ancell 2019-11-21 22:26:59 +13:00 committed by Robert Ancell
parent 02d001564a
commit fe91d17b43

View file

@ -466,7 +466,7 @@ printer_add_real_async (PpNewPrinter *self)
static PPDName * static PPDName *
get_ppd_item_from_output (GVariant *output) get_ppd_item_from_output (GVariant *output)
{ {
PPDName *ppd_item = NULL; g_autoptr(GVariant) array = NULL;
gint j; gint j;
static const char * const match_levels[] = { static const char * const match_levels[] = {
"exact-cmd", "exact-cmd",
@ -475,40 +475,42 @@ get_ppd_item_from_output (GVariant *output)
"generic", "generic",
"none"}; "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); g_variant_get (array, "a(ss)", &iter);
for (j = 0; j < G_N_ELEMENTS (match_levels) && !ppd_item; j++) while (g_variant_iter_next (iter, "(&s&s)", &driver, &match))
{ {
g_autoptr(GVariantIter) iter = NULL; PPDName *ppd_item;
const gchar *driver, *match;
g_variant_get (array, "a(ss)", &iter); if (!g_str_equal (match, match_levels[j]))
while (g_variant_iter_next (iter, "(&s&s)", &driver, &match) && !ppd_item) continue;
{
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 = g_new0 (PPDName, 1);
ppd_item->ppd_match_level = PPD_EXACT_CMD_MATCH; ppd_item->ppd_name = g_strdup (driver);
else if (g_strcmp0 (match, "exact") == 0)
ppd_item->ppd_match_level = PPD_EXACT_MATCH; if (g_strcmp0 (match, "exact-cmd") == 0)
else if (g_strcmp0 (match, "close") == 0) ppd_item->ppd_match_level = PPD_EXACT_CMD_MATCH;
ppd_item->ppd_match_level = PPD_CLOSE_MATCH; else if (g_strcmp0 (match, "exact") == 0)
else if (g_strcmp0 (match, "generic") == 0) ppd_item->ppd_match_level = PPD_EXACT_MATCH;
ppd_item->ppd_match_level = PPD_GENERIC_MATCH; else if (g_strcmp0 (match, "close") == 0)
else if (g_strcmp0 (match, "none") == 0) ppd_item->ppd_match_level = PPD_CLOSE_MATCH;
ppd_item->ppd_match_level = PPD_NO_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;
} }