Exemple #1
0
gchar *
file_utils_filename_to_uri (Gimp         *gimp,
                            const gchar  *filename,
                            GError      **error)
{
    GError *temp_error = NULL;
    gchar  *absolute;
    gchar  *uri;

    g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
    g_return_val_if_fail (filename != NULL, NULL);
    g_return_val_if_fail (error == NULL || *error == NULL, NULL);

    /*  check for prefixes like http or ftp  */
    if (file_procedure_find_by_prefix (gimp->plug_in_manager->load_procs,
                                       filename))
    {
        if (g_utf8_validate (filename, -1, NULL))
        {
            return g_strdup (filename);
        }
        else
        {
            g_set_error_literal (error,
                                 G_CONVERT_ERROR,
                                 G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
                                 _("Invalid character sequence in URI"));
            return NULL;
        }
    }
    else if (file_utils_filename_is_uri (filename, &temp_error))
    {
        return g_strdup (filename);
    }
    else if (temp_error)
    {
        g_propagate_error (error, temp_error);

        return NULL;
    }

    if (! g_path_is_absolute (filename))
    {
        gchar *current;

        current = g_get_current_dir ();
        absolute = g_build_filename (current, filename, NULL);
        g_free (current);
    }
    else
    {
        absolute = g_strdup (filename);
    }

    uri = g_filename_to_uri (absolute, NULL, error);

    g_free (absolute);

    return uri;
}
Exemple #2
0
static gchar *
gimp_unique_filename_to_uri (const gchar  *filename,
                             const gchar  *cwd,
                             GError      **error)
{
    gchar *uri = NULL;

    if (file_utils_filename_is_uri (filename, error))
    {
        uri = g_strdup (filename);
    }
    else if (! *error)
    {
        if (! g_path_is_absolute (filename))
        {
            gchar *absolute = g_build_filename (cwd, filename, NULL);

            uri = g_filename_to_uri (absolute, NULL, error);

            g_free (absolute);
        }
        else
        {
            uri = g_filename_to_uri (filename, NULL, error);
        }
    }

    return uri;
}
Exemple #3
0
GFile *
file_utils_filename_to_file (Gimp         *gimp,
                             const gchar  *filename,
                             GError      **error)
{
  GFile  *file;
  gchar  *absolute;
  GError *temp_error = NULL;

  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
  g_return_val_if_fail (filename != NULL, NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  file = g_file_new_for_uri (filename);

  /*  check for prefixes like http or ftp  */
  if (gimp_plug_in_manager_file_procedure_find_by_prefix (gimp->plug_in_manager,
                                                          GIMP_FILE_PROCEDURE_GROUP_OPEN,
                                                          file))
    {
      if (g_utf8_validate (filename, -1, NULL))
        {
          return file;
        }
      else
        {
          g_set_error_literal (error,
			       G_CONVERT_ERROR,
			       G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
			       _("Invalid character sequence in URI"));
          return NULL;
        }
    }
  else if (file_utils_filename_is_uri (filename, &temp_error))
    {
      return file;
    }
  else if (temp_error)
    {
      g_propagate_error (error, temp_error);
      g_object_unref (file);

      return NULL;
    }

  g_object_unref (file);

  if (! g_path_is_absolute (filename))
    {
      gchar *current;

      current = g_get_current_dir ();
      absolute = g_build_filename (current, filename, NULL);
      g_free (current);
    }
  else
    {
      absolute = g_strdup (filename);
    }

  file = g_file_new_for_path (absolute);

  g_free (absolute);

  return file;
}