Example #1
0
/**
 * g_content_type_get_generic_icon_name:
 * @type: a content type string
 *
 * Gets the generic icon name for a content type.
 *
 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec">shared-mime-info</ulink>
 * specification for more on the generic icon name.
 *
 * Returns: (allow-none): the registered generic icon name for the given @type,
 *     or %NULL if unknown. Free with g_free()
 *
 * Since: 2.34
 */
gchar *
g_content_type_get_generic_icon_name (const gchar *type)
{
  const gchar *xdg_icon_name;
  gchar *icon_name;

  G_LOCK (gio_xdgmime);
  xdg_icon_name = xdg_mime_get_generic_icon (type);
  G_UNLOCK (gio_xdgmime);

  if (!xdg_icon_name)
    {
      const char *p;
      const char *suffix = "-x-generic";

      p = strchr (type, '/');
      if (p == NULL)
        p = type + strlen (type);

      icon_name = g_malloc (p - type + strlen (suffix) + 1);
      memcpy (icon_name, type, p - type);
      memcpy (icon_name + (p - type), suffix, strlen (suffix));
      icon_name[(p - type) + strlen (suffix)] = 0;
    }
  else
    {
      icon_name = g_strdup (xdg_icon_name);
    }

  return icon_name;
}
Example #2
0
static void
test_one_icon (const char *mimetype, const char *expected)
{
  const char *actual;

  actual = xdg_mime_get_generic_icon (mimetype);

  if (actual != expected && strcmp (actual, expected) != 0) 
    {
      printf ("Test Failed: icon of %s is %s, expected %s\n", 
             mimetype, actual, expected);
    }  
}
Example #3
0
static PyObject *get_generic_icon (PyObject *self, PyObject *args)
{
    const char* mime;

    if (!PyArg_ParseTuple(args, "s", &mime))
        return NULL;

    const char* result = xdg_mime_get_generic_icon(mime);

    if (result == NULL)
        Py_RETURN_NONE;

    return PyString_FromString(result);
}