summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Sullivan <sullivan@src.gnome.org>2000-04-12 00:05:23 +0000
committerJohn Sullivan <sullivan@src.gnome.org>2000-04-12 00:05:23 +0000
commitf96591d2e3e9f84e5463749324afc77853095660 (patch)
treead755ba97df94c06aa459007ae59bd06c54aa6c2
parent682bcce22872869051fe04a7bdc710f10463a7b4 (diff)
downloadnautilus-f96591d2e3e9f84e5463749324afc77853095660.tar.gz
Addressed most of task 148 (Better type-as-string for
directory views). Added new directory to CVS, so make sure you do a "cvs update -d" and not just "cvs update". "make install" now installs a file of mime-type-to-English descriptions in the gnome-mime directory. * data/mime/nautilus.keys: The actual mapping between MIME types and English descriptions. Read these and send me your abuse. * data/mime/Makefile.am: New file, copies nautilus.keys to gnome-mime directory. * data/Makefile.am: includes "mime" subdirectory * configure.in: configures "data/mime" directory * libnautilus/nautilus-file.c: (nautilus_file_get_mime_type_as_string_attribute): New function, returns the raw MIME type as a string, and handles the no-MIME-type case. (nautilus_file_get_string_attribute): handle attribute "mime_type", distinct from "type" which is now the human-language one. (nautilus_file_get_type_as_string): Use gnome-mime to get human-language descriptions based on the MIME type. (nautilus_file_is_executable): Fixed this function which was reading info->flags instead of info->permissions. Now the special executable icon appears much more often (though we still don't know what it's supposed to be). * src/file-manager/fm-error-reporting.c: (fm_report_error_renaming_file): Use "directory" instead of "folder" to match our terminology elsewhere. * src/file-manager/fm-icon-text-window.c: add "mime type" to list of choices of text that can appear beneath icons (in addition to just plain "type", which is the human-language one).
-rw-r--r--ChangeLog-2000041439
-rw-r--r--configure.in1
-rw-r--r--data/Makefile.am7
-rw-r--r--data/mime/Makefile.am9
-rw-r--r--data/mime/nautilus.keys65
-rw-r--r--libnautilus-extensions/nautilus-file.c77
-rw-r--r--libnautilus-private/nautilus-file.c77
-rw-r--r--libnautilus/nautilus-file.c77
-rw-r--r--src/file-manager/fm-error-reporting.c2
-rw-r--r--src/file-manager/fm-icon-text-window.c2
10 files changed, 321 insertions, 35 deletions
diff --git a/ChangeLog-20000414 b/ChangeLog-20000414
index 34e981887..62a5b6a77 100644
--- a/ChangeLog-20000414
+++ b/ChangeLog-20000414
@@ -1,3 +1,42 @@
+2000-04-11 John Sullivan <sullivan@eazel.com>
+
+ Addressed most of task 148 (Better type-as-string for
+ directory views). Added new directory to CVS, so make
+ sure you do a "cvs update -d" and not just "cvs update".
+
+ "make install" now installs a file of mime-type-to-English
+ descriptions in the gnome-mime directory.
+
+ * data/mime/nautilus.keys: The actual mapping between
+ MIME types and English descriptions. Read these and send
+ me your abuse.
+ * data/mime/Makefile.am: New file, copies nautilus.keys to
+ gnome-mime directory.
+ * data/Makefile.am: includes "mime" subdirectory
+ * configure.in: configures "data/mime" directory
+
+ * libnautilus/nautilus-file.c:
+ (nautilus_file_get_mime_type_as_string_attribute):
+ New function, returns the raw MIME type as a string,
+ and handles the no-MIME-type case.
+ (nautilus_file_get_string_attribute): handle attribute
+ "mime_type", distinct from "type" which is now the
+ human-language one.
+ (nautilus_file_get_type_as_string): Use gnome-mime
+ to get human-language descriptions based on the MIME
+ type.
+ (nautilus_file_is_executable): Fixed this function which
+ was reading info->flags instead of info->permissions. Now
+ the special executable icon appears much more often (though
+ we still don't know what it's supposed to be).
+ * src/file-manager/fm-error-reporting.c:
+ (fm_report_error_renaming_file): Use "directory" instead of
+ "folder" to match our terminology elsewhere.
+ * src/file-manager/fm-icon-text-window.c:
+ add "mime type" to list of choices of text that can appear
+ beneath icons (in addition to just plain "type", which is
+ the human-language one).
+
2000-04-11 Darin Adler <darin@eazel.com>
Finished task 226 (Read metadata asynchronously instead of
diff --git a/configure.in b/configure.in
index a9bf19162..5994cac0e 100644
--- a/configure.in
+++ b/configure.in
@@ -139,6 +139,7 @@ Makefile
icons/Makefile
icons/eazel/Makefile
data/Makefile
+data/mime/Makefile
data/top/Makefile
idl/Makefile
libnautilus/Makefile
diff --git a/data/Makefile.am b/data/Makefile.am
index 67154695f..c442d447d 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -1 +1,6 @@
-SUBDIRS = top
+NULL=
+
+SUBDIRS =\
+ top \
+ mime \
+ $(NULL)
diff --git a/data/mime/Makefile.am b/data/mime/Makefile.am
new file mode 100644
index 000000000..f665340ae
--- /dev/null
+++ b/data/mime/Makefile.am
@@ -0,0 +1,9 @@
+NULL=
+
+mimedir = $(datadir)/mime-info
+
+mime_DATA = \
+ nautilus.keys \
+ $(NULL)
+
+EXTRA_DIST = $(mime_DATA)
diff --git a/data/mime/nautilus.keys b/data/mime/nautilus.keys
new file mode 100644
index 000000000..f293b20e5
--- /dev/null
+++ b/data/mime/nautilus.keys
@@ -0,0 +1,65 @@
+application/x-backup
+ description=backup document
+
+application/x-cgi
+ description=CGI program
+
+application/x-compressed-tar
+ description=tar archive
+
+application/x-object-file
+ description=object code
+
+application/x-sh
+ description=shell script
+
+application/x-shared-library
+ description=shared library
+
+application/x-shared-library-la
+ description=shared library
+
+image/gif
+ description=GIF image
+
+image/jpeg
+ description=JPEG image
+
+image/xpm
+ description=XPM image
+
+image/x-png
+ description=PNG image
+
+special/directory
+ description=directory
+
+text/html
+ description=HTML document
+
+text/plain
+ description=plain text
+
+text/xml
+ description=XML document
+
+text/x-authors
+ description=authors list
+
+text/x-c
+ description=C source code
+
+text/x-copying
+ description=GNU license
+
+text/x-install
+ description=installation instructions
+
+text/x-makefile
+ description=makefile
+
+text/x-perl
+ description=Perl script
+
+text/x-readme
+ description=text \ No newline at end of file
diff --git a/libnautilus-extensions/nautilus-file.c b/libnautilus-extensions/nautilus-file.c
index 548df8c7b..b7b2a8d39 100644
--- a/libnautilus-extensions/nautilus-file.c
+++ b/libnautilus-extensions/nautilus-file.c
@@ -32,6 +32,8 @@
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-i18n.h>
+#include <libgnome/gnome-mime-info.h>
+#include <libgnome/gnome-mime.h>
#include <stdlib.h>
#include <xmlmemory.h>
@@ -925,6 +927,30 @@ nautilus_file_get_group_as_string (NautilusFile *file)
return g_strdup (group_info->gr_name);
}
+/**
+ * nautilus_file_get_mime_type_as_string_attribute:
+ *
+ * Get a user-displayable string representing a file's MIME type.
+ * This string will be displayed in file manager views and thus
+ * will not be blank even if the MIME type is unknown. The caller
+ * is responsible for g_free-ing this string.
+ * @file: NautilusFile representing the file in question.
+ *
+ * Returns: Newly allocated string ready to display to the user.
+ *
+ **/
+static char *
+nautilus_file_get_mime_type_as_string_attribute (NautilusFile *file)
+{
+ const char *mime_string;
+
+ mime_string = nautilus_file_get_mime_type (file);
+ if (nautilus_strlen (mime_string) > 0) {
+ return g_strdup (mime_string);
+ }
+
+ return g_strdup ("unknown MIME type");
+}
/* This #include is part of the following hack, and should be removed with it */
#include <dirent.h>
@@ -1021,7 +1047,7 @@ nautilus_file_get_size_as_string (NautilusFile *file)
*
* @file: NautilusFile representing the file in question.
* @attribute_name: The name of the desired attribute. The currently supported
- * set includes "name", "type", "size", "date_modified", "date_changed",
+ * set includes "name", "type", "mime_type", "size", "date_modified", "date_changed",
* "date_accessed", "owner", "group", "permissions".
*
* Returns: Newly allocated string ready to display to the user, or NULL
@@ -1043,6 +1069,10 @@ nautilus_file_get_string_attribute (NautilusFile *file, const char *attribute_na
return nautilus_file_get_type_as_string (file);
}
+ if (strcmp (attribute_name, "mime_type") == 0) {
+ return nautilus_file_get_mime_type_as_string_attribute (file);
+ }
+
if (strcmp (attribute_name, "size") == 0) {
return nautilus_file_get_size_as_string (file);
}
@@ -1090,20 +1120,36 @@ nautilus_file_get_string_attribute (NautilusFile *file, const char *attribute_na
static char *
nautilus_file_get_type_as_string (NautilusFile *file)
{
+ const char *mime_type;
+ const char *description;
+
g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
- if (nautilus_file_is_directory (file)) {
- /* Special-case this so it isn't "special/directory".
- * FIXME: Should this be "folder" instead?
- */
- return g_strdup (_("directory"));
- }
+ mime_type = (file->details->info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE) != 0 ?
+ file->details->info->mime_type :
+ NULL;
+
+ if (nautilus_strlen (mime_type) == 0) {
+ /* No mime type, anything else interesting we can say about this? */
+ if (nautilus_file_is_executable (file)) {
+ return g_strdup (_("program"));
+ }
- if (nautilus_strlen (file->details->info->mime_type) == 0) {
return g_strdup (_("unknown type"));
}
- return g_strdup (file->details->info->mime_type);
+ description = gnome_mime_description (mime_type);
+ if (nautilus_strlen (description) > 0) {
+ return g_strdup (description);
+ }
+
+ /* We want to update nautilus/data/nautilus.keys to include
+ * English (& localizable) versions of every mime type anyone ever sees.
+ */
+ g_warning ("No description found for mime type \"%s\" (file is \"%s\"), tell sullivan@eazel.com",
+ mime_type,
+ file->details->info->name);
+ return g_strdup (mime_type);
}
/**
@@ -1342,7 +1388,8 @@ nautilus_file_is_directory (NautilusFile *file)
* Check if this file is executable at all.
* @file: NautilusFile representing the file in question.
*
- * Returns: True if any of the execute bits are set.
+ * Returns: TRUE if any of the execute bits are set. FALSE if
+ * not, or if the permissions are unknown.
*
**/
gboolean
@@ -1350,7 +1397,15 @@ nautilus_file_is_executable (NautilusFile *file)
{
g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
- return (file->details->info->flags & (GNOME_VFS_PERM_USER_EXEC
+ if ((file->details->info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS) == 0){
+ /*
+ * Permissions field is not valid.
+ * Can't tell whether this file is executable, so return FALSE.
+ */
+ return FALSE;
+ }
+
+ return (file->details->info->permissions & (GNOME_VFS_PERM_USER_EXEC
| GNOME_VFS_PERM_GROUP_EXEC
| GNOME_VFS_PERM_OTHER_EXEC)) != 0;
}
diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c
index 548df8c7b..b7b2a8d39 100644
--- a/libnautilus-private/nautilus-file.c
+++ b/libnautilus-private/nautilus-file.c
@@ -32,6 +32,8 @@
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-i18n.h>
+#include <libgnome/gnome-mime-info.h>
+#include <libgnome/gnome-mime.h>
#include <stdlib.h>
#include <xmlmemory.h>
@@ -925,6 +927,30 @@ nautilus_file_get_group_as_string (NautilusFile *file)
return g_strdup (group_info->gr_name);
}
+/**
+ * nautilus_file_get_mime_type_as_string_attribute:
+ *
+ * Get a user-displayable string representing a file's MIME type.
+ * This string will be displayed in file manager views and thus
+ * will not be blank even if the MIME type is unknown. The caller
+ * is responsible for g_free-ing this string.
+ * @file: NautilusFile representing the file in question.
+ *
+ * Returns: Newly allocated string ready to display to the user.
+ *
+ **/
+static char *
+nautilus_file_get_mime_type_as_string_attribute (NautilusFile *file)
+{
+ const char *mime_string;
+
+ mime_string = nautilus_file_get_mime_type (file);
+ if (nautilus_strlen (mime_string) > 0) {
+ return g_strdup (mime_string);
+ }
+
+ return g_strdup ("unknown MIME type");
+}
/* This #include is part of the following hack, and should be removed with it */
#include <dirent.h>
@@ -1021,7 +1047,7 @@ nautilus_file_get_size_as_string (NautilusFile *file)
*
* @file: NautilusFile representing the file in question.
* @attribute_name: The name of the desired attribute. The currently supported
- * set includes "name", "type", "size", "date_modified", "date_changed",
+ * set includes "name", "type", "mime_type", "size", "date_modified", "date_changed",
* "date_accessed", "owner", "group", "permissions".
*
* Returns: Newly allocated string ready to display to the user, or NULL
@@ -1043,6 +1069,10 @@ nautilus_file_get_string_attribute (NautilusFile *file, const char *attribute_na
return nautilus_file_get_type_as_string (file);
}
+ if (strcmp (attribute_name, "mime_type") == 0) {
+ return nautilus_file_get_mime_type_as_string_attribute (file);
+ }
+
if (strcmp (attribute_name, "size") == 0) {
return nautilus_file_get_size_as_string (file);
}
@@ -1090,20 +1120,36 @@ nautilus_file_get_string_attribute (NautilusFile *file, const char *attribute_na
static char *
nautilus_file_get_type_as_string (NautilusFile *file)
{
+ const char *mime_type;
+ const char *description;
+
g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
- if (nautilus_file_is_directory (file)) {
- /* Special-case this so it isn't "special/directory".
- * FIXME: Should this be "folder" instead?
- */
- return g_strdup (_("directory"));
- }
+ mime_type = (file->details->info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE) != 0 ?
+ file->details->info->mime_type :
+ NULL;
+
+ if (nautilus_strlen (mime_type) == 0) {
+ /* No mime type, anything else interesting we can say about this? */
+ if (nautilus_file_is_executable (file)) {
+ return g_strdup (_("program"));
+ }
- if (nautilus_strlen (file->details->info->mime_type) == 0) {
return g_strdup (_("unknown type"));
}
- return g_strdup (file->details->info->mime_type);
+ description = gnome_mime_description (mime_type);
+ if (nautilus_strlen (description) > 0) {
+ return g_strdup (description);
+ }
+
+ /* We want to update nautilus/data/nautilus.keys to include
+ * English (& localizable) versions of every mime type anyone ever sees.
+ */
+ g_warning ("No description found for mime type \"%s\" (file is \"%s\"), tell sullivan@eazel.com",
+ mime_type,
+ file->details->info->name);
+ return g_strdup (mime_type);
}
/**
@@ -1342,7 +1388,8 @@ nautilus_file_is_directory (NautilusFile *file)
* Check if this file is executable at all.
* @file: NautilusFile representing the file in question.
*
- * Returns: True if any of the execute bits are set.
+ * Returns: TRUE if any of the execute bits are set. FALSE if
+ * not, or if the permissions are unknown.
*
**/
gboolean
@@ -1350,7 +1397,15 @@ nautilus_file_is_executable (NautilusFile *file)
{
g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
- return (file->details->info->flags & (GNOME_VFS_PERM_USER_EXEC
+ if ((file->details->info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS) == 0){
+ /*
+ * Permissions field is not valid.
+ * Can't tell whether this file is executable, so return FALSE.
+ */
+ return FALSE;
+ }
+
+ return (file->details->info->permissions & (GNOME_VFS_PERM_USER_EXEC
| GNOME_VFS_PERM_GROUP_EXEC
| GNOME_VFS_PERM_OTHER_EXEC)) != 0;
}
diff --git a/libnautilus/nautilus-file.c b/libnautilus/nautilus-file.c
index 548df8c7b..b7b2a8d39 100644
--- a/libnautilus/nautilus-file.c
+++ b/libnautilus/nautilus-file.c
@@ -32,6 +32,8 @@
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-i18n.h>
+#include <libgnome/gnome-mime-info.h>
+#include <libgnome/gnome-mime.h>
#include <stdlib.h>
#include <xmlmemory.h>
@@ -925,6 +927,30 @@ nautilus_file_get_group_as_string (NautilusFile *file)
return g_strdup (group_info->gr_name);
}
+/**
+ * nautilus_file_get_mime_type_as_string_attribute:
+ *
+ * Get a user-displayable string representing a file's MIME type.
+ * This string will be displayed in file manager views and thus
+ * will not be blank even if the MIME type is unknown. The caller
+ * is responsible for g_free-ing this string.
+ * @file: NautilusFile representing the file in question.
+ *
+ * Returns: Newly allocated string ready to display to the user.
+ *
+ **/
+static char *
+nautilus_file_get_mime_type_as_string_attribute (NautilusFile *file)
+{
+ const char *mime_string;
+
+ mime_string = nautilus_file_get_mime_type (file);
+ if (nautilus_strlen (mime_string) > 0) {
+ return g_strdup (mime_string);
+ }
+
+ return g_strdup ("unknown MIME type");
+}
/* This #include is part of the following hack, and should be removed with it */
#include <dirent.h>
@@ -1021,7 +1047,7 @@ nautilus_file_get_size_as_string (NautilusFile *file)
*
* @file: NautilusFile representing the file in question.
* @attribute_name: The name of the desired attribute. The currently supported
- * set includes "name", "type", "size", "date_modified", "date_changed",
+ * set includes "name", "type", "mime_type", "size", "date_modified", "date_changed",
* "date_accessed", "owner", "group", "permissions".
*
* Returns: Newly allocated string ready to display to the user, or NULL
@@ -1043,6 +1069,10 @@ nautilus_file_get_string_attribute (NautilusFile *file, const char *attribute_na
return nautilus_file_get_type_as_string (file);
}
+ if (strcmp (attribute_name, "mime_type") == 0) {
+ return nautilus_file_get_mime_type_as_string_attribute (file);
+ }
+
if (strcmp (attribute_name, "size") == 0) {
return nautilus_file_get_size_as_string (file);
}
@@ -1090,20 +1120,36 @@ nautilus_file_get_string_attribute (NautilusFile *file, const char *attribute_na
static char *
nautilus_file_get_type_as_string (NautilusFile *file)
{
+ const char *mime_type;
+ const char *description;
+
g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
- if (nautilus_file_is_directory (file)) {
- /* Special-case this so it isn't "special/directory".
- * FIXME: Should this be "folder" instead?
- */
- return g_strdup (_("directory"));
- }
+ mime_type = (file->details->info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE) != 0 ?
+ file->details->info->mime_type :
+ NULL;
+
+ if (nautilus_strlen (mime_type) == 0) {
+ /* No mime type, anything else interesting we can say about this? */
+ if (nautilus_file_is_executable (file)) {
+ return g_strdup (_("program"));
+ }
- if (nautilus_strlen (file->details->info->mime_type) == 0) {
return g_strdup (_("unknown type"));
}
- return g_strdup (file->details->info->mime_type);
+ description = gnome_mime_description (mime_type);
+ if (nautilus_strlen (description) > 0) {
+ return g_strdup (description);
+ }
+
+ /* We want to update nautilus/data/nautilus.keys to include
+ * English (& localizable) versions of every mime type anyone ever sees.
+ */
+ g_warning ("No description found for mime type \"%s\" (file is \"%s\"), tell sullivan@eazel.com",
+ mime_type,
+ file->details->info->name);
+ return g_strdup (mime_type);
}
/**
@@ -1342,7 +1388,8 @@ nautilus_file_is_directory (NautilusFile *file)
* Check if this file is executable at all.
* @file: NautilusFile representing the file in question.
*
- * Returns: True if any of the execute bits are set.
+ * Returns: TRUE if any of the execute bits are set. FALSE if
+ * not, or if the permissions are unknown.
*
**/
gboolean
@@ -1350,7 +1397,15 @@ nautilus_file_is_executable (NautilusFile *file)
{
g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
- return (file->details->info->flags & (GNOME_VFS_PERM_USER_EXEC
+ if ((file->details->info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS) == 0){
+ /*
+ * Permissions field is not valid.
+ * Can't tell whether this file is executable, so return FALSE.
+ */
+ return FALSE;
+ }
+
+ return (file->details->info->permissions & (GNOME_VFS_PERM_USER_EXEC
| GNOME_VFS_PERM_GROUP_EXEC
| GNOME_VFS_PERM_OTHER_EXEC)) != 0;
}
diff --git a/src/file-manager/fm-error-reporting.c b/src/file-manager/fm-error-reporting.c
index 3f621d8cb..af972df59 100644
--- a/src/file-manager/fm-error-reporting.c
+++ b/src/file-manager/fm-error-reporting.c
@@ -41,7 +41,7 @@ fm_report_error_renaming_file (const char *original_name,
switch (error) {
case GNOME_VFS_ERROR_FILEEXISTS:
- message = g_strdup_printf ("The name \"%s\" is already used in this folder.\nPlease use a different name.",
+ message = g_strdup_printf ("The name \"%s\" is already used in this directory.\nPlease use a different name.",
new_name);
break;
default:
diff --git a/src/file-manager/fm-icon-text-window.c b/src/file-manager/fm-icon-text-window.c
index 9b6a98ee9..646382485 100644
--- a/src/file-manager/fm-icon-text-window.c
+++ b/src/file-manager/fm-icon-text-window.c
@@ -64,6 +64,7 @@ static char * attribute_names[] = {
"owner",
"group",
"permissions",
+ "mime_type",
NULL
};
@@ -76,6 +77,7 @@ static char * attribute_labels[] = {
_("owner"),
_("group"),
_("permissions"),
+ _("MIME type"),
NULL
};