/**
 * Load the .desktop file using GNOME VFS.
 * @param uri
 * @param err if non-null, this will contain an error in the domain LAUNCHER_ERROR
 * @return desktop file or null
 */
static GnomeDesktopFile *load_desktop_file(const char *uri, GError **err)
{
        GnomeDesktopFile *retval;
        GError *gnome_err = NULL;
        char *path;

        g_return_val_if_fail(uri, NULL);
        g_return_val_if_fail(err==NULL || *err==NULL, NULL);

        path=gnome_vfs_get_local_path_from_uri(uri);
        if(path==NULL) {
                g_set_error(err,
                            LAUNCHER_ERROR,
                            LAUNCHER_INVALID_URI,
                            "Error parsing %s: not a local file",
                            uri);
                g_error_free(gnome_err);
        }

        retval = gnome_desktop_file_load(path, err==NULL ? NULL:&gnome_err);

        if(gnome_err) {
                g_set_error(err,
                            LAUNCHER_ERROR,
                            LAUNCHER_INVALID_URI,
                            "Error parsing %s: %s",
                            uri,
                            gnome_err->message);
                g_error_free(gnome_err);
        }
        g_assert(retval!=NULL || err==NULL || *err!=NULL);
        return retval;
}
/** 
 * gnome_vfs_volume_unmount:
 * @volume: the #GnomeVFSVolume that should be unmounted.
 * @callback: the #GnomeVFSVolumeOpCallback that should be invoked after unmounting @volume.
 * @user_data: the user data to pass to @callback.
 *
 * Note that gnome_vfs_volume_unmount() may also invoke gnome_vfs_volume_eject(),
 * if the @volume signals that it should be ejected when it is unmounted.
 * This may be true for CD-ROMs, USB sticks and other devices, depending on the
 * backend providing the @volume.
 *
 * Since: 2.6
 */
void
gnome_vfs_volume_unmount (GnomeVFSVolume *volume,
			  GnomeVFSVolumeOpCallback  callback,
			  gpointer                   user_data)
{
	char *mount_path, *device_path;
	char *uri;
	GnomeVFSVolumeType type;

	if (volume->priv->drive != NULL) {
		if (volume->priv->drive->priv->must_eject_at_unmount) {
			gnome_vfs_volume_eject (volume, callback, user_data);
			return;
		}
	}

	emit_pre_unmount (volume);

	type = gnome_vfs_volume_get_volume_type (volume);
	if (type == GNOME_VFS_VOLUME_TYPE_MOUNTPOINT) {
		char *hal_udi;

		uri = gnome_vfs_volume_get_activation_uri (volume);
		mount_path = gnome_vfs_get_local_path_from_uri (uri);
		g_free (uri);
		device_path = gnome_vfs_volume_get_device_path (volume);
		hal_udi = gnome_vfs_volume_get_hal_udi (volume);

		/* Volumes from drives that are not polled may not
		 * have a hal_udi.. take the one from HAL to get
		 * gnome-mount working */
		if (hal_udi == NULL) {
			GnomeVFSDrive *drive;
			drive = gnome_vfs_volume_get_drive (volume);
			if (drive != NULL) {
				hal_udi = gnome_vfs_drive_get_hal_udi (drive);
				gnome_vfs_drive_unref (drive);
			}
		}

		mount_unmount_operation (mount_path,
					 device_path,
					 hal_udi,
					 gnome_vfs_volume_get_device_type (volume),
					 FALSE, TRUE, FALSE,
					 callback, user_data);
		g_free (mount_path);
		g_free (device_path);
		g_free (hal_udi);
	} else if (type == GNOME_VFS_VOLUME_TYPE_VFS_MOUNT) {
		/* left intentionally blank as these cannot be mounted and thus not unmounted */
	} else if (type == GNOME_VFS_VOLUME_TYPE_CONNECTED_SERVER) {
		unmount_connected_server (volume, callback, user_data);
	}
}
Example #3
0
char *
mn_vfs_get_local_path (GnomeVFSURI *uri)
{
  char *text_uri;
  char *path;

  g_return_val_if_fail(uri != NULL, NULL);

  text_uri = gnome_vfs_uri_to_string(uri, GNOME_VFS_URI_HIDE_NONE);
  path = gnome_vfs_get_local_path_from_uri(text_uri);
  g_free(text_uri);

  return path;
}
/** 
 * gnome_vfs_drive_eject:
 * @drive: the #GnomeVFSDrive that should be ejcted.
 * @callback: the #GnomeVFSVolumeOpCallback that should be invoked after ejecting @drive.
 * @user_data: the user data to pass to @callback.
 *
 * If @drive has associated #GnomeVFSVolume objects, all of them will be
 * unmounted by calling gnome_vfs_volume_unmount() for each volume in
 * gnome_vfs_drive_get_mounted_volumes(), except for the last one,
 * for which gnome_vfs_volume_eject() is called to ensure that the
 * @drive's media is ejected.
 *
 * If @drive however has no associated #GnomeVFSVolume objects, it
 * simply calls an unmount helper on the @drive.
 *
 * Since: 2.6
 */
