[gnome-control-center] printers: Remove redundant functions



commit a0ad46365fa96b7159ab16dede4b5e39b1346750
Author: Marek Kasik <mkasik redhat com>
Date:   Mon Sep 3 21:35:21 2012 +0200

    printers: Remove redundant functions
    
    Remove functions which are not used anymore. (#683229)

 panels/printers/pp-utils.c | 1216 --------------------------------------------
 panels/printers/pp-utils.h |   11 -
 2 files changed, 0 insertions(+), 1227 deletions(-)
---
diff --git a/panels/printers/pp-utils.c b/panels/printers/pp-utils.c
index e8638aa..df53b0b 100644
--- a/panels/printers/pp-utils.c
+++ b/panels/printers/pp-utils.c
@@ -100,80 +100,6 @@ get_tag_value (const gchar *tag_string, const gchar *tag_name)
 }
 
 
-typedef struct
-{
-  gchar *ppd_name;
-  gchar *ppd_device_id;
-  gchar *ppd_product;
-  gchar *ppd_make_and_model;
-
-  gchar *driver_type;
-
-  gchar *mfg;
-  gchar *mdl;
-  gint   match_level;
-  gint   preference_value;
-} PPDItem;
-
-
-static void
-ppd_item_free (PPDItem *item)
-{
-  if (item)
-    {
-      g_free (item->ppd_name);
-      g_free (item->ppd_device_id);
-      g_free (item->ppd_product);
-      g_free (item->ppd_make_and_model);
-      g_free (item->driver_type);
-      g_free (item->mfg);
-      g_free (item->mdl);
-    }
-}
-
-static PPDItem *
-ppd_item_copy (PPDItem *item)
-{
-  PPDItem *result = NULL;
-
-  result = g_new0 (PPDItem, 1);
-  if (item && result)
-    {
-      result->ppd_name = g_strdup (item->ppd_name);
-      result->ppd_device_id = g_strdup (item->ppd_device_id);
-      result->ppd_product = g_strdup (item->ppd_product);
-      result->ppd_make_and_model = g_strdup (item->ppd_make_and_model);
-      result->driver_type = g_strdup (item->driver_type);
-      result->mfg = g_strdup (item->mfg);
-      result->mdl = g_strdup (item->mdl);
-      result->match_level = item->match_level;
-      result->preference_value = item->preference_value;
-    }
-
-  return result;
-}
-
-
-/*
- * Make deep copy of given const string array.
- */
-static gchar **
-strvdup (const gchar * const x[])
-{
-  gint i, length = 0;
-  gchar **result;
-
-  for (length = 0; x && x[length]; length++);
-
-  length++;
-
-  result = g_new0 (gchar *, length);
-  for (i = 0; i < length; i++)
-    result[i] = g_strdup (x[i]);
-
-  return result;
-}
-
 /*
  * Normalize given string so that it is lowercase, doesn't
  * have trailing or leading whitespaces and digits doesn't
@@ -235,1009 +161,6 @@ normalize (const gchar *input_string)
 }
 
 
-/*
- * Find out type of the given printer driver.
- * (see xml/preferreddrivers.xml from system-config-printer)
- */
-static gchar *
-get_driver_type (gchar *ppd_name,
-                 gchar *ppd_device_id,
-                 gchar *ppd_make_and_model,
-                 gchar *ppd_product,
-                 gint   match_level)
-{
-  gchar *tmp = NULL;
-
-  if (match_level == PPD_GENERIC_MATCH)
-    {
-      if (ppd_name && g_regex_match_simple ("(foomatic(-db-compressed-ppds)?|ijsgutenprint.*):", ppd_name, 0, 0))
-        {
-          tmp = get_tag_value ("DRV", ppd_device_id);
-          if (tmp && g_regex_match_simple (".*,?R1", tmp, 0, 0))
-            return g_strdup ("generic-foomatic-recommended");
-        }
-    }
-
-  if (match_level == PPD_GENERIC_MATCH || match_level == PPD_NO_MATCH)
-    {
-      if (ppd_name && g_regex_match_simple ("(foomatic(-db-compressed-ppds)?|ijsgutenprint.*):Generic-ESC_P", ppd_name, 0, 0))
-        return g_strdup ("generic-escp");
-
-      if (ppd_name && g_regex_match_simple ("drv:///sample.drv/epson(9|24).ppd", ppd_name, 0, 0))
-        return g_strdup ("generic-escp");
-
-      if (g_strcmp0 (ppd_make_and_model, "Generic PostScript Printer") == 0)
-        return g_strdup ("generic-postscript");
-
-      if (g_strcmp0 (ppd_make_and_model, "Generic PCL 6 Printer") == 0)
-        return g_strdup ("generic-pcl6");
-
-      if (g_strcmp0 (ppd_make_and_model, "Generic PCL 5e Printer") == 0)
-        return g_strdup ("generic-pcl5e");
-
-      if (g_strcmp0 (ppd_make_and_model, "Generic PCL 5 Printer") == 0)
-        return g_strdup ("generic-pcl5");
-
-      if (g_strcmp0 (ppd_make_and_model, "Generic PCL Laser Printer") == 0)
-        return g_strdup ("generic-pcl");
-
-      return g_strdup ("generic");
-    }
-
-
-  if (ppd_name && g_regex_match_simple ("drv:///sample.drv/", ppd_name, 0, 0))
-    return g_strdup ("cups");
-
-  if (ppd_product && g_regex_match_simple (".*Ghostscript", ppd_product, 0, 0))
-    return g_strdup ("ghostscript");
-
-  if (ppd_name && g_regex_match_simple ("gutenprint.*:.*/simple|.*-gutenprint.*\\.sim", ppd_name, 0, 0))
-    return g_strdup ("gutenprint-simplified");
-
-  if (ppd_name && g_regex_match_simple ("gutenprint.*:|.*-gutenprint", ppd_name, 0, 0))
-    return g_strdup ("gutenprint-expert");
-
-  if (ppd_make_and_model && g_regex_match_simple (".* Foomatic/hpijs", ppd_make_and_model, 0, 0))
-    {
-      tmp = get_tag_value ("DRV", ppd_device_id);
-      if (tmp && g_regex_match_simple (",?R1", tmp, 0, 0))
-        return g_strdup ("foomatic-recommended-hpijs");
-    }
-
-  if (ppd_make_and_model && g_regex_match_simple (".* Foomatic/hpijs", ppd_make_and_model, 0, 0))
-    return g_strdup ("foomatic-hpijs");
-
-  if (ppd_name && g_regex_match_simple ("foomatic(-db-compressed-ppds)?:", ppd_name, 0, 0) &&
-      ppd_make_and_model && g_regex_match_simple (".* Postscript", ppd_make_and_model, 0, 0))
-    {
-      tmp = get_tag_value ("DRV", ppd_device_id);
-      if (tmp && g_regex_match_simple (".*,?R1", tmp, 0, 0))
-        return g_strdup ("foomatic-recommended-postscript");
-    }
-
-  if (ppd_name && g_regex_match_simple ("foomatic(-db-compressed-ppds)?:.*-Postscript", ppd_name, 0, 0))
-    return g_strdup ("foomatic-postscript");
-
-  if (ppd_make_and_model && g_regex_match_simple (".* Foomatic/pxlmono", ppd_make_and_model, 0, 0))
-    return g_strdup ("foomatic-pxlmono");
-
-  if (ppd_name && g_regex_match_simple ("(foomatic(-db-compressed-ppds)?|ijsgutenprint.*):", ppd_name, 0, 0))
-    {
-      tmp = get_tag_value ("DRV", ppd_device_id);
-      if (tmp && g_regex_match_simple (".*,?R1", tmp, 0, 0))
-        return g_strdup ("foomatic-recommended-non-postscript");
-    }
-
-  if (ppd_name && g_regex_match_simple ("(foomatic(-db-compressed-ppds)?|ijsgutenprint.*):.*-gutenprint", ppd_name, 0, 0))
-    return g_strdup ("foomatic-gutenprint");
-
-  if (ppd_name && g_regex_match_simple ("(foomatic(-db-compressed-ppds)?|ijsgutenprint.*):", ppd_name, 0, 0))
-    return g_strdup ("foomatic");
-
-  if (ppd_name && g_regex_match_simple ("drv:///(hp/)?hpcups.drv/|.*-hpcups", ppd_name, 0, 0) &&
-      ppd_make_and_model && g_regex_match_simple (".* plugin", ppd_make_and_model, 0, 0))
-    return g_strdup ("hpcups-plugin");
-
-  if (ppd_name && g_regex_match_simple ("drv:///(hp/)?hpcups.drv/|.*-hpcups", ppd_name, 0, 0))
-    return g_strdup ("hpcups");
-
-  if (ppd_name && g_regex_match_simple ("drv:///(hp/)?hpijs.drv/|.*-hpijs", ppd_name, 0, 0) &&
-      ppd_make_and_model && g_regex_match_simple (".* plugin", ppd_make_and_model, 0, 0))
-    return g_strdup ("hpijs-plugin");
-
-  if (ppd_name && g_regex_match_simple ("drv:///(hp/)?hpijs.drv/|.*-hpijs", ppd_name, 0, 0))
-    return g_strdup ("hpijs");
-
-  if (ppd_name && g_regex_match_simple (".*splix", ppd_name, 0, 0))
-    return g_strdup ("splix");
-
-  if (ppd_name && g_regex_match_simple (".*turboprint", ppd_name, 0, 0))
-    return g_strdup ("turboprint");
-
-  if (ppd_name && g_regex_match_simple (".*/(Ricoh|Lanier|Gestetner|InfoPrint|Infotech|Savin|NRG)/PS/", ppd_name, 0, 0))
-    return g_strdup ("manufacturer-ricoh-postscript");
-
-  if (ppd_name && g_regex_match_simple (".*/(Ricoh|Lanier|Gestetner|InfoPrint|Infotech|Savin|NRG)/PXL/", ppd_name, 0, 0))
-    return g_strdup ("manufacturer-ricoh-pxl");
-
-  if (match_level == PPD_EXACT_CMD_MATCH)
-    return g_strdup ("manufacturer-cmd");
-
-  return g_strdup ("manufacturer");
-}
-
-
-/*
- * Return preference value. The most preferred driver has the lowest value.
- * If the value is higher or equal to 1000 then try to avoid installation
- * of this driver. If it is higher or equal to 2000 then don't install
- * this driver.
- * (see xml/preferreddrivers.xml from system-config-printer)
- */
-static gint
-get_driver_preference (PPDItem *item)
-{
-  gchar   *tmp1 = NULL;
-  gchar   *tmp2 = NULL;
-  gint     result = 0;
-
-  if (item && item->ppd_make_and_model &&
-      g_regex_match_simple ("Brother HL-2030", item->ppd_make_and_model, 0, 0))
-    {
-      tmp1 = get_tag_value ("MFG", item->ppd_device_id);
-      tmp2 = get_tag_value ("MDL", item->ppd_device_id);
-
-      if (tmp1 && g_regex_match_simple ("Brother", tmp1, 0, 0) &&
-          tmp2 && g_regex_match_simple ("HL-2030", tmp2, 0, 0))
-        {
-          if (item->driver_type && g_regex_match_simple ("gutenprint*", item->driver_type, 0, 0))
-            return result + 2000;
-          else
-            return result;
-        }
-    }
-  result++;
-
-  if (item && item->ppd_make_and_model &&
-      g_regex_match_simple ("(Ricoh|Lanier|Gestetner|InfoPrint|Infotech|Savin|NRG) ", item->ppd_make_and_model, 0, 0))
-    {
-      tmp1 = get_tag_value ("MFG", item->ppd_device_id);
-
-      if (tmp1 && g_regex_match_simple ("(Ricoh|Lanier|Gestetner|InfoPrint|Infotech|Savin|NRG)", tmp1, 0, 0) &&
-          ((g_strcmp0 (item->driver_type, "manufacturer-ricoh-postscript") == 0) ||
-           (g_strcmp0 (item->driver_type, "manufacturer-ricoh-pxl") == 0)))
-        return result;
-    }
-  result++;
-
-  if (item && item->ppd_make_and_model &&
-      g_regex_match_simple ("Xerox 6250DP", item->ppd_make_and_model, 0, 0))
-    {
-      tmp1 = get_tag_value ("MFG", item->ppd_device_id);
-      tmp2 = get_tag_value ("MDL", item->ppd_device_id);
-
-      if (tmp1 && g_regex_match_simple ("Xerox", tmp1, 0, 0) &&
-          tmp2 && g_regex_match_simple ("6250DP", tmp2, 0, 0))
-        {
-          if (item->driver_type && g_regex_match_simple ("gutenprint*", item->driver_type, 0, 0))
-            return result + 1000;
-          else
-            return result;
-        }
-    }
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "manufacturer-cmd") == 0)
-    return result;
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "foomatic-recommended-hpijs") == 0)
-    return result;
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "foomatic-recommended-non-postscript") == 0)
-    return result;
-  result++;
-
-  if (item && item->driver_type &&
-      g_regex_match_simple ("manufacturer*", item->driver_type, 0, 0))
-    return result;
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "foomatic-recommended-postscript") == 0)
-    return result;
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "foomatic-postscript") == 0)
-    return result;
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "hpcups") == 0)
-    return result;
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "hpijs") == 0)
-    return result;
-  result++;
-
-  if (item && item->ppd_make_and_model &&
-      g_regex_match_simple ("(HP|Hewlett-Packard) ", item->ppd_make_and_model, 0, 0))
-    {
-      tmp1 = get_tag_value ("MFG", item->ppd_device_id);
-
-      if (tmp1 && g_regex_match_simple ("HP|Hewlett-Packard", tmp1, 0, 0) &&
-          g_strcmp0 (item->driver_type, "foomatic-hpijs") == 0)
-        return result;
-    }
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "gutenprint-simplified") == 0)
-    return result;
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "gutenprint-expert") == 0)
-    return result;
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "foomatic-hpijs") == 0)
-    return result;
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "foomatic-gutenprint") == 0)
-    return result;
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "foomatic") == 0)
-    return result;
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "cups") == 0)
-    return result;
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "generic-postscript") == 0)
-    return result;
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "generic-foomatic-recommended") == 0)
-    return result;
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "generic-pcl6") == 0)
-    return result;
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "generic-pcl5c") == 0)
-    return result;
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "generic-pcl5e") == 0)
-    return result;
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "generic-pcl5") == 0)
-    return result;
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "generic-pcl") == 0)
-    return result;
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "foomatic-pxlmono") == 0)
-    return result;
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "generic-escp") == 0)
-    return result;
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "ghostscript") == 0)
-    return result;
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "generic") == 0)
-    return result;
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "hpcups-plugin") == 0)
-    return result;
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "hpijs-plugin") == 0)
-    return result;
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "splix") == 0)
-    return result;
-  result++;
-
-  if (item && g_strcmp0 (item->driver_type, "turboprint") == 0)
-    return result;
-  result++;
-
-  return result;
-}
-
-
-/*
- * Compare driver types according to preference order.
- * The most preferred driver is the lowest one.
- * (see xml/preferreddrivers.xml from system-config-printer)
- */
-static gint
-preference_value_cmp (gconstpointer a,
-                      gconstpointer b)
-{
-  PPDItem *c = (PPDItem *) a;
-  PPDItem *d = (PPDItem *) b;
-
-  if (c == NULL && d == NULL)
-    return 0;
-  else if (c == NULL)
-    return -1;
-  else if (d == NULL)
-    return 1;
-
-  if (c->preference_value < d->preference_value)
-    return -1;
-  else if (c->preference_value > d->preference_value)
-    return 1;
-  else
-    return 0;
-}
-
-
-/* Compare PPDItems a and b according to normalized model name */
-static gint
-item_cmp (gconstpointer a,
-          gconstpointer b)
-{
-  PPDItem *c = (PPDItem *) a;
-  PPDItem *d = (PPDItem *) b;
-  glong   a_number;
-  glong   b_number;
-  gchar  *a_normalized = NULL;
-  gchar  *b_normalized = NULL;
-  gchar **av = NULL;
-  gchar **bv = NULL;
-  gint    a_length = 0;
-  gint    b_length = 0;
-  gint    min_length;
-  gint    result = 0;
-  gint    i;
-
-  if (c && d)
-    {
-      a_normalized = normalize (c->mdl);
-      b_normalized = normalize (d->mdl);
-
-      if (a_normalized)
-        av = g_strsplit (a_normalized, " ", 0);
-
-      if (b_normalized)
-        bv = g_strsplit (b_normalized, " ", 0);
-
-      if (av)
-        a_length = g_strv_length (av);
-
-      if (bv)
-        b_length = g_strv_length (bv);
-
-      min_length = a_length < b_length ? a_length : b_length;
-
-      for (i = 0; i < min_length; i++)
-        {
-          if (g_ascii_isdigit (av[i][0]) && g_ascii_isdigit (bv[i][0]))
-            {
-              a_number = atol (av[i]);
-              b_number = atol (bv[i]);
-              if (a_number < b_number)
-                {
-                  result = -1;
-                  goto out;
-                }
-              else if (a_number > b_number)
-                {
-                  result = 1;
-                  goto out;
-                }
-            }
-          else if (g_ascii_isdigit (av[i][0]) && !g_ascii_isdigit (bv[i][0]))
-            {
-              result = -1;
-              goto out;
-            }
-          else if (!g_ascii_isdigit (av[i][0]) && g_ascii_isdigit (bv[i][0]))
-            {
-              result = 1;
-              goto out;
-            }
-          else
-            {
-              if (g_strcmp0 (av[i], bv[i]) != 0)
-                {
-                  result = g_strcmp0 (av[i], bv[i]);
-                  goto out;
-                }
-            }
-        }
-
-      if (a_length < b_length)
-        result = -1;
-      else if (a_length > b_length)
-        result = 1;
-    }
-
-out:
-  if (av)
-    g_strfreev (av);
-
-  if (bv)
-    g_strfreev (bv);
-
-  g_free (a_normalized);
-  g_free (b_normalized);
-
-  return result;
-}
-
-
-static gint
-get_prefix_length (gchar *a, gchar *b)
-{
-  gint a_length;
-  gint b_length;
-  gint min_length;
-  gint i;
-
-  if (a && b)
-    {
-      a_length = strlen (a);
-      b_length = strlen (b);
-      min_length = a_length < b_length ? a_length : b_length;
-
-      for (i = 0; i < min_length; i++)
-        {
-          if (a[i] != b[i])
-            return i;
-        }
-      return min_length;
-    }
-
-  return 0;
-}
-
-
-/*
- * Append best matching ppds from list "ppds" to list "list"
- * according to model name "model". Return the resulting list.
- */
-static GList *
-append_best_ppds (GList *list,
-                  GList *ppds,
-                  gchar *model)
-{
-  PPDItem *item;
-  PPDItem *tmp_item;
-  PPDItem *best_item = NULL;
-  gchar   *mdl_normalized;
-  gchar   *mdl;
-  gchar   *tmp;
-  GList   *local_ppds;
-  GList   *actual_item;
-  GList   *candidates = NULL;
-  GList   *tmp_list = NULL;
-  GList   *result = NULL;
-  gint     best_prefix_length = -1;
-  gint     prefix_length;
-
-  result = list;
-
-  if (model)
-    {
-      mdl = g_ascii_strdown (model, -1);
-      if (g_str_has_suffix (mdl, " series"))
-        {
-          tmp = g_strndup (mdl, strlen (mdl) - 7);
-          g_free (mdl);
-          mdl = tmp;
-        }
-
-      mdl_normalized = normalize (mdl);
-
-      item = g_new0 (PPDItem, 1);
-      item->ppd_device_id = g_strdup_printf ("mdl:%s;", mdl);
-      item->mdl = mdl_normalized;
-
-      local_ppds = g_list_copy (ppds);
-      local_ppds = g_list_append (local_ppds, item);
-      local_ppds = g_list_sort (local_ppds, item_cmp);
-
-      actual_item = g_list_find (local_ppds, item);
-      if (actual_item)
-        {
-          if (actual_item->prev)
-            candidates = g_list_append (candidates, actual_item->prev->data);
-          if (actual_item->next)
-            candidates = g_list_append (candidates, actual_item->next->data);
-        }
-
-      for (tmp_list = candidates; tmp_list; tmp_list = tmp_list->next)
-        {
-          tmp_item = (PPDItem *) tmp_list->data;
-
-          prefix_length = get_prefix_length (tmp_item->mdl, mdl_normalized);
-          if (prefix_length > best_prefix_length)
-            {
-              best_prefix_length = prefix_length;
-              best_item = tmp_item;
-            }
-        }
-
-      if (best_item && best_prefix_length > strlen (mdl_normalized) / 2)
-        {
-          if (best_prefix_length == strlen (mdl_normalized))
-            best_item->match_level = PPD_EXACT_MATCH;
-          else
-            best_item->match_level = PPD_CLOSE_MATCH;
-
-          result = g_list_append (result, ppd_item_copy (best_item));
-        }
-      else
-        {
-          /* TODO the last resort (see _findBestMatchPPDs() in ppds.py) */
-        }
-
-      g_list_free (candidates);
-      g_list_free (local_ppds);
-
-      g_free (item->ppd_device_id);
-      g_free (item);
-      g_free (mdl);
-      g_free (mdl_normalized);
-    }
-
-  return result;
-}
-
-/*
- * Return the best matching driver name
- * for device described by given parameters.
- */
-PPDName *
-get_ppd_name (gchar *device_id,
-              gchar *device_make_and_model,
-              gchar *device_uri)
-{
-  GDBusConnection *bus;
-  GVariant   *output;
-  GVariant   *array;
-  GVariant   *tuple;
-  PPDName    *result = NULL;
-  GError     *error = NULL;
-  gchar      *name, *match;
-  gint        i, j;
-  static const char * const match_levels[] = {
-             "exact-cmd",
-             "exact",
-             "close",
-             "generic",
-             "none"};
-
-  bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
-  if (bus)
-    {
-      output = g_dbus_connection_call_sync (bus,
-                                            SCP_BUS,
-                                            SCP_PATH,
-                                            SCP_IFACE,
-                                            "GetBestDrivers",
-                                            g_variant_new ("(sss)",
-                                                           device_id ? device_id : "",
-                                                           device_make_and_model ? device_make_and_model : "",
-                                                           device_uri ? device_uri : ""),
-                                            NULL,
-                                            G_DBUS_CALL_FLAGS_NONE,
-                                            60000,
-                                            NULL,
-                                            &error);
-
-      if (output && g_variant_n_children (output) >= 1)
-        {
-          array = g_variant_get_child_value (output, 0);
-          if (array)
-            for (j = 0; j < G_N_ELEMENTS (match_levels) && result == NULL; j++)
-              for (i = 0; i < g_variant_n_children (array) && result == NULL; i++)
-                {
-                  tuple = g_variant_get_child_value (array, i);
-                  if (tuple && g_variant_n_children (tuple) == 2)
-                    {
-                      name = g_strdup (g_variant_get_string (
-                                         g_variant_get_child_value (tuple, 0),
-                                         NULL));
-                      match = g_strdup (g_variant_get_string (
-                                          g_variant_get_child_value (tuple, 1),
-                                          NULL));
-
-                      if (g_strcmp0 (match, match_levels[j]) == 0)
-                        {
-                          result = g_new0 (PPDName, 1);
-                          result->ppd_name = g_strdup (name);
-
-                          if (g_strcmp0 (match, "exact-cmd") == 0)
-                            result->ppd_match_level = PPD_EXACT_CMD_MATCH;
-                          else if (g_strcmp0 (match, "exact") == 0)
-                            result->ppd_match_level = PPD_EXACT_MATCH;
-                          else if (g_strcmp0 (match, "close") == 0)
-                            result->ppd_match_level = PPD_CLOSE_MATCH;
-                          else if (g_strcmp0 (match, "generic") == 0)
-                            result->ppd_match_level = PPD_GENERIC_MATCH;
-                          else if (g_strcmp0 (match, "none") == 0)
-                            result->ppd_match_level = PPD_NO_MATCH;
-                        }
-
-                      g_free (match);
-                      g_free (name);
-                    }
-                }
-        }
-
-      if (output)
-        g_variant_unref (output);
-      g_object_unref (bus);
-    }
-
-  if (bus == NULL ||
-      (error &&
-       error->domain == G_DBUS_ERROR &&
-       (error->code == G_DBUS_ERROR_SERVICE_UNKNOWN ||
-        error->code == G_DBUS_ERROR_UNKNOWN_METHOD)))
-    {
-      ipp_attribute_t *attr = NULL;
-      const gchar     *hp_equivalents[] = {"hp", "hewlett packard", NULL};
-      const gchar     *kyocera_equivalents[] = {"kyocera", "kyocera mita", NULL};
-      const gchar     *toshiba_equivalents[] = {"toshiba", "toshiba tec corp.", NULL};
-      const gchar     *lexmark_equivalents[] = {"lexmark", "lexmark international", NULL};
-      gboolean         ppd_exact_match_found = FALSE;
-      PPDItem         *item;
-      http_t          *http = NULL;
-      ipp_t           *request = NULL;
-      ipp_t           *response = NULL;
-      GList           *tmp_list;
-      GList           *tmp_list2;
-      GList           *mdls = NULL;
-      GList           *list = NULL;
-      gchar           *mfg_normalized = NULL;
-      gchar           *mdl_normalized = NULL;
-      gchar           *eq_normalized = NULL;
-      gchar           *mfg = NULL;
-      gchar           *mdl = NULL;
-      gchar           *tmp = NULL;
-      const gchar     *ppd_device_id;
-      const gchar     *ppd_make_and_model;
-      const gchar     *ppd_name;
-      const gchar     *ppd_product;
-      gchar          **equivalents = NULL;
-      gint             i;
-
-      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)
-        mfg = get_tag_value (device_id, "manufacturer");
-
-      mdl = get_tag_value (device_id, "mdl");
-      if (!mdl)
-        mdl = get_tag_value (device_id, "model");
-
-      mfg_normalized = normalize (mfg);
-      mdl_normalized = normalize (mdl);
-
-      if (mfg_normalized && mfg)
-        {
-          if (g_str_has_prefix (mfg_normalized, "hewlett") ||
-              g_str_has_prefix (mfg_normalized, "hp"))
-            equivalents = strvdup (hp_equivalents);
-
-          if (g_str_has_prefix (mfg_normalized, "kyocera"))
-            equivalents = strvdup (kyocera_equivalents);
-
-          if (g_str_has_prefix (mfg_normalized, "toshiba"))
-            equivalents = strvdup (toshiba_equivalents);
-
-          if (g_str_has_prefix (mfg_normalized, "lexmark"))
-            equivalents = strvdup (lexmark_equivalents);
-
-          if (equivalents == NULL)
-            {
-              equivalents = g_new0 (gchar *, 2);
-              equivalents[0] = g_strdup (mfg);
-            }
-        }
-
-      http = httpConnectEncrypt (cupsServer (),
-                                 ippPort (),
-                                 cupsEncryption ());
-
-      /* Find usable drivers for given device */
-      if (http)
-        {
-          /* Try exact match according to device-id */
-          if (device_id)
-            {
-              request = ippNewRequest (CUPS_GET_PPDS);
-              ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_TEXT,
-                            "ppd-device-id", NULL, device_id);
-              response = cupsDoRequest (http, request, "/");
-
-              if (response &&
-                  ippGetStatusCode (response) <= IPP_OK_CONFLICT)
-                {
-                  for (attr = ippFirstAttribute (response); attr != NULL; attr = ippNextAttribute (response))
-                    {
-                      while (attr != NULL && ippGetGroupTag (attr) != IPP_TAG_PRINTER)
-                        attr = ippNextAttribute (response);
-
-                      if (attr == NULL)
-                        break;
-
-                      ppd_device_id = NULL;
-                      ppd_make_and_model = NULL;
-                      ppd_name = NULL;
-                      ppd_product = NULL;
-
-                      while (attr != NULL && ippGetGroupTag (attr) == IPP_TAG_PRINTER)
-                        {
-                          if (g_strcmp0 (ippGetName (attr), "ppd-device-id") == 0 &&
-                              ippGetValueTag (attr) == IPP_TAG_TEXT)
-                            ppd_device_id = (gchar *) ippGetString (attr, 0, NULL);
-                          else if (g_strcmp0 (ippGetName (attr), "ppd-make-and-model") == 0 &&
-                                   ippGetValueTag (attr) == IPP_TAG_TEXT)
-                            ppd_make_and_model = ippGetString (attr, 0, NULL);
-                          else if (g_strcmp0 (ippGetName (attr), "ppd-name") == 0 &&
-                                   ippGetValueTag (attr) == IPP_TAG_NAME)
-                            ppd_name = ippGetString (attr, 0, NULL);
-                          else if (g_strcmp0 (ippGetName (attr), "ppd-product") == 0 &&
-                                   ippGetValueTag (attr) == IPP_TAG_TEXT)
-                            ppd_product = ippGetString (attr, 0, NULL);
-
-                          attr = ippNextAttribute (response);
-                        }
-
-                      if (ppd_device_id && ppd_name)
-                        {
-                          item = g_new0 (PPDItem, 1);
-                          item->ppd_name = g_strdup (ppd_name);
-                          item->ppd_device_id = g_strdup (ppd_device_id);
-                          item->ppd_make_and_model = g_strdup (ppd_make_and_model);
-                          item->ppd_product = g_strdup (ppd_product);
-
-                          tmp = get_tag_value (ppd_device_id, "mfg");
-                          if (!tmp)
-                            tmp = get_tag_value (ppd_device_id, "manufacturer");
-                          item->mfg = normalize (tmp);
-                          g_free (tmp);
-
-                          tmp = get_tag_value (ppd_device_id, "mdl");
-                          if (!tmp)
-                            tmp = get_tag_value (ppd_device_id, "model");
-                          item->mdl = normalize (tmp);
-                          g_free (tmp);
-
-                          item->match_level = PPD_EXACT_CMD_MATCH;
-                          ppd_exact_match_found = TRUE;
-                          list = g_list_append (list, item);
-                        }
-
-                      if (attr == NULL)
-                        break;
-                    }
-                }
-
-              if (response)
-                ippDelete(response);
-            }
-
-          /* Try match according to manufacturer and model fields */
-          if (!ppd_exact_match_found && mfg_normalized && mdl_normalized)
-            {
-              request = ippNewRequest (CUPS_GET_PPDS);
-              response = cupsDoRequest (http, request, "/");
-
-              if (response &&
-                  ippGetStatusCode (response) <= IPP_OK_CONFLICT)
-                {
-                  for (i = 0; equivalents && equivalents[i]; i++)
-                    {
-                      eq_normalized = normalize (equivalents[i]);
-                      for (attr = ippFirstAttribute (response); attr != NULL; attr = ippNextAttribute (response))
-                        {
-                          while (attr != NULL && ippGetGroupTag (attr) != IPP_TAG_PRINTER)
-                            attr = ippNextAttribute (response);
-
-                          if (attr == NULL)
-                            break;
-
-                          ppd_device_id = NULL;
-                          ppd_make_and_model = NULL;
-                          ppd_name = NULL;
-                          ppd_product = NULL;
-
-                          while (attr != NULL && ippGetGroupTag (attr) == IPP_TAG_PRINTER)
-                            {
-                              if (g_strcmp0 (ippGetName (attr), "ppd-device-id") == 0 &&
-                                  ippGetValueTag (attr) == IPP_TAG_TEXT)
-                                ppd_device_id = ippGetString (attr, 0, NULL);
-                              else if (g_strcmp0 (ippGetName (attr), "ppd-make-and-model") == 0 &&
-                                       ippGetValueTag (attr) == IPP_TAG_TEXT)
-                                ppd_make_and_model = ippGetString (attr, 0, NULL);
-                              else if (g_strcmp0 (ippGetName (attr), "ppd-name") == 0 &&
-                                       ippGetValueTag (attr) == IPP_TAG_NAME)
-                                ppd_name = ippGetString (attr, 0, NULL);
-                              else if (g_strcmp0 (ippGetName (attr), "ppd-product") == 0 &&
-                                       ippGetValueTag (attr) == IPP_TAG_TEXT)
-                                ppd_product = ippGetString (attr, 0, NULL);
-
-                              attr = ippNextAttribute (response);
-                            }
-
-                          if (ppd_device_id && ppd_name)
-                            {
-                              item = g_new0 (PPDItem, 1);
-                              item->ppd_name = g_strdup (ppd_name);
-                              item->ppd_device_id = g_strdup (ppd_device_id);
-                              item->ppd_make_and_model = g_strdup (ppd_make_and_model);
-                              item->ppd_product = g_strdup (ppd_product);
-
-                              tmp = get_tag_value (ppd_device_id, "mfg");
-                              if (!tmp)
-                                tmp = get_tag_value (ppd_device_id, "manufacturer");
-                              item->mfg = normalize (tmp);
-                              g_free (tmp);
-
-                              tmp = get_tag_value (ppd_device_id, "mdl");
-                              if (!tmp)
-                                tmp = get_tag_value (ppd_device_id, "model");
-                              item->mdl = normalize (tmp);
-                              g_free (tmp);
-
-                              if (item->mdl && item->mfg &&
-                                  g_ascii_strcasecmp (item->mdl, mdl_normalized) == 0 &&
-                                  g_ascii_strcasecmp (item->mfg, eq_normalized) == 0)
-                                {
-                                  item->match_level = PPD_EXACT_MATCH;
-                                  ppd_exact_match_found = TRUE;
-                                }
-
-                              if (item->match_level == PPD_EXACT_MATCH)
-                                list = g_list_append (list, item);
-                              else if (item->mfg &&
-                                       g_ascii_strcasecmp (item->mfg, eq_normalized) == 0)
-                                mdls = g_list_append (mdls, item);
-                              else
-                                {
-                                  ppd_item_free (item);
-                                  g_free (item);
-                                }
-                            }
-
-                          if (attr == NULL)
-                            break;
-                        }
-
-                      g_free (eq_normalized);
-                    }
-                }
-
-              if (response)
-                ippDelete(response);
-            }
-
-          httpClose (http);
-        }
-
-      if (list == NULL)
-        list = append_best_ppds (list, mdls, mdl);
-
-      /* Find out driver types for all listed drivers and set their preference values */
-      for (tmp_list = list; tmp_list; tmp_list = tmp_list->next)
-        {
-          item = (PPDItem *) tmp_list->data;
-          if (item)
-            {
-              item->driver_type = get_driver_type (item->ppd_name,
-                                                   item->ppd_device_id,
-                                                   item->ppd_make_and_model,
-                                                   item->ppd_product,
-                                                   item->match_level);
-              item->preference_value = get_driver_preference (item);
-            }
-        }
-
-      /* Sort driver list according to preference value */
-      list = g_list_sort (list, preference_value_cmp);
-
-      /* Split blacklisted drivers to tmp_list */
-      for (tmp_list = list; tmp_list; tmp_list = tmp_list->next)
-        {
-          item = (PPDItem *) tmp_list->data;
-          if (item && item->preference_value >= 2000)
-            break;
-        }
-
-      /* Free tmp_list */
-      if (tmp_list)
-        {
-          if (tmp_list->prev)
-            tmp_list->prev->next = NULL;
-          else
-            list = NULL;
-
-          tmp_list->prev = NULL;
-          for (tmp_list2 = tmp_list; tmp_list2; tmp_list2 = tmp_list2->next)
-            {
-              item = (PPDItem *) tmp_list2->data;
-              ppd_item_free (item);
-              g_free (item);
-            }
-
-          g_list_free (tmp_list);
-        }
-
-      /* Free driver list and set the best one */
-      if (list)
-        {
-          item = (PPDItem *) list->data;
-          if (item)
-            {
-              result = g_new0 (PPDName, 1);
-              result->ppd_name = g_strdup (item->ppd_name);
-              result->ppd_match_level = item->match_level;
-              switch (item->match_level)
-                {
-                  case PPD_GENERIC_MATCH:
-                  case PPD_CLOSE_MATCH:
-                    g_warning ("Found PPD does not match given device exactly!");
-                    break;
-                  default:
-                    break;
-                }
-            }
-
-          for (tmp_list = list; tmp_list; tmp_list = tmp_list->next)
-            {
-              item = (PPDItem *) tmp_list->data;
-              ppd_item_free (item);
-              g_free (item);
-            }
-
-          g_list_free (list);
-        }
-
-      if (mdls)
-        {
-          for (tmp_list = mdls; tmp_list; tmp_list = tmp_list->next)
-            {
-              item = (PPDItem *) tmp_list->data;
-              ppd_item_free (item);
-              g_free (item);
-            }
-          g_list_free (mdls);
-        }
-
-      g_free (mfg);
-      g_free (mdl);
-      g_free (mfg_normalized);
-      g_free (mdl_normalized);
-      if (equivalents)
-        g_strfreev (equivalents);
-    }
-
-  return result;
-}
-
 char *
 get_dest_attr (const char *dest_name,
                const char *attr)
