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 *
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,21 +475,23 @@ get_ppd_item_from_output (GVariant *output)
"generic",
"none"};
if (output)
{
g_autoptr(GVariant) array = NULL;
if (output == NULL)
return NULL;
g_variant_get (output, "(@a(ss))", &array);
for (j = 0; j < G_N_ELEMENTS (match_levels) && !ppd_item; j++)
for (j = 0; j < G_N_ELEMENTS (match_levels); j++)
{
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]))
while (g_variant_iter_next (iter, "(&s&s)", &driver, &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);
@ -503,12 +505,12 @@ get_ppd_item_from_output (GVariant *output)
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;
}