mirror of https://github.com/GNOME/gimp.git
app: gimp_image_get/set_imported/exported/save_a_copy_uri()
Add more proper core API for GimpImage URI management.
This commit is contained in:
parent
8d61a61c0e
commit
366cddc856
|
@ -260,10 +260,8 @@ file_actions_update (GimpActionGroup *group,
|
|||
if (image)
|
||||
{
|
||||
drawable = gimp_image_get_active_drawable (image);
|
||||
source = g_object_get_data (G_OBJECT (image),
|
||||
GIMP_FILE_IMPORT_SOURCE_URI_KEY);
|
||||
export = g_object_get_data (G_OBJECT (image),
|
||||
GIMP_FILE_EXPORT_URI_KEY);
|
||||
source = gimp_image_get_imported_uri (image);
|
||||
export = gimp_image_get_exported_uri (image);
|
||||
}
|
||||
|
||||
show_overwrite =
|
||||
|
|
|
@ -288,14 +288,10 @@ file_save_cmd_callback (GtkAction *action,
|
|||
const gchar *uri;
|
||||
GimpPlugInProcedure *export_proc;
|
||||
|
||||
uri = g_object_get_data (G_OBJECT (image),
|
||||
GIMP_FILE_EXPORT_URI_KEY);
|
||||
uri = gimp_image_get_exported_uri (image);
|
||||
|
||||
if (!uri)
|
||||
{
|
||||
uri = g_object_get_data (G_OBJECT (image),
|
||||
GIMP_FILE_IMPORT_SOURCE_URI_KEY);
|
||||
}
|
||||
uri = gimp_image_get_imported_uri (image);
|
||||
|
||||
if (uri)
|
||||
{
|
||||
|
@ -363,8 +359,7 @@ file_revert_cmd_callback (GtkAction *action,
|
|||
|
||||
if (! uri)
|
||||
{
|
||||
uri = g_object_get_data (G_OBJECT (image),
|
||||
GIMP_FILE_IMPORT_SOURCE_URI_KEY);
|
||||
uri = gimp_image_get_imported_uri (image);
|
||||
source = uri;
|
||||
}
|
||||
|
||||
|
@ -665,8 +660,7 @@ file_revert_confirm_response (GtkWidget *dialog,
|
|||
uri = gimp_image_get_uri (old_image);
|
||||
|
||||
if (! uri)
|
||||
uri = g_object_get_data (G_OBJECT (old_image),
|
||||
GIMP_FILE_IMPORT_SOURCE_URI_KEY);
|
||||
uri = gimp_image_get_imported_uri (old_image);
|
||||
|
||||
new_image = file_open_image (gimp, gimp_get_user_context (gimp),
|
||||
GIMP_PROGRESS (display),
|
||||
|
|
|
@ -78,6 +78,11 @@
|
|||
#define TRC(x)
|
||||
#endif
|
||||
|
||||
/* Data keys for GimpImage */
|
||||
#define GIMP_FILE_EXPORT_URI_KEY "gimp-file-export-uri"
|
||||
#define GIMP_FILE_SAVE_A_COPY_URI_KEY "gimp-file-save-a-copy-uri"
|
||||
#define GIMP_FILE_IMPORT_SOURCE_URI_KEY "gimp-file-import-source-uri"
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
|
@ -1584,6 +1589,108 @@ gimp_image_set_filename (GimpImage *image,
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_image_get_imported_uri:
|
||||
* @image: A #GimpImage.
|
||||
*
|
||||
* Returns: The URI of the imported image, or NULL if the image has
|
||||
* been saved as XCF after it was imported.
|
||||
**/
|
||||
const gchar *
|
||||
gimp_image_get_imported_uri (const GimpImage *image)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
||||
|
||||
return g_object_get_data (G_OBJECT (image),
|
||||
GIMP_FILE_IMPORT_SOURCE_URI_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_image_get_exported_uri:
|
||||
* @image: A #GimpImage.
|
||||
*
|
||||
* Returns: The URI of the image last exported from this XCF file, or
|
||||
* NULL if the image has never been exported.
|
||||
**/
|
||||
const gchar *
|
||||
gimp_image_get_exported_uri (const GimpImage *image)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
||||
|
||||
return g_object_get_data (G_OBJECT (image),
|
||||
GIMP_FILE_EXPORT_URI_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_image_get_save_a_copy_uri:
|
||||
* @image: A #GimpImage.
|
||||
*
|
||||
* Returns: The URI of the last copy that was saved of this XCF file.
|
||||
**/
|
||||
const gchar *
|
||||
gimp_image_get_save_a_copy_uri (const GimpImage *image)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
||||
|
||||
return g_object_get_data (G_OBJECT (image),
|
||||
GIMP_FILE_SAVE_A_COPY_URI_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_image_set_imported_uri:
|
||||
* @image: A #GimpImage.
|
||||
* @uri:
|
||||
*
|
||||
* Sets the URI this file was imported from.
|
||||
**/
|
||||
void
|
||||
gimp_image_set_imported_uri (GimpImage *image,
|
||||
const gchar *uri)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_IMAGE (image));
|
||||
|
||||
g_object_set_data_full (G_OBJECT (image), GIMP_FILE_IMPORT_SOURCE_URI_KEY,
|
||||
g_strdup (uri), (GDestroyNotify) g_free);
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_image_set_exported_uri:
|
||||
* @image: A #GimpImage.
|
||||
* @uri:
|
||||
*
|
||||
* Sets the URI this file was last exported to. Note that saving as
|
||||
* XCF is not "exporting".
|
||||
**/
|
||||
void
|
||||
gimp_image_set_exported_uri (GimpImage *image,
|
||||
const gchar *uri)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_IMAGE (image));
|
||||
|
||||
g_object_set_data_full (G_OBJECT (image),
|
||||
GIMP_FILE_EXPORT_URI_KEY,
|
||||
g_strdup (uri), (GDestroyNotify) g_free);
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_image_set_save_a_copy_uri:
|
||||
* @image: A #GimpImage.
|
||||
* @uri:
|
||||
*
|
||||
* Set the URI to the last copy this XCF file was saved to through the
|
||||
* "save a copy" action.
|
||||
**/
|
||||
void
|
||||
gimp_image_set_save_a_copy_uri (GimpImage *image,
|
||||
const gchar *uri)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_IMAGE (image));
|
||||
|
||||
g_object_set_data_full (G_OBJECT (image),
|
||||
GIMP_FILE_SAVE_A_COPY_URI_KEY,
|
||||
g_strdup (uri), (GDestroyNotify) g_free);
|
||||
}
|
||||
|
||||
gchar *
|
||||
gimp_image_get_filename (const GimpImage *image)
|
||||
{
|
||||
|
|
|
@ -170,10 +170,20 @@ gint gimp_image_get_ID (const GimpImage *image);
|
|||
GimpImage * gimp_image_get_by_ID (Gimp *gimp,
|
||||
gint id);
|
||||
|
||||
void gimp_image_set_uri (GimpImage *image,
|
||||
const gchar *uri);
|
||||
const gchar * gimp_image_get_uri (const GimpImage *image);
|
||||
const gchar * gimp_image_get_uri_or_untitled (const GimpImage *image);
|
||||
const gchar * gimp_image_get_imported_uri (const GimpImage *image);
|
||||
const gchar * gimp_image_get_exported_uri (const GimpImage *image);
|
||||
const gchar * gimp_image_get_save_a_copy_uri (const GimpImage *image);
|
||||
|
||||
void gimp_image_set_uri (GimpImage *image,
|
||||
const gchar *uri);
|
||||
void gimp_image_set_imported_uri (GimpImage *image,
|
||||
const gchar *uri);
|
||||
void gimp_image_set_exported_uri (GimpImage *image,
|
||||
const gchar *uri);
|
||||
void gimp_image_set_save_a_copy_uri (GimpImage *image,
|
||||
const gchar *uri);
|
||||
|
||||
void gimp_image_set_filename (GimpImage *image,
|
||||
const gchar *filename);
|
||||
|
|
|
@ -197,11 +197,7 @@ file_save_dialog_response (GtkWidget *save_dialog,
|
|||
* places
|
||||
*/
|
||||
if (dialog->save_a_copy)
|
||||
{
|
||||
g_object_set_data_full (G_OBJECT (dialog->image),
|
||||
GIMP_FILE_SAVE_A_COPY_URI_KEY,
|
||||
g_strdup (uri), (GDestroyNotify) g_free);
|
||||
}
|
||||
gimp_image_set_save_a_copy_uri (dialog->image, uri);
|
||||
|
||||
if (! dialog->export)
|
||||
{
|
||||
|
@ -213,9 +209,7 @@ file_save_dialog_response (GtkWidget *save_dialog,
|
|||
* save as that the user is not interested in being able
|
||||
* to quickly export back to the original any longer
|
||||
*/
|
||||
g_object_set_data (G_OBJECT (dialog->image),
|
||||
GIMP_FILE_IMPORT_SOURCE_URI_KEY,
|
||||
NULL);
|
||||
gimp_image_set_imported_uri (dialog->image, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -228,9 +222,7 @@ file_save_dialog_response (GtkWidget *save_dialog,
|
|||
* happens implicitly when saving since the GimpObject name
|
||||
* of a GimpImage is the last-save URI
|
||||
*/
|
||||
g_object_set_data_full (G_OBJECT (dialog->image),
|
||||
GIMP_FILE_EXPORT_URI_KEY,
|
||||
g_strdup (uri), (GDestroyNotify) g_free);
|
||||
gimp_image_set_exported_uri (dialog->image, uri);
|
||||
}
|
||||
|
||||
g_object_set_data_full (G_OBJECT (dialog->image->gimp),
|
||||
|
|
|
@ -470,12 +470,11 @@ gimp_display_shell_format_filename (gchar *buf,
|
|||
gboolean is_imported = FALSE;
|
||||
gint incr = 0;
|
||||
|
||||
source = g_object_get_data (G_OBJECT (image),
|
||||
GIMP_FILE_IMPORT_SOURCE_URI_KEY);
|
||||
source = gimp_image_get_imported_uri (image);
|
||||
|
||||
/* Note that as soon as the image is saved, it is not considered
|
||||
* imported any longer (GIMP_FILE_IMPORT_SOURCE_URI_KEY is set to
|
||||
* NULL)
|
||||
* imported any longer (gimp_image_set_imported_uri (image, NULL) is
|
||||
* called)
|
||||
*/
|
||||
is_imported = (source != NULL);
|
||||
|
||||
|
@ -498,8 +497,7 @@ gimp_display_shell_format_filename (gchar *buf,
|
|||
if (! gimp_image_is_export_dirty (image))
|
||||
{
|
||||
gboolean is_exported;
|
||||
is_exported = (g_object_get_data (G_OBJECT (image),
|
||||
GIMP_FILE_EXPORT_URI_KEY) != NULL);
|
||||
is_exported = (gimp_image_get_exported_uri (image) != NULL);
|
||||
if (is_exported)
|
||||
export_status = _(" (exported)");
|
||||
else if (is_imported)
|
||||
|
|
|
@ -209,8 +209,7 @@ file_open_image (Gimp *gimp,
|
|||
if (file_open_file_proc_is_import (file_proc))
|
||||
{
|
||||
/* Remember the import source */
|
||||
g_object_set_data_full (G_OBJECT (image), GIMP_FILE_IMPORT_SOURCE_URI_KEY,
|
||||
g_strdup (uri), (GDestroyNotify) g_free);
|
||||
gimp_image_set_imported_uri (image, uri);
|
||||
|
||||
/* We shall treat this file as an Untitled file */
|
||||
gimp_object_set_name (GIMP_OBJECT (image), NULL);
|
||||
|
|
|
@ -26,11 +26,5 @@
|
|||
#define GIMP_FILE_SAVE_LAST_URI_KEY "gimp-file-save-last-uri"
|
||||
#define GIMP_FILE_EXPORT_LAST_URI_KEY "gimp-file-export-last-uri"
|
||||
|
||||
/* Data keys for GimpImage */
|
||||
#define GIMP_FILE_EXPORT_URI_KEY "gimp-file-export-uri"
|
||||
#define GIMP_FILE_SAVE_A_COPY_URI_KEY "gimp-file-save-a-copy-uri"
|
||||
#define GIMP_FILE_IMPORT_SOURCE_URI_KEY "gimp-file-import-source-uri"
|
||||
|
||||
|
||||
|
||||
#endif /* __GIMP_FILE_H__ */
|
||||
|
|
|
@ -519,8 +519,7 @@ gimp_file_dialog_set_save_image (GimpFileDialog *dialog,
|
|||
*/
|
||||
|
||||
if (save_a_copy)
|
||||
dir_uri = g_object_get_data (G_OBJECT (image),
|
||||
GIMP_FILE_SAVE_A_COPY_URI_KEY);
|
||||
dir_uri = gimp_image_get_save_a_copy_uri (image);
|
||||
|
||||
if (! dir_uri)
|
||||
dir_uri = gimp_image_get_uri (image);
|
||||
|
@ -530,8 +529,7 @@ gimp_file_dialog_set_save_image (GimpFileDialog *dialog,
|
|||
"gimp-image-source-uri");
|
||||
|
||||
if (! dir_uri)
|
||||
dir_uri = g_object_get_data (G_OBJECT (image),
|
||||
GIMP_FILE_IMPORT_SOURCE_URI_KEY);
|
||||
dir_uri = gimp_image_get_imported_uri (image);
|
||||
|
||||
if (! dir_uri)
|
||||
dir_uri = g_object_get_data (G_OBJECT (gimp),
|
||||
|
@ -551,19 +549,16 @@ gimp_file_dialog_set_save_image (GimpFileDialog *dialog,
|
|||
*/
|
||||
|
||||
if (save_a_copy)
|
||||
name_uri = g_object_get_data (G_OBJECT (image),
|
||||
GIMP_FILE_SAVE_A_COPY_URI_KEY);
|
||||
name_uri = gimp_image_get_save_a_copy_uri (image);
|
||||
|
||||
if (! name_uri)
|
||||
name_uri = gimp_image_get_uri (image);
|
||||
|
||||
if (! name_uri)
|
||||
name_uri = g_object_get_data (G_OBJECT (image),
|
||||
GIMP_FILE_EXPORT_URI_KEY);
|
||||
name_uri = gimp_image_get_exported_uri (image);
|
||||
|
||||
if (! name_uri)
|
||||
name_uri = g_object_get_data (G_OBJECT (image),
|
||||
GIMP_FILE_IMPORT_SOURCE_URI_KEY);
|
||||
name_uri = gimp_image_get_imported_uri (image);
|
||||
|
||||
if (! name_uri)
|
||||
name_uri = gimp_image_get_string_untitled ();
|
||||
|
@ -592,16 +587,14 @@ gimp_file_dialog_set_save_image (GimpFileDialog *dialog,
|
|||
* 6. The OS 'Documents' path
|
||||
*/
|
||||
|
||||
dir_uri = g_object_get_data (G_OBJECT (image),
|
||||
GIMP_FILE_EXPORT_URI_KEY);
|
||||
dir_uri = gimp_image_get_exported_uri (image);
|
||||
|
||||
if (! dir_uri)
|
||||
dir_uri = g_object_get_data (G_OBJECT (image),
|
||||
"gimp-image-source-uri");
|
||||
|
||||
if (! dir_uri)
|
||||
dir_uri = g_object_get_data (G_OBJECT (image),
|
||||
GIMP_FILE_IMPORT_SOURCE_URI_KEY);
|
||||
dir_uri = gimp_image_get_imported_uri (image);
|
||||
|
||||
if (! dir_uri)
|
||||
dir_uri = gimp_image_get_uri (image);
|
||||
|
@ -626,15 +619,13 @@ gimp_file_dialog_set_save_image (GimpFileDialog *dialog,
|
|||
* 3. 'Untitled'
|
||||
*/
|
||||
|
||||
name_uri = g_object_get_data (G_OBJECT (image),
|
||||
GIMP_FILE_EXPORT_URI_KEY);
|
||||
name_uri = gimp_image_get_exported_uri (image);
|
||||
|
||||
if (! name_uri)
|
||||
name_uri = gimp_image_get_uri (image);
|
||||
|
||||
if (! name_uri)
|
||||
name_uri = g_object_get_data (G_OBJECT (image),
|
||||
GIMP_FILE_IMPORT_SOURCE_URI_KEY);
|
||||
name_uri = gimp_image_get_imported_uri (image);
|
||||
|
||||
if (! name_uri)
|
||||
name_uri = gimp_image_get_string_untitled ();
|
||||
|
@ -646,8 +637,7 @@ gimp_file_dialog_set_save_image (GimpFileDialog *dialog,
|
|||
* 3. Type of latest Export of any document
|
||||
* 2. .png
|
||||
*/
|
||||
ext_uri = g_object_get_data (G_OBJECT (image),
|
||||
GIMP_FILE_EXPORT_URI_KEY);
|
||||
ext_uri = gimp_image_get_exported_uri (image);
|
||||
|
||||
if (! ext_uri)
|
||||
ext_uri = g_object_get_data (G_OBJECT (gimp),
|
||||
|
|
Loading…
Reference in New Issue