@@ -1277,145 +200,6 @@ out:
   return ret;
 }
 
-ipp_t *
-execute_maintenance_command (const char *printer_name,
-                             const char *command,
-                             const char *title)
-{
-  http_t *http;
-  GError *error = NULL;
-  ipp_t  *request = NULL;
-  ipp_t  *response = NULL;
-  gchar  *file_name = NULL;
-  char   *uri;
-  int     fd = -1;
-
-  http = httpConnectEncrypt (cupsServer (),
-                             ippPort (),
-                             cupsEncryption ());
-
-  if (!http)
-    return NULL;
-
-  request = ippNewRequest (IPP_PRINT_JOB);
-
-  uri = g_strdup_printf ("ipp://localhost/printers/%s", printer_name);
-
-  ippAddString (request,
-                IPP_TAG_OPERATION,
-                IPP_TAG_URI,
-                "printer-uri",
-                NULL,
-                uri);
-
-  g_free (uri);
-
-  ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name",
-                NULL, title);
-
-  ippAddString (request, IPP_TAG_JOB, IPP_TAG_MIMETYPE, "document-format",
-                NULL, "application/vnd.cups-command");
-
-  fd = g_file_open_tmp ("ccXXXXXX", &file_name, &error);
-
-  if (fd != -1)
-    {
-      FILE *file;
-
-      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;
-}
-
-int
-ccGetAllowedUsers (gchar ***allowed_users, const char *printer_name)
-{
-  const char * const   attrs[1] = { "requesting-user-name-allowed" };
-  http_t              *http;
-  ipp_t               *request = NULL;
-  gchar              **users = NULL;
-  ipp_t               *response;
-  char                *uri;
-  int                  num_allowed_users = 0;
-
-  http = httpConnectEncrypt (cupsServer (),
-                             ippPort (),
-                             cupsEncryption ());
-
-  if (!http)
-    {
-      *allowed_users = NULL;
-      return 0;
-    }
-
-  request = ippNewRequest (IPP_GET_PRINTER_ATTRIBUTES);
-
-  uri = g_strdup_printf ("ipp://localhost/printers/%s", printer_name);
-
-  ippAddString (request,
-                IPP_TAG_OPERATION,
-                IPP_TAG_URI,
-                "printer-uri",
-                NULL,
-                uri);
-
-  g_free (uri);
-
-  ippAddStrings (request,
-                 IPP_TAG_OPERATION,
-                 IPP_TAG_KEYWORD,
-                 "requested-attributes",
-                 1,
-                 NULL,
-                 attrs);
-
-  response = cupsDoRequest (http, request, "/");
-  if (response)
-    {
-      ipp_attribute_t *attr = NULL;
-      ipp_attribute_t *allowed = NULL;
-
-      for (attr = ippFirstAttribute (response); attr != NULL; attr = ippNextAttribute (response))
-        {
-          if (ippGetGroupTag (attr) == IPP_TAG_PRINTER &&
-              ippGetValueTag (attr) == IPP_TAG_NAME &&
-              !g_strcmp0 (ippGetName (attr), "requesting-user-name-allowed"))
-            allowed = attr;
-        }
-
-      if (allowed && ippGetCount (allowed) > 0)
-        {
-          int i;
-
-          num_allowed_users = ippGetCount (allowed);
-          users = g_new (gchar*, num_allowed_users);
-
-          for (i = 0; i < num_allowed_users; i ++)
-            users[i] = g_strdup (ippGetString (allowed, i, NULL));
-        }
-      ippDelete(response);
-    }
-  httpClose (http);
-
-  *allowed_users = users;
-  return num_allowed_users;
-}
-
 gchar *
 get_ppd_attribute (const gchar *ppd_file_name,
                    const gchar *attribute_name)
diff --git a/panels/printers/pp-utils.h b/panels/printers/pp-utils.h
index f8b763d..6d18bfe 100644
--- a/panels/printers/pp-utils.h
+++ b/panels/printers/pp-utils.h
@@ -77,20 +77,9 @@ typedef struct
 gchar      *get_tag_value (const gchar *tag_string,
                            const gchar *tag_name);
 
-PPDName    *get_ppd_name (gchar *device_id,
-                          gchar *device_make_and_model,
-                          gchar *device_uri);
-
 char       *get_dest_attr (const char *dest_name,
                            const char *attr);
 
-ipp_t      *execute_maintenance_command (const char *printer_name,
-                                         const char *command,
-                                         const char *title);
-
-int         ccGetAllowedUsers (gchar      ***allowed_users,
-                               const char   *printer_name);
-
 gchar      *get_ppd_attribute (const gchar *ppd_file_name,
                                const gchar *attribute_name);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]