Doc fixes
[platform/upstream/glib.git] / gio / gcontenttype.c
index 31d5e83..2c48a77 100644 (file)
@@ -1,3 +1,5 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
 /* GIO - GLib Input, Output and Streaming Library
  * 
  * Copyright (C) 2006-2007 Red Hat, Inc.
@@ -25,6 +27,7 @@
 #include <string.h>
 #include <stdio.h>
 #include "gcontenttypeprivate.h"
+#include "gthemedicon.h"
 #include "glibintl.h"
 
 #include "gioalias.h"
@@ -32,7 +35,7 @@
 /**
  * SECTION:gcontenttype
  * @short_description: Platform-specific content typing
- * @include: gio.h
+ * @include: gio/gio.h
  *
  * A content type is a platform specific string that defines the type
  * of a file. On unix it is a mime type, on win32 it is an extension string
@@ -322,7 +325,7 @@ char **
 _g_unix_content_type_get_parents (const char *type)
 {
   const char *umime;
-  const char **parents;
+  char **parents;
   GPtrArray *array;
   int i;
 
@@ -331,12 +334,15 @@ _g_unix_content_type_get_parents (const char *type)
   G_LOCK (gio_xdgmime);
   
   umime = xdg_mime_unalias_mime_type (type);
+  
   g_ptr_array_add (array, g_strdup (umime));
   
-  parents = xdg_mime_get_mime_parents (umime);
+  parents = xdg_mime_list_mime_parents (umime);
   for (i = 0; parents && parents[i] != NULL; i++)
     g_ptr_array_add (array, g_strdup (parents[i]));
   
+  free (parents);
+  
   G_UNLOCK (gio_xdgmime);
   
   g_ptr_array_add (array, NULL);
@@ -588,6 +594,8 @@ g_content_type_get_description (const char *type)
   g_return_val_if_fail (type != NULL, NULL);
   
   G_LOCK (gio_xdgmime);
+  type = xdg_mime_unalias_mime_type (type);
+
   if (type_comment_cache == NULL)
     type_comment_cache = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
 
@@ -636,10 +644,35 @@ g_content_type_get_mime_type (const char *type)
 GIcon *
 g_content_type_get_icon (const char *type)
 {
+  char *mimetype_icon, *generic_mimetype_icon, *p;
+  char *icon_names[2];
+  GThemedIcon *themed_icon;
+  
   g_return_val_if_fail (type != NULL, NULL);
-
-  /* TODO: Implement */
-  return NULL;
+  
+  mimetype_icon = g_strdup (type);
+  
+  while ((p = strchr (mimetype_icon, '/')) != NULL)
+    *p = '-';
+  
+  p = strchr (type, '/');
+  if (p == NULL)
+    p = type + strlen (type);
+  
+  generic_mimetype_icon = g_malloc (p - type + strlen ("-x-generic") + 1);
+  memcpy (generic_mimetype_icon, type, p - type);
+  memcpy (generic_mimetype_icon + (p - type), "-x-generic", strlen ("-x-generic"));
+  generic_mimetype_icon[(p - type) + strlen ("-x-generic")] = 0;
+  
+  icon_names[0] = mimetype_icon;
+  icon_names[1] = generic_mimetype_icon;
+  
+  themed_icon = g_themed_icon_new_from_names (icon_names, 2);
+  
+  g_free (mimetype_icon);
+  g_free (generic_mimetype_icon);
+  
+  return G_ICON (themed_icon);
 }
 
 /**
@@ -668,9 +701,14 @@ static gboolean
 looks_like_text (const guchar *data, gsize data_size)
 {
   gsize i;
+  char c;
+  
   for (i = 0; i < data_size; i++)
     {
-      if g_ascii_iscntrl (data[i])
+      c = data[i];
+      
+      if (g_ascii_iscntrl (c) &&
+         !g_ascii_isspace (c))
        return FALSE;
     }
   return TRUE;
@@ -840,8 +878,8 @@ enumerate_mimetypes_dir (const char *dir,
  * g_content_types_get_registered:
  * 
  * Gets a list of strings containing all the registered content types
- * known to the system.
- * 
+ * known to the system. The list and its data should be freed using 
+ * @g_list_foreach(list, g_free, NULL) and @g_list_free(list)
  * Returns: #GList of the registered content types.
  **/  
 GList *