コード例 #1
0
void
gimp_export_dialog_set_image (GimpExportDialog *dialog,
                              Gimp             *gimp,
                              GimpImage        *image)
{
  GFile *dir_file  = NULL;
  GFile *name_file = NULL;
  GFile *ext_file  = NULL;
  gchar *basename;

  g_return_if_fail (GIMP_IS_EXPORT_DIALOG (dialog));
  g_return_if_fail (GIMP_IS_IMAGE (image));

  GIMP_FILE_DIALOG (dialog)->image = image;

  gimp_file_dialog_set_file_proc (GIMP_FILE_DIALOG (dialog), NULL);

  /*
   * Priority of default paths for Export:
   *
   *   1. Last Export path
   *   2. Path of import source
   *   3. Path of XCF source
   *   4. Last path of any save to XCF
   *   5. Last Export path of any document
   *   6. The default path (usually the OS 'Documents' path)
   */

  dir_file = gimp_image_get_exported_file (image);

  if (! dir_file)
    dir_file = g_object_get_data (G_OBJECT (image),
                                  "gimp-image-source-file");

  if (! dir_file)
    dir_file = gimp_image_get_imported_file (image);

  if (! dir_file)
    dir_file = gimp_image_get_file (image);

  if (! dir_file)
    dir_file = g_object_get_data (G_OBJECT (gimp),
                                  GIMP_FILE_SAVE_LAST_FILE_KEY);

  if (! dir_file)
    dir_file = g_object_get_data (G_OBJECT (gimp),
                                  GIMP_FILE_EXPORT_LAST_FILE_KEY);

  if (! dir_file)
    dir_file = gimp_export_dialog_get_default_folder (gimp);

  /* Priority of default basenames for Export:
   *
   *   1. Last Export name
   *   3. Save URI
   *   2. Source file name
   *   3. 'Untitled'
   */

  name_file = gimp_image_get_exported_file (image);

  if (! name_file)
    name_file = gimp_image_get_file (image);

  if (! name_file)
    name_file = gimp_image_get_imported_file (image);

  if (! name_file)
    name_file = gimp_image_get_untitled_file (image);


  /* Priority of default type/extension for Export:
   *
   *   1. Type of last Export
   *   2. Type of the image Import
   *   3. Type of latest Export of any document
   *   4. .png
   */
  ext_file = gimp_image_get_exported_file (image);

  if (! ext_file)
    ext_file = gimp_image_get_imported_file (image);

  if (! ext_file)
    ext_file = g_object_get_data (G_OBJECT (gimp),
                                  GIMP_FILE_EXPORT_LAST_FILE_KEY);

  if (ext_file)
    g_object_ref (ext_file);
  else
    ext_file = g_file_new_for_uri ("file:///we/only/care/about/extension.png");

  if (ext_file)
    {
      GFile *tmp_file = file_utils_file_with_new_ext (name_file, ext_file);
      basename = g_path_get_basename (gimp_file_get_utf8_name (tmp_file));
      g_object_unref (tmp_file);
      g_object_unref (ext_file);
    }
  else
    {
      basename = g_path_get_basename (gimp_file_get_utf8_name (name_file));
    }

  if (g_file_query_file_type (dir_file, G_FILE_QUERY_INFO_NONE, NULL) ==
      G_FILE_TYPE_DIRECTORY)
    {
      gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (dialog),
                                                dir_file, NULL);
    }
  else
    {
      GFile *parent_file = g_file_get_parent (dir_file);
      gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (dialog),
                                                parent_file, NULL);
      g_object_unref (parent_file);
    }

  gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), basename);
}
コード例 #2
0
ファイル: gimpfiledialog.c プロジェクト: Amerekanets/gimp
void
gimp_file_dialog_set_image (GimpFileDialog *dialog,
                            GimpImage      *image,
                            gboolean        save_a_copy,
                            gboolean        close_after_saving)
{
  const gchar *uri = NULL;
  gchar       *dirname;
  gchar       *basename;

  g_return_if_fail (GIMP_IS_FILE_DIALOG (dialog));
  g_return_if_fail (GIMP_IS_IMAGE (image));

  dialog->image              = image;
  dialog->save_a_copy        = save_a_copy;
  dialog->close_after_saving = close_after_saving;

  if (save_a_copy)
    uri = g_object_get_data (G_OBJECT (image), "gimp-image-save-a-copy");

  if (! uri)
    uri = gimp_image_get_uri (image);

  gimp_file_dialog_set_file_proc (dialog, NULL);

#ifndef G_OS_WIN32
  dirname  = g_path_get_dirname (uri);
#else
  /* g_path_get_dirname() is supposed to work on pathnames, not URIs.
   *
   * If uri points to a file on the root of a drive
   * "file:///d:/foo.png", g_path_get_dirname() would return
   * "file:///d:". (What we really would want is "file:///d:/".) When
   * this then is passed inside gtk+ to g_filename_from_uri() we get
   * "d:" which is not an absolute pathname. This currently causes an
   * assertion failure in gtk+. This scenario occurs if we have opened
   * an image from the root of a drive and then do Save As.
   *
   * Of course, gtk+ shouldn't assert even if we feed it slighly bogus
   * data, and that problem should be fixed, too. But to get the
   * correct default current folder in the filechooser combo box, we
   * need to pass it the proper URI for an absolute path anyway. So
   * don't use g_path_get_dirname() on file: URIs.
   */
  if (g_str_has_prefix (uri, "file:///"))
    {
      gchar *filepath = g_filename_from_uri (uri, NULL, NULL);
      gchar *dirpath  = NULL;

      if (filepath != NULL)
	{
	  dirpath = g_path_get_dirname (filepath);
	  g_free (filepath);
	}

      if (dirpath != NULL)
	{
	  dirname = g_filename_to_uri (dirpath, NULL, NULL);
	  g_free (dirpath);
	}
      else
        {
          dirname = NULL;
        }
    }
  else
    {
      dirname = g_path_get_dirname (uri);
    }
#endif

  if (dirname && strlen (dirname) && strcmp (dirname, "."))
    {
      gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dialog),
                                               dirname);
    }
  else
    {
      const gchar *folder;

      folder = g_object_get_data (G_OBJECT (image), "gimp-image-dirname");

      if (folder)
        gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), folder);
    }

  g_free (dirname);

  basename = file_utils_uri_display_basename (uri);
  gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), basename);
  g_free (basename);
}