char * mn_vfs_uri_extract_short_name (const char *text_uri) { GnomeVFSURI *uri; char *name; g_return_val_if_fail(text_uri != NULL, NULL); uri = gnome_vfs_uri_new(text_uri); if (! uri) return NULL; name = gnome_vfs_uri_extract_short_name(uri); gnome_vfs_uri_unref(uri); return name; }
static GnomeVFSResult do_get_file_info ( GnomeVFSMethod* method, GnomeVFSURI* uri, GnomeVFSFileInfo* info, GnomeVFSFileInfoOptions options, GnomeVFSContext* context) { GnomeVFSResult result; GnomeVFSURI *parent; Camera *camera; CameraFileInfo camera_info; CameraList *list; const gchar *path, *name; char *basename; guint i; int count; printf ("ENTER: do_get_file_info (%s)\n", camera_uri_get_path (uri)); G_LOCK (cameras); /* Is this root? */ if (!gnome_vfs_uri_has_parent (uri)) { info->name = g_strdup ("/"); info->valid_fields = GNOME_VFS_FILE_INFO_FIELDS_TYPE | GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE; info->type = GNOME_VFS_FILE_TYPE_DIRECTORY; info->mime_type = g_strdup ("x-directory/normal"); G_UNLOCK (cameras); return (GNOME_VFS_OK); } printf ("Getting camera (do_get_file_info)...\n"); result = get_camera (uri, &camera); if (result != GNOME_VFS_OK) { G_UNLOCK (cameras); return (result); } result = GNOME_VFS_RESULT (gp_list_new (&list)); if (result != GNOME_VFS_OK) { unref_camera (camera); G_UNLOCK (cameras); return (result); } /* * We cannot use get_basename here because of potential trailing * slashes. */ basename = gnome_vfs_uri_extract_short_name (uri); parent = camera_uri_get_parent (uri); path = camera_uri_get_path (parent); result = GNOME_VFS_RESULT (gp_camera_folder_list_folders (camera, path, list, NULL)); if (result != GNOME_VFS_OK) { gnome_vfs_uri_unref (parent); unref_camera (camera); gp_list_free (list); g_free (basename); G_UNLOCK (cameras); return (result); } count = gp_list_count (list); if (count < 0) { gnome_vfs_uri_unref (parent); unref_camera (camera); gp_list_free (list); g_free (basename); G_UNLOCK (cameras); return (GNOME_VFS_RESULT (count)); } for (i = 0; i < count; i++) { result = GNOME_VFS_RESULT (gp_list_get_name (list, i, &name)); if (result != GNOME_VFS_OK) { gnome_vfs_uri_unref (parent); unref_camera (camera); gp_list_free (list); g_free (basename); G_UNLOCK (cameras); return (result); } if (!strcmp (name, basename)) { info->name = g_strdup (basename); info->valid_fields = GNOME_VFS_FILE_INFO_FIELDS_TYPE | GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE; info->type = GNOME_VFS_FILE_TYPE_DIRECTORY; info->mime_type = g_strdup ("x-directory/normal"); gnome_vfs_uri_unref (parent); unref_camera (camera); gp_list_free (list); g_free (basename); G_UNLOCK (cameras); printf ("Found folder!\n"); return (GNOME_VFS_OK); } } result = GNOME_VFS_RESULT (gp_camera_folder_list_files (camera, path, list, NULL)); if (result != GNOME_VFS_OK) { gnome_vfs_uri_unref (parent); unref_camera (camera); gp_list_free (list); g_free (basename); G_UNLOCK (cameras); return (result); } count = gp_list_count (list); if (count < 0) { gnome_vfs_uri_unref (parent); unref_camera (camera); gp_list_free (list); g_free (basename); G_UNLOCK (cameras); return (GNOME_VFS_RESULT (count)); } for (i = 0; i < count; i++) { result = GNOME_VFS_RESULT (gp_list_get_name (list, i, &name)); if (result != GNOME_VFS_OK) { gnome_vfs_uri_unref (parent); unref_camera (camera); gp_list_free (list); g_free (basename); G_UNLOCK (cameras); return (result); } if (!strcmp (name, basename)) { result = GNOME_VFS_RESULT (gp_camera_file_get_info ( camera, path, basename, &camera_info, NULL)); g_free (basename); unref_camera (camera); gp_list_free (list); if (result != GNOME_VFS_OK) { G_UNLOCK (cameras); return (result); } get_info_from_camera_info (&camera_info, FALSE, info); gnome_vfs_uri_unref (parent); G_UNLOCK (cameras); printf ("Found file!\n"); return (GNOME_VFS_OK); } } gnome_vfs_uri_unref (parent); g_free (basename); unref_camera (camera); gp_list_free (list); G_UNLOCK (cameras); return (GNOME_VFS_ERROR_NOT_FOUND); }