void
gnome_vfs_drive_eject (GnomeVFSDrive  *drive,
		       GnomeVFSVolumeOpCallback  callback,
		       gpointer                   user_data)
{
	GList *vol_list;
	GList * current_vol;

	vol_list = gnome_vfs_drive_get_mounted_volumes (drive);

	for (current_vol = vol_list; current_vol != NULL; current_vol = current_vol->next) {
		GnomeVFSVolume *vol;
		vol = GNOME_VFS_VOLUME (current_vol->data);

		/* Check to see if this is the last volume */
		/* If not simply unmount it */
		/* If so the eject the media along with the unmount */
		if (current_vol->next != NULL) { 
			gnome_vfs_volume_unmount (vol,
						  callback,
						  user_data);
		} else { 
			gnome_vfs_volume_eject (vol,
						callback,
						user_data);
		}

	}

	if (vol_list == NULL) { /* no mounted volumes */
		char *mount_path, *device_path, *uri;
	
		uri = gnome_vfs_drive_get_activation_uri (drive);
		mount_path = gnome_vfs_get_local_path_from_uri (uri);
		g_free (uri);
		device_path = gnome_vfs_drive_get_device_path (drive);
		mount_unmount_operation (mount_path,
					 device_path,
					 gnome_vfs_drive_get_hal_udi (drive),
					 GNOME_VFS_DEVICE_TYPE_UNKNOWN,
					 FALSE, FALSE, TRUE,
					 callback, user_data);
		g_free (mount_path);
		g_free (device_path);
	}

	gnome_vfs_drive_volume_list_free (vol_list);
}
Example #5
0
/**
 * create_full_path:
 * @filename: a gchar * with the (relative or not) filename
 * @basedir: a gchar * with a basedir or NULL for current dir
 *
 * if filename is already absolute, it returns it
 * else it will use basedir if available, else the current dir
 * to add to the filename to form the full path
 *
 * for URL's it will simply return a strdup(), except for file:// URL's, 
 * there the file:// bit is stripped and 
 * IF YOU HAVE GNOME_VFS any %XX sequenves are converted
 * so if you DON'T have gnome_vfs, you should not feed file:// uri's!!
 *
 * it does use most_efficient_filename() to remote unwanted dir/../ entries
 *
 * Return value: a newly allocated gchar * with the full path
 **/
gchar *create_full_path(const gchar * filename, const gchar *basedir) {
	gchar *absolute_filename;
	gchar *tmpcdir;

	if (!filename) return NULL;
	DEBUG_MSG("create_full_path, filename=%s, basedir=%s\n", filename, basedir);
#ifdef STRIP_FILE_URI
	if (strchr(filename, ':') != NULL) { /* it is an URI!! */
		DEBUG_MSG("create_full_path, %s is an URI\n",filename);
		if (strncmp(filename, "file://", 7)==0) {
#ifdef HAVE_GNOME_VFS
			return gnome_vfs_get_local_path_from_uri(filename);
#else
			/* THIS IS A BUG, IF YOU DON'T HAVE GNOME_VFS BUT YOU DO HAVE 
			GTK-2.4 A %21 OR SOMETHING LIKE THAT IS NOW NOT CONVERTED !!!!!!!!! */
#ifdef WIN32
			return g_strdup(bf_strrepl(filename+7,"%20"," "));
#endif
			return g_strdup(filename+7); /* file:// URI's are never relative paths */
#endif
		}
#ifdef WIN32
		return g_strdup(bf_strrepl(filename,"%20"," "));
#endif
		return g_strdup(filename); /* cannot do this on remote paths */
	}
#endif /* HAVE_GNOME_VFS */
	if (g_path_is_absolute(filename)) {
		absolute_filename = g_strdup(filename);
	} else {
		if (basedir) {
			tmpcdir = ending_slash(basedir);
		} else {
			gchar *curdir = g_get_current_dir();
			tmpcdir = ending_slash(curdir);
			g_free(curdir);
		}
		absolute_filename = g_strconcat(tmpcdir, filename, NULL);
		g_free(tmpcdir);
	}
	absolute_filename = most_efficient_filename(absolute_filename);
#ifdef WIN32
			return g_strdup(bf_strrepl(absolute_filename,"%20"," "));
#endif
	return absolute_filename;
}
/** 
 * gnome_vfs_drive_mount:
 * @drive: the #GnomeVFSDrive that should be mounted.
 * @callback: the #GnomeVFSVolumeOpCallback that should be invoked after mounting @drive.
 * @user_data: the user data to pass to @callback.
 *
 * Since: 2.6
 */
