From 366cddc856eb300d598d28ee9523b0bcaee622c3 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Wed, 26 Jan 2011 20:45:32 +0100 Subject: [PATCH] app: gimp_image_get/set_imported/exported/save_a_copy_uri() Add more proper core API for GimpImage URI management. --- app/actions/file-actions.c | 6 +- app/actions/file-commands.c | 14 +--- app/core/gimpimage.c | 107 +++++++++++++++++++++++++++ app/core/gimpimage.h | 14 +++- app/dialogs/file-save-dialog.c | 14 +--- app/display/gimpdisplayshell-title.c | 10 +-- app/file/file-open.c | 3 +- app/file/gimp-file.h | 6 -- app/widgets/gimpfiledialog.c | 30 +++----- 9 files changed, 143 insertions(+), 61 deletions(-) diff --git a/app/actions/file-actions.c b/app/actions/file-actions.c index 372405c42f..c3fa676516 100644 --- a/app/actions/file-actions.c +++ b/app/actions/file-actions.c @@ -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 = diff --git a/app/actions/file-commands.c b/app/actions/file-commands.c index e160c6843d..2395e2ef37 100644 --- a/app/actions/file-commands.c +++ b/app/actions/file-commands.c @@ -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), diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c index 4c0a87c415..cc9a37eaa5 100644 --- a/app/core/gimpimage.c +++ b/app/core/gimpimage.c @@ -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) { diff --git a/app/core/gimpimage.h b/app/core/gimpimage.h index 912c7340ab..d28bdb4a8c 100644 --- a/app/core/gimpimage.h +++ b/app/core/gimpimage.h @@ -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); diff --git a/app/dialogs/file-save-dialog.c b/app/dialogs/file-save-dialog.c index 48ffc61f5a..daf71a6cfd 100644 --- a/app/dialogs/file-save-dialog.c +++ b/app/dialogs/file-save-dialog.c @@ -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), diff --git a/app/display/gimpdisplayshell-title.c b/app/display/gimpdisplayshell-title.c index 487228cb8c..7614968e77 100644 --- a/app/display/gimpdisplayshell-title.c +++ b/app/display/gimpdisplayshell-title.c @@ -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) diff --git a/app/file/file-open.c b/app/file/file-open.c index 838fc92370..2b97aa39b8 100644 --- a/app/file/file-open.c +++ b/app/file/file-open.c @@ -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); diff --git a/app/file/gimp-file.h b/app/file/gimp-file.h index 351e5f6695..6ef725f01c 100644 --- a/app/file/gimp-file.h +++ b/app/file/gimp-file.h @@ -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__ */ diff --git a/app/widgets/gimpfiledialog.c b/app/widgets/gimpfiledialog.c index 8e75215353..37fb0f2ef2 100644 --- a/app/widgets/gimpfiledialog.c +++ b/app/widgets/gimpfiledialog.c @@ -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),