summaryrefslogtreecommitdiff
path: root/libnautilus-private/nautilus-link.c
diff options
context:
space:
mode:
authorDarin Adler <darin@src.gnome.org>2001-11-06 17:29:42 +0000
committerDarin Adler <darin@src.gnome.org>2001-11-06 17:29:42 +0000
commitdfefd4c356ae77366f765379de8641677e4e0e91 (patch)
tree6f0bb2d4602eeb90520e5f28ee059ed7f3cc7500 /libnautilus-private/nautilus-link.c
parent41572cfeec9d4b94b0464aecfbd1e742b25a4240 (diff)
downloadnautilus-dfefd4c356ae77366f765379de8641677e4e0e91.tar.gz
Update for gnome-vfs API changes.
* libnautilus-private/nautilus-file.c: Remove include of gnome-vfs-mime-info.h. Also switch to g_ascii_strcasecmp instead of g_strcasecmp. * libnautilus-private/nautilus-icon-factory.c: Remove includes of gnome-vfs-mime.h and gnome-vfs-mime-info.h. * libnautilus-private/nautilus-link-desktop-file.c: Remove include of gnome-vfs-mime.h. * libnautilus-private/nautilus-link-historical.c: (local_get_root_property): Rewrote to use gnome_vfs_get_file_info. Removed include of gnome-vfs-mime.h. * libnautilus-private/nautilus-link.c: (get_link_style_for_mime_type): New function. (get_link_style_for_local_file): New function, uses gnome_vfs_get_file_info instead of gnome_vfs_get_mime_type. (get_link_style_for_data): New function. (nautilus_link_local_create), (nautilus_link_local_set_icon), (nautilus_link_local_set_link_uri), (nautilus_link_local_set_type), (nautilus_link_local_get_additional_text), (nautilus_link_local_get_link_uri), (nautilus_link_local_get_link_type), (nautilus_link_get_link_uri_given_file_contents), (nautilus_link_get_link_name_given_file_contents), (nautilus_link_get_link_icon_given_file_contents), (nautilus_link_local_is_volume_link), (nautilus_link_local_is_home_link), (nautilus_link_local_is_trash_link), (nautilus_link_local_create_from_gnome_entry): Rewrote all of these to simplify and get rid of spread-out MIME type code. * libnautilus-private/nautilus-mime-actions.c: Remove include of gnome-vfs-mime-info.h. * src/Makefile.am: Remove extra dist-hook.
Diffstat (limited to 'libnautilus-private/nautilus-link.c')
-rw-r--r--libnautilus-private/nautilus-link.c350
1 files changed, 155 insertions, 195 deletions
diff --git a/libnautilus-private/nautilus-link.c b/libnautilus-private/nautilus-link.c
index 9a8c71b3f..8d270e317 100644
--- a/libnautilus-private/nautilus-link.c
+++ b/libnautilus-private/nautilus-link.c
@@ -44,22 +44,63 @@
#include <libgnome/gnome-i18n.h>
#include <libgnome/gnome-util.h>
#include <libgnomevfs/gnome-vfs-mime.h>
-#include <libgnomevfs/gnome-vfs.h>
+#include <libgnomevfs/gnome-vfs-ops.h>
+#include <libgnomevfs/gnome-vfs-utils.h>
#include <stdlib.h>
-const char *get_uri_mime_type_full (const gchar *uri_path);
+typedef enum {
+ not_link,
+ historical,
+ desktop
+} LinkStyle;
-const char *
-get_uri_mime_type_full (const gchar *uri_path)
+static LinkStyle
+get_link_style_for_mime_type (const char *mime_type)
{
- const gchar *retval;
- GnomeVFSURI *uri;
+ if (mime_type != NULL) {
+ if (g_ascii_strcasecmp (mime_type, "application/x-nautilus-link") == 0) {
+ return desktop;
+ }
+ if (g_ascii_strcasecmp (mime_type, "application/x-nautilus-link") == 0) {
+ return historical;
+ }
+ }
+ return not_link;
+}
+
+static LinkStyle
+get_link_style_for_local_file (const char *path)
+{
+ LinkStyle type;
+ GnomeVFSFileInfo *info;
+ char *uri;
+ GnomeVFSResult result;
+
+ info = gnome_vfs_file_info_new ();
+
+ uri = gnome_vfs_get_uri_from_local_path (path);
+ result = gnome_vfs_get_file_info (uri, info,
+ GNOME_VFS_FILE_INFO_GET_MIME_TYPE
+ | GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
+ g_free (uri);
+
+ if (result == GNOME_VFS_OK
+ && (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE) != 0) {
+ type = get_link_style_for_mime_type (info->mime_type);
+ } else {
+ type = not_link;
+ }
+
+ gnome_vfs_file_info_unref (info);
- uri = gnome_vfs_uri_new (uri_path);
- retval = gnome_vfs_get_mime_type (uri);
- gnome_vfs_uri_unref (uri);
+ return type;
+}
- return retval;
+static LinkStyle
+get_link_style_for_data (const char *file_contents, int file_size)
+{
+ return get_link_style_for_mime_type
+ (gnome_vfs_get_mime_type_for_data (file_contents, file_size));
}
gboolean
@@ -70,65 +111,58 @@ nautilus_link_local_create (const char *directory_path,
const GdkPoint *point,
NautilusLinkType type)
{
- gboolean retval;
-
- retval = nautilus_link_desktop_file_local_create (directory_path,
- name, image,
- target_uri, point,
- type);
-
- return retval;
+ return nautilus_link_desktop_file_local_create (directory_path,
+ name, image,
+ target_uri, point,
+ type);
}
gboolean
nautilus_link_local_set_icon (const char *path, const char *icon_name)
{
- const gchar *mime_type;
- gboolean retval;
+ gboolean result;
NautilusFile *file;
GList *attributes;
- mime_type = get_uri_mime_type_full (path);
- retval = FALSE;
-
- if (mime_type == NULL) {
- return retval;
- }
-
- if (strcmp (mime_type, "application/x-nautilus-link") == 0) {
- retval = nautilus_link_historical_local_set_icon (path, icon_name);
- } else if (strcmp (mime_type, "application/x-gnome-app-info") == 0) {
- retval = nautilus_link_desktop_file_local_set_icon (path, icon_name);
+ switch (get_link_style_for_local_file (path)) {
+ case desktop:
+ result = nautilus_link_desktop_file_local_set_icon (path, icon_name);
+ break;
+ case historical:
+ result = nautilus_link_historical_local_set_icon (path, icon_name);
+ break;
+ default:
+ result = FALSE;
}
-
+
file = nautilus_file_get (path);
attributes = g_list_prepend (NULL, NAUTILUS_FILE_ATTRIBUTE_ACTIVATION_URI);
nautilus_file_invalidate_attributes (file, attributes);
nautilus_file_unref (file);
g_list_free (attributes);
-
- return retval;
+
+ return result;
}
gboolean
nautilus_link_local_set_link_uri (const char *path, const char *link_uri)
{
- const gchar *mime_type;
- gboolean retval;
+ gboolean result;
NautilusFile *file;
GList *attributes;
- mime_type = get_uri_mime_type_full (path);
- retval = FALSE;
-
- if (mime_type == NULL) {
- return retval;
+ switch (get_link_style_for_local_file (path)) {
+ case desktop:
+ /* FIXME: May want to implement this for desktop files too */
+ result = FALSE;
+ break;
+ case historical:
+ result = nautilus_link_historical_local_set_link_uri (path, link_uri);
+ break;
+ default:
+ result = FALSE;
}
- if (strcmp (mime_type, "application/x-nautilus-link") == 0) {
- retval = nautilus_link_historical_local_set_link_uri (path, link_uri);
- }
- /* FIXME: May want to implement this for desktop files too */
file = nautilus_file_get (path);
attributes = g_list_prepend (NULL, NAUTILUS_FILE_ATTRIBUTE_ACTIVATION_URI);
@@ -136,227 +170,153 @@ nautilus_link_local_set_link_uri (const char *path, const char *link_uri)
nautilus_file_unref (file);
g_list_free (attributes);
- return retval;
+ return result;
}
gboolean
nautilus_link_local_set_type (const char *path,
NautilusLinkType type)
{
- const gchar *mime_type;
- gboolean retval;
-
- mime_type = get_uri_mime_type_full (path);
- retval = FALSE;
-
- if (mime_type == NULL) {
- return retval;
+ switch (get_link_style_for_local_file (path)) {
+ case desktop:
+ /* FIXME: May want to implement this for desktop files too */
+ return FALSE;
+ case historical:
+ return nautilus_link_historical_local_set_type (path, type);
+ default:
+ return FALSE;
}
-
- if (strcmp (mime_type, "application/x-nautilus-link") == 0) {
- retval = nautilus_link_historical_local_set_type (path, type);
- }
- /* FIXME: May want to implement this for desktop files too */
-
- return retval;
}
/* returns additional text to display under the name, NULL if none */
char *
nautilus_link_local_get_additional_text (const char *path)
{
- const gchar *mime_type;
- gchar *retval;
-
- mime_type = get_uri_mime_type_full (path);
- retval = NULL;
-
- if (mime_type == NULL) {
- return retval;
- }
-
- if (strcmp (mime_type, "application/x-nautilus-link") == 0) {
- retval = nautilus_link_historical_local_get_additional_text (path);
- } else if (strcmp (mime_type, "application/x-gnome-app-info") == 0) {
- retval = nautilus_link_desktop_file_local_get_additional_text (path);
+ switch (get_link_style_for_local_file (path)) {
+ case desktop:
+ return nautilus_link_desktop_file_local_get_additional_text (path);
+ case historical:
+ return nautilus_link_historical_local_get_additional_text (path);
+ default:
+ return NULL;
}
-
- return retval;
}
/* Returns the link uri associated with a link file. */
char *
nautilus_link_local_get_link_uri (const char *path)
{
- const gchar *mime_type;
- gchar *retval;
-
- mime_type = get_uri_mime_type_full (path);
- retval = NULL;
-
- if (mime_type == NULL) {
- return retval;
- }
-
- if (strcmp (mime_type, "application/x-nautilus-link") == 0) {
- retval = nautilus_link_historical_local_get_link_uri (path);
- } else if (strcmp (mime_type, "application/x-gnome-app-info") == 0) {
- retval = nautilus_link_desktop_file_local_get_link_uri (path);
+ switch (get_link_style_for_local_file (path)) {
+ case desktop:
+ return nautilus_link_desktop_file_local_get_link_uri (path);
+ case historical:
+ return nautilus_link_historical_local_get_link_uri (path);
+ default:
+ return NULL;
}
-
- return retval;
}
/* Returns the link type of the link file. */
NautilusLinkType
nautilus_link_local_get_link_type (const char *path)
{
- const gchar *mime_type;
- NautilusLinkType retval;
-
- mime_type = get_uri_mime_type_full (path);
- retval = NAUTILUS_LINK_GENERIC;
-
- if (mime_type == NULL) {
- return retval;
- }
-
- if (strcmp (mime_type, "application/x-nautilus-link") == 0) {
- retval = nautilus_link_historical_local_get_link_type (path);
- } else if (strcmp (mime_type, "application/x-gnome-app-info") == 0) {
- retval = nautilus_link_desktop_file_local_get_link_type (path);
+ switch (get_link_style_for_local_file (path)) {
+ case desktop:
+ return nautilus_link_desktop_file_local_get_link_type (path);
+ case historical:
+ return nautilus_link_historical_local_get_link_type (path);
+ default:
+ return NAUTILUS_LINK_GENERIC;
}
-
- return retval;
}
char *
nautilus_link_get_link_uri_given_file_contents (const char *file_contents,
int file_size)
{
- const gchar *mime_type;
- gchar *retval;
-
- mime_type = gnome_vfs_get_mime_type_for_data (file_contents, file_size);
- retval = NULL;
-
- if (strcmp (mime_type, "application/x-nautilus-link") == 0) {
- retval = nautilus_link_historical_get_link_uri_given_file_contents (file_contents, file_size);
- } else if (strcmp (mime_type, "application/x-gnome-app-info") == 0) {
- retval = nautilus_link_desktop_file_get_link_uri_given_file_contents (file_contents, file_size);
+ switch (get_link_style_for_data (file_contents, file_size)) {
+ case desktop:
+ return nautilus_link_desktop_file_get_link_uri_given_file_contents (file_contents, file_size);
+ case historical:
+ return nautilus_link_historical_get_link_uri_given_file_contents (file_contents, file_size);
+ default:
+ return NULL;
}
-
- return retval;
}
char *
nautilus_link_get_link_name_given_file_contents (const char *file_contents,
- int file_size)
+ int file_size)
{
- const gchar *mime_type;
- gchar *retval;
-
- mime_type = gnome_vfs_get_mime_type_for_data (file_contents, file_size);
- retval = NULL;
-
- if (strcmp (mime_type, "application/x-nautilus-link") == 0) {
- retval = NULL;
- } else if (strcmp (mime_type, "application/x-gnome-app-info") == 0) {
- retval = nautilus_link_desktop_file_get_link_name_given_file_contents (file_contents, file_size);
+ switch (get_link_style_for_data (file_contents, file_size)) {
+ case desktop:
+ return nautilus_link_desktop_file_get_link_name_given_file_contents (file_contents, file_size);
+ case historical:
+ return NULL;
+ default:
+ return NULL;
}
-
- return retval;
}
char *
nautilus_link_get_link_icon_given_file_contents (const char *file_contents,
int file_size)
{
- const gchar *mime_type;
- gchar *retval;
-
- mime_type = gnome_vfs_get_mime_type_for_data (file_contents, file_size);
- retval = NULL;
-
- if (strcmp (mime_type, "application/x-nautilus-link") == 0) {
- retval = nautilus_link_historical_get_link_icon_given_file_contents (file_contents, file_size);
- } else if (strcmp (mime_type, "application/x-gnome-app-info") == 0) {
- retval = nautilus_link_desktop_file_get_link_icon_given_file_contents (file_contents, file_size);
+ switch (get_link_style_for_data (file_contents, file_size)) {
+ case desktop:
+ return nautilus_link_desktop_file_get_link_icon_given_file_contents (file_contents, file_size);
+ case historical:
+ return nautilus_link_historical_get_link_icon_given_file_contents (file_contents, file_size);
+ default:
+ return NULL;
}
-
- return retval;
}
gboolean
nautilus_link_local_is_volume_link (const char *path)
{
- const gchar *mime_type;
- gboolean retval;
-
- mime_type = get_uri_mime_type_full (path);
- retval = FALSE;
-
- if (mime_type == NULL) {
- return retval;
- }
-
- if (strcmp (mime_type, "application/x-nautilus-link") == 0) {
- retval = nautilus_link_historical_local_is_volume_link (path);
- } else if (strcmp (mime_type, "application/x-gnome-app-info") == 0) {
- retval = nautilus_link_desktop_file_local_is_volume_link (path);
+ switch (get_link_style_for_local_file (path)) {
+ case desktop:
+ return nautilus_link_desktop_file_local_is_volume_link (path);
+ case historical:
+ return nautilus_link_historical_local_is_volume_link (path);
+ default:
+ return FALSE;
}
-
- return retval;
}
gboolean
nautilus_link_local_is_home_link (const char *path)
{
- const gchar *mime_type;
- gboolean retval;
-
- mime_type = get_uri_mime_type_full (path);
- retval = FALSE;
-
- if (mime_type == NULL) {
- return retval;
+ switch (get_link_style_for_local_file (path)) {
+ case desktop:
+ return nautilus_link_desktop_file_local_is_home_link (path);
+ case historical:
+ return nautilus_link_historical_local_is_home_link (path);
+ default:
+ return FALSE;
}
-
- if (strcmp (mime_type, "application/x-nautilus-link") == 0) {
- retval = nautilus_link_historical_local_is_home_link (path);
- } else if (strcmp (mime_type, "application/x-gnome-app-info") == 0) {
- retval = nautilus_link_desktop_file_local_is_home_link (path);
- }
-
- return retval;
}
gboolean
nautilus_link_local_is_trash_link (const char *path)
{
- const gchar *mime_type;
- gboolean retval;
-
- mime_type = get_uri_mime_type_full (path);
- retval = FALSE;
-
- if (mime_type == NULL) {
- return retval;
+ switch (get_link_style_for_local_file (path)) {
+ case desktop:
+ return nautilus_link_desktop_file_local_is_trash_link (path);
+ case historical:
+ return nautilus_link_historical_local_is_trash_link (path);
+ default:
+ return FALSE;
}
-
- if (strcmp (mime_type, "application/x-nautilus-link") == 0) {
- retval = nautilus_link_historical_local_is_trash_link (path);
- } else if (strcmp (mime_type, "application/x-gnome-app-info") == 0) {
- retval = nautilus_link_desktop_file_local_is_trash_link (path);
- }
-
- return retval;
}
#if GNOME2_CONVERSION_COMPLETE
void
-nautilus_link_local_create_from_gnome_entry (GnomeDesktopEntry *entry, const char *dest_path, const GdkPoint *position)
+nautilus_link_local_create_from_gnome_entry (GnomeDesktopEntry *entry,
+ const char *dest_path,
+ const GdkPoint *position)
{
nautilus_link_desktop_file_local_create_from_gnome_entry (entry, dest_path, position);
}