void
gnome_vfs_drive_mount (GnomeVFSDrive  *drive,
		       GnomeVFSVolumeOpCallback  callback,
		       gpointer                   user_data)
{
	char *mount_path, *device_path, *uri;

	uri = gnome_vfs_drive_get_activation_uri (drive);
	mount_path = gnome_vfs_get_local_path_from_uri (uri);
	g_free (uri);
	device_path = gnome_vfs_drive_get_device_path (drive);
	mount_unmount_operation (mount_path,
				 device_path,
				 gnome_vfs_drive_get_hal_udi (drive),
				 gnome_vfs_drive_get_device_type (drive),
				 TRUE, FALSE, FALSE,
				 callback, user_data);
	g_free (mount_path);
	g_free (device_path);
}
/** 
 * gnome_vfs_volume_eject:
 * @volume: the #GnomeVFSVolume that should be ejected.
 * @callback: the #GnomeVFSVolumeOpCallback that should be invoked after ejecting of @volume.
 * @user_data: the user data to pass to @callback.
 *
 * Requests ejection of a #GnomeVFSVolume.
 *
 * Before the unmount operation is executed, the
 * #GnomeVFSVolume::pre-unmount signal is emitted.
 *
 * If the @volume is a mount point (its type is
 * #GNOME_VFS_VOLUME_TYPE_MOUNTPOINT), it is unmounted,
 * and if it refers to a disc, it is also ejected.
 *
 * If the @volume is a special VFS mount, i.e.
 * its type is #GNOME_VFS_VOLUME_TYPE_VFS_MOUNT, it
 * is ejected.
 *
 * If the @volume is a connected server, it
 * is removed from the list of connected servers.
 *
 * Otherwise, no further action is done.
 *
 * Since: 2.6
 */
void
gnome_vfs_volume_eject (GnomeVFSVolume *volume,
			GnomeVFSVolumeOpCallback  callback,
			gpointer                   user_data)
{
	char *mount_path, *device_path;
	char *uri;
	char *hal_udi;
	GnomeVFSVolumeType type;
	
	emit_pre_unmount (volume);

	type = gnome_vfs_volume_get_volume_type (volume);
	if (type == GNOME_VFS_VOLUME_TYPE_MOUNTPOINT) {
		uri = gnome_vfs_volume_get_activation_uri (volume);
		mount_path = gnome_vfs_get_local_path_from_uri (uri);
		g_free (uri);
		device_path = gnome_vfs_volume_get_device_path (volume);
		hal_udi = gnome_vfs_volume_get_hal_udi (volume);

		/* Volumes from drives that are not polled may not
		 * have a hal_udi.. take the one from HAL to get
		 * gnome-mount working */
		if (hal_udi == NULL) {
			GnomeVFSDrive *drive;
			drive = gnome_vfs_volume_get_drive (volume);
			if (drive != NULL) {
				hal_udi = gnome_vfs_drive_get_hal_udi (drive);
				gnome_vfs_drive_unref (drive);
			}
		}

		mount_unmount_operation (mount_path,
					 device_path,
					 hal_udi,
					 gnome_vfs_volume_get_device_type (volume),
					 FALSE, TRUE, TRUE,
					 callback, user_data);
		g_free (mount_path);
		g_free (device_path);
		g_free (hal_udi);
	} else if (type == GNOME_VFS_VOLUME_TYPE_VFS_MOUNT) {
		hal_udi = gnome_vfs_volume_get_hal_udi (volume);
		uri = gnome_vfs_volume_get_activation_uri (volume);
		device_path = gnome_vfs_volume_get_device_path (volume);

		/* special handling for optical disc VFS_MOUNT created by the hal backend */
		if (hal_udi != NULL &&
		    (g_str_has_prefix (uri, "cdda://") || g_str_has_prefix (uri, "burn:///"))) {
			device_path = gnome_vfs_volume_get_device_path (volume);
			mount_unmount_operation (NULL,
						 device_path,
						 hal_udi,
						 gnome_vfs_volume_get_device_type (volume),
						 FALSE, FALSE, TRUE,
						 callback, user_data);
			g_free (device_path);
		    }
		g_free (uri);
		g_free (hal_udi);
	} else if (type == GNOME_VFS_VOLUME_TYPE_CONNECTED_SERVER) {
		unmount_connected_server (volume, callback, user_data);
	}
}