static gboolean
gst_gnome_vfs_sink_open_file (GstGnomeVFSSink * sink)
{
    GnomeVFSResult result;

    if (sink->uri) {
        /* open the file, all permissions, umask will apply */
        result = gnome_vfs_create_uri (&(sink->handle), sink->uri,
                                       GNOME_VFS_OPEN_WRITE, TRUE,
                                       GNOME_VFS_PERM_USER_READ | GNOME_VFS_PERM_USER_WRITE |
                                       GNOME_VFS_PERM_GROUP_READ | GNOME_VFS_PERM_GROUP_WRITE |
                                       GNOME_VFS_PERM_OTHER_READ | GNOME_VFS_PERM_OTHER_WRITE);

        /* if the file existed and the property says to ask, then ask! */
        if (result == GNOME_VFS_ERROR_FILE_EXISTS) {
            gboolean erase_anyway = FALSE;

            g_signal_emit (G_OBJECT (sink),
                           gst_gnome_vfs_sink_signals[SIGNAL_ERASE_ASK], 0, sink->uri,
                           &erase_anyway);
            if (erase_anyway) {
                result = gnome_vfs_create_uri (&(sink->handle), sink->uri,
                                               GNOME_VFS_OPEN_WRITE, FALSE,
                                               GNOME_VFS_PERM_USER_READ | GNOME_VFS_PERM_USER_WRITE |
                                               GNOME_VFS_PERM_GROUP_READ | GNOME_VFS_PERM_GROUP_WRITE |
                                               GNOME_VFS_PERM_OTHER_READ | GNOME_VFS_PERM_OTHER_WRITE);
            }
        }

        GST_DEBUG_OBJECT (sink, "open: %s", gnome_vfs_result_to_string (result));

        if (result != GNOME_VFS_OK) {
            gchar *filename = gnome_vfs_uri_to_string (sink->uri,
                              GNOME_VFS_URI_HIDE_PASSWORD);

            GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE,
                               (_("Could not open vfs file \"%s\" for writing: %s."),
                                filename, gnome_vfs_result_to_string (result)), GST_ERROR_SYSTEM);
            g_free (filename);
            return FALSE;
        }
        sink->own_handle = TRUE;
    } else if (!sink->handle) {
        GST_ELEMENT_ERROR (sink, RESOURCE, FAILED, (_("No filename given")),
                           (NULL));
        return FALSE;
    } else {
        sink->own_handle = FALSE;
    }

    sink->current_pos = 0;

    return TRUE;
}
Example #2
0
GnomeVFSResult
mn_vfs_write_entire_file_uri (GnomeVFSURI *uri,
			      gsize file_size,
			      const char *file_contents,
			      gboolean exclusive,
			      unsigned int perms)
{
  GnomeVFSHandle *handle;
  GnomeVFSResult result;
  GnomeVFSFileSize bytes_written = 0;

  result = gnome_vfs_create_uri(&handle, uri, GNOME_VFS_OPEN_WRITE | GNOME_VFS_OPEN_TRUNCATE, exclusive, perms);
  if (result != GNOME_VFS_OK)
    return result;

  while (bytes_written < file_size)
    {
      GnomeVFSFileSize this_bytes_written;

      result = gnome_vfs_write(handle, file_contents + bytes_written, file_size - bytes_written, &this_bytes_written);
      if (result != GNOME_VFS_OK)
	{
	  gnome_vfs_close(handle);
	  return result;
	}

      bytes_written += this_bytes_written;
    }

  return gnome_vfs_close(handle);
}
static gboolean
write_theme_to_disk (GnomeThemeMetaInfo  *theme_info,
		     const gchar         *theme_name,
		     const gchar         *theme_description,
		     gboolean		  save_background,
		     GError             **error)
{
  gchar *dir, *theme_name_dir;
  GnomeVFSURI *uri;
  GnomeVFSURI *target_uri;
  GnomeVFSHandle *handle = NULL;
  GnomeVFSFileSize bytes_written;
  gchar *str, *current_background;
  GConfClient *client;
  const gchar *theme_header =
      "[Desktop Entry]\n"
      "Name=%s\n"
      "Type=X-GNOME-Metatheme\n"
      "Comment=%s\n"
      "\n"
      "[X-GNOME-Metatheme]\n"
      "GtkTheme=%s\n"
      "MetacityTheme=%s\n"
      "IconTheme=%s\n";

  theme_name_dir = str_remove_slash (theme_name);
  dir = g_build_filename (g_get_home_dir (), ".themes", theme_name_dir, "index.theme~", NULL);
  g_free (theme_name_dir);

  uri = gnome_vfs_uri_new (dir);
  dir [strlen (dir) - 1] = '\000';
  target_uri = gnome_vfs_uri_new (dir);
  g_free (dir);
  gnome_vfs_create_uri (&handle, uri, GNOME_VFS_OPEN_READ | GNOME_VFS_OPEN_WRITE, FALSE, 0644);

  gnome_vfs_truncate_handle (handle, 0);

  /* start making the theme file */
  str = g_strdup_printf (theme_header, theme_name, theme_description,
			 theme_info->gtk_theme_name,
			 theme_info->metacity_theme_name,
			 theme_info->icon_theme_name);
  gnome_vfs_write (handle, str, strlen (str), &bytes_written);
  g_free (str);

  if (theme_info->gtk_color_scheme) {
    gchar *a, *tmp;
    tmp = g_strdup (theme_info->gtk_color_scheme);
    for (a = tmp; *a != '\0'; a++)
      if (*a == '\n')
        *a = ',';
    str = g_strdup_printf ("GtkColorScheme=%s\n", tmp);
    gnome_vfs_write (handle, str, strlen (str), &bytes_written);
    g_free (str);
    g_free (tmp);
  }

  if (theme_info->cursor_theme_name) {
#ifdef HAVE_XCURSOR
    str = g_strdup_printf ("CursorTheme=%s\n"
                           "CursorSize=%i\n",
                           theme_info->cursor_theme_name,
                           theme_info->cursor_size);
#else
    str = g_strdup_printf ("CursorFont=%s\n", theme_info->cursor_theme_name);
#endif
    gnome_vfs_write (handle, str, strlen (str), &bytes_written);
    g_free (str);
  }

  if (save_background) {
    client = gconf_client_get_default ();
    current_background = gconf_client_get_string (client, BACKGROUND_KEY, NULL);

    if (current_background != NULL) {
      str = g_strdup_printf ("BackgroundImage=%s\n", current_background);

      gnome_vfs_write (handle, str, strlen (str), &bytes_written);

      g_free (current_background);
      g_free (str);
    }
    g_object_unref (client);
  }

  gnome_vfs_close (handle);

  gnome_vfs_move_uri (uri, target_uri, TRUE);
  gnome_vfs_uri_unref (uri);
  gnome_vfs_uri_unref (target_uri);

  return TRUE;
}