]> Pileus Git - ~andy/gtk/commitdiff
Implement getting the MIME type of a file. Look it up in the Registry. Bug
authorTor Lillqvist <tml@novell.com>
Thu, 14 Jul 2005 19:10:03 +0000 (19:10 +0000)
committerTor Lillqvist <tml@src.gnome.org>
Thu, 14 Jul 2005 19:10:03 +0000 (19:10 +0000)
2005-07-14  Tor Lillqvist  <tml@novell.com>

* gtk/gtkfilesystemwin32.c (filename_get_info): Implement getting
the MIME type of a file. Look it up in the Registry. Bug reported
by Hans Oesterholt.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-8
gtk/gtkfilesystemwin32.c

index cda164976de2326adfe168258e5878c6b587340b..fdaa1450176ab84389aa84a1358e2004bf1a862e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-07-14  Tor Lillqvist  <tml@novell.com>
+
+       * gtk/gtkfilesystemwin32.c (filename_get_info): Implement getting
+       the MIME type of a file. Look it up in the Registry. Bug reported
+       by Hans Oesterholt.
+
 2005-07-14  Tor Lillqvist  <tml@novell.com>
 
        * configure.in (GDK_EXTRA_LIBS): Don't need -luuid on Win32. It
index cda164976de2326adfe168258e5878c6b587340b..fdaa1450176ab84389aa84a1358e2004bf1a862e 100644 (file)
@@ -1,3 +1,9 @@
+2005-07-14  Tor Lillqvist  <tml@novell.com>
+
+       * gtk/gtkfilesystemwin32.c (filename_get_info): Implement getting
+       the MIME type of a file. Look it up in the Registry. Bug reported
+       by Hans Oesterholt.
+
 2005-07-14  Tor Lillqvist  <tml@novell.com>
 
        * configure.in (GDK_EXTRA_LIBS): Don't need -luuid on Win32. It
index cda164976de2326adfe168258e5878c6b587340b..fdaa1450176ab84389aa84a1358e2004bf1a862e 100644 (file)
@@ -1,3 +1,9 @@
+2005-07-14  Tor Lillqvist  <tml@novell.com>
+
+       * gtk/gtkfilesystemwin32.c (filename_get_info): Implement getting
+       the MIME type of a file. Look it up in the Registry. Bug reported
+       by Hans Oesterholt.
+
 2005-07-14  Tor Lillqvist  <tml@novell.com>
 
        * configure.in (GDK_EXTRA_LIBS): Don't need -luuid on Win32. It
index 555400767ffc911d7d8386a1a714cf24601225ed..48740c472fbe15587188679c3d67a3c39e3385a6 100644 (file)
@@ -1540,23 +1540,37 @@ filename_get_info (const gchar     *filename,
     }
 #endif
 
-  if ((types & GTK_FILE_INFO_MIME_TYPE)
-#if 0 /* it's dead in gtkfilesystemunix.c, too */
-      || ((types & GTK_FILE_INFO_ICON) && icon_type == GTK_FILE_ICON_REGULAR)
-#endif
-     )
+  if (types & GTK_FILE_INFO_MIME_TYPE)
     {
-#if 0
-      const char *mime_type = xdg_mime_get_mime_type_for_file (filename);
-      gtk_file_info_set_mime_type (info, mime_type);
-
-      if ((types & GTK_FILE_INFO_ICON) && icon_type == GTK_FILE_ICON_REGULAR &&
-         (statbuf.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) &&
-         (strcmp (mime_type, XDG_MIME_TYPE_UNKNOWN) == 0 ||
-          strcmp (mime_type, "application/x-executable") == 0 ||
-          strcmp (mime_type, "application/x-shellscript") == 0))
-       gtk_file_info_set_icon_type (info, GTK_FILE_ICON_EXECUTABLE);
-#endif
+      if (g_file_test (filename, G_FILE_TEST_IS_EXECUTABLE))
+       gtk_file_info_set_mime_type (info, "application/x-executable");
+      else
+       {
+         const char *extension = strrchr (filename, '.');
+         HKEY key = NULL;
+         DWORD type, nbytes = 0;
+         char *value;
+
+         if (extension != NULL &&
+             extension[1] != '\0' &&
+             RegOpenKeyEx (HKEY_CLASSES_ROOT, extension, 0,
+                           KEY_QUERY_VALUE, &key) == ERROR_SUCCESS &&
+             RegQueryValueEx (key, "Content Type", 0,
+                              &type, NULL, &nbytes) == ERROR_SUCCESS &&
+             type == REG_SZ &&
+             (value = g_try_malloc (nbytes + 1)) &&
+             RegQueryValueEx (key, "Content Type", 0,
+                              &type, value, &nbytes) == ERROR_SUCCESS)
+           {
+             value[nbytes] = '\0';
+             gtk_file_info_set_mime_type (info, value);
+             g_free (value);
+           }
+         else
+           gtk_file_info_set_mime_type (info, "application/octet-stream");
+         if (key != NULL)
+           RegCloseKey (key);
+       }
     }
 
   if (types & GTK_FILE_INFO_MODIFICATION_TIME)