app: reduce casts in file-save-dialog.c and file-open-dialog.c

also, name variables like their type, e.g. a GimpOpenDialog is always
called open_dialog now.
This commit is contained in:
Michael Natterer 2015-09-09 21:04:18 +02:00
parent a9c7af8b70
commit 03e12184f5
2 changed files with 88 additions and 86 deletions

View File

@ -50,14 +50,14 @@
/* local function prototypes */ /* local function prototypes */
static void file_open_dialog_response (GtkWidget *open_dialog, static void file_open_dialog_response (GtkWidget *dialog,
gint response_id, gint response_id,
Gimp *gimp); Gimp *gimp);
static GimpImage *file_open_dialog_open_image (GtkWidget *open_dialog, static GimpImage *file_open_dialog_open_image (GtkWidget *dialog,
Gimp *gimp, Gimp *gimp,
GFile *file, GFile *file,
GimpPlugInProcedure *load_proc); GimpPlugInProcedure *load_proc);
static gboolean file_open_dialog_open_layers (GtkWidget *open_dialog, static gboolean file_open_dialog_open_layers (GtkWidget *dialog,
GimpImage *image, GimpImage *image,
GFile *file, GFile *file,
GimpPlugInProcedure *load_proc); GimpPlugInProcedure *load_proc);
@ -90,11 +90,12 @@ file_open_dialog_new (Gimp *gimp)
/* private functions */ /* private functions */
static void static void
file_open_dialog_response (GtkWidget *open_dialog, file_open_dialog_response (GtkWidget *dialog,
gint response_id, gint response_id,
Gimp *gimp) Gimp *gimp)
{ {
GimpFileDialog *dialog = GIMP_FILE_DIALOG (open_dialog); GimpFileDialog *file_dialog = GIMP_FILE_DIALOG (dialog);
GimpOpenDialog *open_dialog = GIMP_OPEN_DIALOG (dialog);
GSList *files; GSList *files;
GSList *list; GSList *list;
gboolean success = FALSE; gboolean success = FALSE;
@ -104,20 +105,20 @@ file_open_dialog_response (GtkWidget *open_dialog,
if (response_id != GTK_RESPONSE_OK) if (response_id != GTK_RESPONSE_OK)
{ {
if (! dialog->busy) if (! file_dialog->busy)
gtk_widget_destroy (open_dialog); gtk_widget_destroy (dialog);
return; return;
} }
files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (open_dialog)); files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (dialog));
if (files) if (files)
g_object_set_data_full (G_OBJECT (gimp), GIMP_FILE_OPEN_LAST_FILE_KEY, g_object_set_data_full (G_OBJECT (gimp), GIMP_FILE_OPEN_LAST_FILE_KEY,
g_object_ref (files->data), g_object_ref (files->data),
(GDestroyNotify) g_object_unref); (GDestroyNotify) g_object_unref);
gimp_file_dialog_set_sensitive (dialog, FALSE); gimp_file_dialog_set_sensitive (file_dialog, FALSE);
/* When we are going to open new image windows, unset the transient /* When we are going to open new image windows, unset the transient
* window. We don't need it since we will use gdk_window_raise() to * window. We don't need it since we will use gdk_window_raise() to
@ -125,70 +126,70 @@ file_open_dialog_response (GtkWidget *open_dialog,
* will pull the image window it was invoked from on top of all the * will pull the image window it was invoked from on top of all the
* new opened image windows, and we don't want that to happen. * new opened image windows, and we don't want that to happen.
*/ */
if (! GIMP_OPEN_DIALOG (dialog)->open_as_layers) if (! open_dialog->open_as_layers)
gtk_window_set_transient_for (GTK_WINDOW (open_dialog), NULL); gtk_window_set_transient_for (GTK_WINDOW (dialog), NULL);
for (list = files; list; list = g_slist_next (list)) for (list = files; list; list = g_slist_next (list))
{ {
GFile *file = list->data; GFile *file = list->data;
if (GIMP_OPEN_DIALOG (dialog)->open_as_layers) if (open_dialog->open_as_layers)
{ {
if (! GIMP_FILE_DIALOG (dialog)->image) if (! file_dialog->image)
{ {
GIMP_FILE_DIALOG (dialog)->image = file_open_dialog_open_image (open_dialog, file_dialog->image = file_open_dialog_open_image (dialog,
gimp, gimp,
file, file,
dialog->file_proc); file_dialog->file_proc);
if (GIMP_FILE_DIALOG (dialog)->image) if (file_dialog->image)
success = TRUE; success = TRUE;
} }
else if (file_open_dialog_open_layers (open_dialog, else if (file_open_dialog_open_layers (dialog,
GIMP_FILE_DIALOG (dialog)->image, file_dialog->image,
file, file,
dialog->file_proc)) file_dialog->file_proc))
{ {
success = TRUE; success = TRUE;
} }
} }
else else
{ {
if (file_open_dialog_open_image (open_dialog, if (file_open_dialog_open_image (dialog,
gimp, gimp,
file, file,
dialog->file_proc)) file_dialog->file_proc))
{ {
success = TRUE; success = TRUE;
/* Make the dialog stay on top of all images we open if /* Make the dialog stay on top of all images we open if
* we open say 10 at once * we open say 10 at once
*/ */
gdk_window_raise (gtk_widget_get_window (open_dialog)); gdk_window_raise (gtk_widget_get_window (dialog));
} }
} }
if (dialog->canceled) if (file_dialog->canceled)
break; break;
} }
if (success) if (success)
{ {
if (GIMP_OPEN_DIALOG (dialog)->open_as_layers && GIMP_FILE_DIALOG (dialog)->image) if (open_dialog->open_as_layers && file_dialog->image)
gimp_image_flush (GIMP_FILE_DIALOG (dialog)->image); gimp_image_flush (file_dialog->image);
gtk_widget_destroy (open_dialog); gtk_widget_destroy (dialog);
} }
else else
{ {
gimp_file_dialog_set_sensitive (dialog, TRUE); gimp_file_dialog_set_sensitive (file_dialog, TRUE);
} }
g_slist_free_full (files, (GDestroyNotify) g_object_unref); g_slist_free_full (files, (GDestroyNotify) g_object_unref);
} }
static GimpImage * static GimpImage *
file_open_dialog_open_image (GtkWidget *open_dialog, file_open_dialog_open_image (GtkWidget *dialog,
Gimp *gimp, Gimp *gimp,
GFile *file, GFile *file,
GimpPlugInProcedure *load_proc) GimpPlugInProcedure *load_proc)
@ -199,16 +200,16 @@ file_open_dialog_open_image (GtkWidget *open_dialog,
image = file_open_with_proc_and_display (gimp, image = file_open_with_proc_and_display (gimp,
gimp_get_user_context (gimp), gimp_get_user_context (gimp),
GIMP_PROGRESS (open_dialog), GIMP_PROGRESS (dialog),
file, file, FALSE, file, file, FALSE,
load_proc, load_proc,
G_OBJECT (gtk_widget_get_screen (open_dialog)), G_OBJECT (gtk_widget_get_screen (dialog)),
gimp_widget_get_monitor (open_dialog), gimp_widget_get_monitor (dialog),
&status, &error); &status, &error);
if (! image && status != GIMP_PDB_CANCEL) if (! image && status != GIMP_PDB_CANCEL)
{ {
gimp_message (gimp, G_OBJECT (open_dialog), GIMP_MESSAGE_ERROR, gimp_message (gimp, G_OBJECT (dialog), GIMP_MESSAGE_ERROR,
_("Opening '%s' failed:\n\n%s"), _("Opening '%s' failed:\n\n%s"),
gimp_file_get_utf8_name (file), error->message); gimp_file_get_utf8_name (file), error->message);
g_clear_error (&error); g_clear_error (&error);
@ -218,7 +219,7 @@ file_open_dialog_open_image (GtkWidget *open_dialog,
} }
static gboolean static gboolean
file_open_dialog_open_layers (GtkWidget *open_dialog, file_open_dialog_open_layers (GtkWidget *dialog,
GimpImage *image, GimpImage *image,
GFile *file, GFile *file,
GimpPlugInProcedure *load_proc) GimpPlugInProcedure *load_proc)
@ -229,7 +230,7 @@ file_open_dialog_open_layers (GtkWidget *open_dialog,
new_layers = file_open_layers (image->gimp, new_layers = file_open_layers (image->gimp,
gimp_get_user_context (image->gimp), gimp_get_user_context (image->gimp),
GIMP_PROGRESS (open_dialog), GIMP_PROGRESS (dialog),
image, FALSE, image, FALSE,
file, GIMP_RUN_INTERACTIVE, load_proc, file, GIMP_RUN_INTERACTIVE, load_proc,
&status, &error); &status, &error);
@ -249,7 +250,7 @@ file_open_dialog_open_layers (GtkWidget *open_dialog,
} }
else if (status != GIMP_PDB_CANCEL) else if (status != GIMP_PDB_CANCEL)
{ {
gimp_message (image->gimp, G_OBJECT (open_dialog), GIMP_MESSAGE_ERROR, gimp_message (image->gimp, G_OBJECT (dialog), GIMP_MESSAGE_ERROR,
_("Opening '%s' failed:\n\n%s"), _("Opening '%s' failed:\n\n%s"),
gimp_file_get_utf8_name (file), error->message); gimp_file_get_utf8_name (file), error->message);
g_clear_error (&error); g_clear_error (&error);

View File

@ -66,9 +66,9 @@ typedef enum
/* local function prototypes */ /* local function prototypes */
static GtkFileChooserConfirmation static GtkFileChooserConfirmation
file_save_dialog_confirm_overwrite (GtkWidget *save_dialog, file_save_dialog_confirm_overwrite (GtkWidget *dialog,
Gimp *gimp); Gimp *gimp);
static void file_save_dialog_response (GtkWidget *save_dialog, static void file_save_dialog_response (GtkWidget *dialog,
gint response_id, gint response_id,
Gimp *gimp); Gimp *gimp);
static CheckUriResult file_save_dialog_check_file (GtkWidget *save_dialog, static CheckUriResult file_save_dialog_check_file (GtkWidget *save_dialog,
@ -93,7 +93,7 @@ GtkWidget *
file_save_dialog_new (Gimp *gimp, file_save_dialog_new (Gimp *gimp,
gboolean export) gboolean export)
{ {
GtkWidget *dialog; GtkWidget *dialog;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL); g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
@ -127,12 +127,12 @@ file_save_dialog_new (Gimp *gimp,
/* private functions */ /* private functions */
static GtkFileChooserConfirmation static GtkFileChooserConfirmation
file_save_dialog_confirm_overwrite (GtkWidget *save_dialog, file_save_dialog_confirm_overwrite (GtkWidget *dialog,
Gimp *gimp) Gimp *gimp)
{ {
GimpFileDialog *dialog = GIMP_FILE_DIALOG (save_dialog); GimpFileDialog *file_dialog = GIMP_FILE_DIALOG (dialog);
if (file_save_dialog_no_overwrite_confirmation (dialog, gimp)) if (file_save_dialog_no_overwrite_confirmation (file_dialog, gimp))
/* The URI will not be accepted whatever happens, so don't /* The URI will not be accepted whatever happens, so don't
* bother asking the user about overwriting files * bother asking the user about overwriting files
*/ */
@ -142,47 +142,47 @@ file_save_dialog_confirm_overwrite (GtkWidget *save_dialog,
} }
static void static void
file_save_dialog_response (GtkWidget *save_dialog, file_save_dialog_response (GtkWidget *dialog,
gint response_id, gint response_id,
Gimp *gimp) Gimp *gimp)
{ {
GimpFileDialog *dialog = GIMP_FILE_DIALOG (save_dialog); GimpFileDialog *file_dialog = GIMP_FILE_DIALOG (dialog);
GFile *file; GFile *file;
gchar *basename; gchar *basename;
GimpPlugInProcedure *save_proc; GimpPlugInProcedure *save_proc;
if (GIMP_IS_SAVE_DIALOG (dialog)) if (GIMP_IS_SAVE_DIALOG (dialog))
{ {
gimp_file_dialog_save_state (dialog, "gimp-file-save-dialog-state"); gimp_file_dialog_save_state (file_dialog, "gimp-file-save-dialog-state");
} }
else /* GIMP_IS_EXPORT_DIALOG (dialog) */ else /* GIMP_IS_EXPORT_DIALOG (dialog) */
{ {
gimp_file_dialog_save_state (dialog, "gimp-file-export-dialog-state"); gimp_file_dialog_save_state (file_dialog, "gimp-file-export-dialog-state");
} }
if (response_id != GTK_RESPONSE_OK) if (response_id != GTK_RESPONSE_OK)
{ {
if (! dialog->busy) if (! file_dialog->busy)
gtk_widget_destroy (save_dialog); gtk_widget_destroy (dialog);
return; return;
} }
g_object_ref (dialog); g_object_ref (file_dialog);
g_object_ref (dialog->image); g_object_ref (file_dialog->image);
switch (file_save_dialog_check_file (save_dialog, gimp, switch (file_save_dialog_check_file (dialog, gimp,
&file, &basename, &save_proc)) &file, &basename, &save_proc))
{ {
case CHECK_URI_FAIL: case CHECK_URI_FAIL:
break; break;
case CHECK_URI_OK: case CHECK_URI_OK:
gimp_file_dialog_set_sensitive (dialog, FALSE); gimp_file_dialog_set_sensitive (file_dialog, FALSE);
if (file_save_dialog_save_image (GIMP_PROGRESS (save_dialog), if (file_save_dialog_save_image (GIMP_PROGRESS (dialog),
gimp, gimp,
dialog->image, file_dialog->image,
file, file,
save_proc, save_proc,
GIMP_RUN_INTERACTIVE, GIMP_RUN_INTERACTIVE,
@ -201,26 +201,24 @@ file_save_dialog_response (GtkWidget *save_dialog,
*/ */
if (GIMP_IS_SAVE_DIALOG (dialog)) if (GIMP_IS_SAVE_DIALOG (dialog))
{ {
GimpSaveDialog *save_dialog = GIMP_SAVE_DIALOG (dialog); if (GIMP_SAVE_DIALOG (dialog)->save_a_copy)
gimp_image_set_save_a_copy_file (file_dialog->image, file);
if (save_dialog->save_a_copy) g_object_set_data_full (G_OBJECT (file_dialog->image->gimp),
gimp_image_set_save_a_copy_file (dialog->image, file);
g_object_set_data_full (G_OBJECT (dialog->image->gimp),
GIMP_FILE_SAVE_LAST_FILE_KEY, GIMP_FILE_SAVE_LAST_FILE_KEY,
g_object_ref (file), g_object_ref (file),
(GDestroyNotify) g_object_unref); (GDestroyNotify) g_object_unref);
} }
else else
{ {
g_object_set_data_full (G_OBJECT (dialog->image->gimp), g_object_set_data_full (G_OBJECT (file_dialog->image->gimp),
GIMP_FILE_EXPORT_LAST_FILE_KEY, GIMP_FILE_EXPORT_LAST_FILE_KEY,
g_object_ref (file), g_object_ref (file),
(GDestroyNotify) g_object_unref); (GDestroyNotify) g_object_unref);
} }
/* make sure the menus are updated with the keys we've just set */ /* make sure the menus are updated with the keys we've just set */
gimp_image_flush (dialog->image); gimp_image_flush (file_dialog->image);
/* Handle close-after-saving */ /* Handle close-after-saving */
if (GIMP_IS_SAVE_DIALOG (dialog) && if (GIMP_IS_SAVE_DIALOG (dialog) &&
@ -235,26 +233,26 @@ file_save_dialog_response (GtkWidget *save_dialog,
} }
} }
gtk_widget_destroy (save_dialog); gtk_widget_destroy (dialog);
} }
g_object_unref (file); g_object_unref (file);
g_free (basename); g_free (basename);
gimp_file_dialog_set_sensitive (dialog, TRUE); gimp_file_dialog_set_sensitive (file_dialog, TRUE);
break; break;
case CHECK_URI_SWITCH_DIALOGS: case CHECK_URI_SWITCH_DIALOGS:
dialog->busy = TRUE; /* prevent destruction */ file_dialog->busy = TRUE; /* prevent destruction */
gtk_dialog_response (GTK_DIALOG (dialog), FILE_SAVE_RESPONSE_OTHER_DIALOG); gtk_dialog_response (GTK_DIALOG (dialog), FILE_SAVE_RESPONSE_OTHER_DIALOG);
dialog->busy = FALSE; file_dialog->busy = FALSE;
gtk_widget_destroy (save_dialog); gtk_widget_destroy (dialog);
break; break;
} }
g_object_unref (dialog->image); g_object_unref (file_dialog->image);
g_object_unref (dialog); g_object_unref (file_dialog);
} }
/* IMPORTANT: When changing this function, keep /* IMPORTANT: When changing this function, keep
@ -263,13 +261,13 @@ file_save_dialog_response (GtkWidget *save_dialog,
* implemented in GTK+ in combination with how we use it. * implemented in GTK+ in combination with how we use it.
*/ */
static CheckUriResult static CheckUriResult
file_save_dialog_check_file (GtkWidget *save_dialog, file_save_dialog_check_file (GtkWidget *dialog,
Gimp *gimp, Gimp *gimp,
GFile **ret_file, GFile **ret_file,
gchar **ret_basename, gchar **ret_basename,
GimpPlugInProcedure **ret_save_proc) GimpPlugInProcedure **ret_save_proc)
{ {
GimpFileDialog *dialog = GIMP_FILE_DIALOG (save_dialog); GimpFileDialog *file_dialog = GIMP_FILE_DIALOG (dialog);
GFile *file; GFile *file;
gchar *uri; gchar *uri;
gchar *basename; gchar *basename;
@ -286,10 +284,12 @@ file_save_dialog_check_file (GtkWidget *save_dialog,
basename = g_path_get_basename (gimp_file_get_utf8_name (file)); basename = g_path_get_basename (gimp_file_get_utf8_name (file));
basename_file = g_file_new_for_uri (basename); basename_file = g_file_new_for_uri (basename);
save_proc = dialog->file_proc; save_proc = file_dialog->file_proc;
uri_proc = file_procedure_find (file_save_dialog_get_procs (dialog, gimp), uri_proc = file_procedure_find (file_save_dialog_get_procs (file_dialog,
gimp),
file, NULL); file, NULL);
basename_proc = file_procedure_find (file_save_dialog_get_procs (dialog, gimp), basename_proc = file_procedure_find (file_save_dialog_get_procs (file_dialog,
gimp),
basename_file, NULL); basename_file, NULL);
g_object_unref (basename_file); g_object_unref (basename_file);
@ -342,7 +342,7 @@ file_save_dialog_check_file (GtkWidget *save_dialog,
basename = ext_basename; basename = ext_basename;
utf8 = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL); utf8 = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL);
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (save_dialog), gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog),
utf8); utf8);
g_free (utf8); g_free (utf8);
@ -353,7 +353,7 @@ file_save_dialog_check_file (GtkWidget *save_dialog,
/* call the response callback again, so the /* call the response callback again, so the
* overwrite-confirm logic can check the changed uri * overwrite-confirm logic can check the changed uri
*/ */
gtk_dialog_response (GTK_DIALOG (save_dialog), GTK_RESPONSE_OK); gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
goto fail; goto fail;
} }
@ -376,7 +376,7 @@ file_save_dialog_check_file (GtkWidget *save_dialog,
GIMP_LOG (SAVE_DIALOG, GIMP_LOG (SAVE_DIALOG,
"unable to figure save_proc, bailing out"); "unable to figure save_proc, bailing out");
if (file_save_dialog_switch_dialogs (dialog, gimp, basename)) if (file_save_dialog_switch_dialogs (file_dialog, gimp, basename))
{ {
goto switch_dialogs; goto switch_dialogs;
} }
@ -410,7 +410,7 @@ file_save_dialog_check_file (GtkWidget *save_dialog,
GIMP_LOG (SAVE_DIALOG, GIMP_LOG (SAVE_DIALOG,
"basename has no useful extension, bailing out"); "basename has no useful extension, bailing out");
if (file_save_dialog_switch_dialogs (dialog, gimp, basename)) if (file_save_dialog_switch_dialogs (file_dialog, gimp, basename))
{ {
goto switch_dialogs; goto switch_dialogs;
} }
@ -441,7 +441,7 @@ file_save_dialog_check_file (GtkWidget *save_dialog,
/* remote URI */ /* remote URI */
gimp_message (gimp, G_OBJECT (save_dialog), GIMP_MESSAGE_WARNING, gimp_message (gimp, G_OBJECT (dialog), GIMP_MESSAGE_WARNING,
_("Saving remote files needs to determine the " _("Saving remote files needs to determine the "
"file format from the file extension. " "file format from the file extension. "
"Please enter a file extension that matches " "Please enter a file extension that matches "
@ -457,7 +457,7 @@ file_save_dialog_check_file (GtkWidget *save_dialog,
/* local URI */ /* local URI */
if (! file_save_dialog_use_extension (save_dialog, file)) if (! file_save_dialog_use_extension (dialog, file))
{ {
goto fail; goto fail;
} }
@ -508,7 +508,7 @@ file_save_dialog_check_file (GtkWidget *save_dialog,
* IMPORTANT: Keep this up to date with file_save_dialog_check_uri(). * IMPORTANT: Keep this up to date with file_save_dialog_check_uri().
*/ */
static gboolean static gboolean
file_save_dialog_no_overwrite_confirmation (GimpFileDialog *dialog, file_save_dialog_no_overwrite_confirmation (GimpFileDialog *file_dialog,
Gimp *gimp) Gimp *gimp)
{ {
GFile *file; GFile *file;
@ -519,7 +519,7 @@ file_save_dialog_no_overwrite_confirmation (GimpFileDialog *dialog,
gboolean uri_will_change; gboolean uri_will_change;
gboolean unknown_ext; gboolean unknown_ext;
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog)); file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (file_dialog));
if (! file) if (! file)
return FALSE; return FALSE;
@ -527,8 +527,9 @@ file_save_dialog_no_overwrite_confirmation (GimpFileDialog *dialog,
basename = g_path_get_basename (gimp_file_get_utf8_name (file)); basename = g_path_get_basename (gimp_file_get_utf8_name (file));
basename_file = g_file_new_for_uri (basename); basename_file = g_file_new_for_uri (basename);
save_proc = dialog->file_proc; save_proc = file_dialog->file_proc;
basename_proc = file_procedure_find (file_save_dialog_get_procs (dialog, gimp), basename_proc = file_procedure_find (file_save_dialog_get_procs (file_dialog,
gimp),
basename_file, NULL); basename_file, NULL);
g_object_unref (basename_file); g_object_unref (basename_file);
@ -547,10 +548,10 @@ file_save_dialog_no_overwrite_confirmation (GimpFileDialog *dialog,
} }
static GSList * static GSList *
file_save_dialog_get_procs (GimpFileDialog *dialog, file_save_dialog_get_procs (GimpFileDialog *file_dialog,
Gimp *gimp) Gimp *gimp)
{ {
return (GIMP_IS_SAVE_DIALOG (dialog) ? return (GIMP_IS_SAVE_DIALOG (file_dialog) ?
gimp->plug_in_manager->save_procs : gimp->plug_in_manager->save_procs :
gimp->plug_in_manager->export_procs); gimp->plug_in_manager->export_procs);
} }