From 5c1f14be67e235ff6ef1860946d3b58a464ee8d3 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Thu, 10 Jul 2014 22:52:29 +0200 Subject: [PATCH] app: add gimp_mount_enclosing_volume(), using the the GimpGui vtable and implement it in gui-vtable.c using gtk_mount_operation_new(). --- app/core/gimp-gui.c | 64 +++++++----- app/core/gimp-gui.h | 239 ++++++++++++++++++++++--------------------- app/gui/gui-vtable.c | 215 +++++++++++++++++++++++--------------- 3 files changed, 298 insertions(+), 220 deletions(-) diff --git a/app/core/gimp-gui.c b/app/core/gimp-gui.c index 8403a5ee5e..83a638a554 100644 --- a/app/core/gimp-gui.c +++ b/app/core/gimp-gui.c @@ -41,29 +41,30 @@ gimp_gui_init (Gimp *gimp) { g_return_if_fail (GIMP_IS_GIMP (gimp)); - gimp->gui.ungrab = NULL; - gimp->gui.threads_enter = NULL; - gimp->gui.threads_leave = NULL; - gimp->gui.set_busy = NULL; - gimp->gui.unset_busy = NULL; - gimp->gui.show_message = NULL; - gimp->gui.help = NULL; - gimp->gui.get_program_class = NULL; - gimp->gui.get_display_name = NULL; - gimp->gui.get_user_time = NULL; - gimp->gui.get_theme_dir = NULL; - gimp->gui.display_get_by_id = NULL; - gimp->gui.display_get_id = NULL; - gimp->gui.display_get_window_id = NULL; - gimp->gui.display_create = NULL; - gimp->gui.display_delete = NULL; - gimp->gui.displays_reconnect = NULL; - gimp->gui.progress_new = NULL; - gimp->gui.progress_free = NULL; - gimp->gui.pdb_dialog_set = NULL; - gimp->gui.pdb_dialog_close = NULL; - gimp->gui.recent_list_add_file = NULL; - gimp->gui.recent_list_load = NULL; + gimp->gui.ungrab = NULL; + gimp->gui.threads_enter = NULL; + gimp->gui.threads_leave = NULL; + gimp->gui.set_busy = NULL; + gimp->gui.unset_busy = NULL; + gimp->gui.show_message = NULL; + gimp->gui.help = NULL; + gimp->gui.get_program_class = NULL; + gimp->gui.get_display_name = NULL; + gimp->gui.get_user_time = NULL; + gimp->gui.get_theme_dir = NULL; + gimp->gui.display_get_by_id = NULL; + gimp->gui.display_get_id = NULL; + gimp->gui.display_get_window_id = NULL; + gimp->gui.display_create = NULL; + gimp->gui.display_delete = NULL; + gimp->gui.displays_reconnect = NULL; + gimp->gui.progress_new = NULL; + gimp->gui.progress_free = NULL; + gimp->gui.pdb_dialog_set = NULL; + gimp->gui.pdb_dialog_close = NULL; + gimp->gui.recent_list_add_file = NULL; + gimp->gui.recent_list_load = NULL; + gimp->gui.mount_enclosing_volume = NULL; } void @@ -492,3 +493,20 @@ gimp_recent_list_load (Gimp *gimp) if (gimp->gui.recent_list_load) gimp->gui.recent_list_load (gimp); } + +gboolean +gimp_mount_enclosing_volume (Gimp *gimp, + GFile *file, + GimpProgress *progress, + GError **error) +{ + g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE); + g_return_val_if_fail (G_IS_FILE (file), FALSE); + g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), FALSE); + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + if (gimp->gui.mount_enclosing_volume) + return gimp->gui.mount_enclosing_volume (gimp, file, progress, error); + + return FALSE; +} diff --git a/app/core/gimp-gui.h b/app/core/gimp-gui.h index 4c275a06a6..5d076fe5dd 100644 --- a/app/core/gimp-gui.h +++ b/app/core/gimp-gui.h @@ -23,153 +23,162 @@ typedef struct _GimpGui GimpGui; struct _GimpGui { - void (* ungrab) (Gimp *gimp); + void (* ungrab) (Gimp *gimp); - void (* threads_enter) (Gimp *gimp); - void (* threads_leave) (Gimp *gimp); + void (* threads_enter) (Gimp *gimp); + void (* threads_leave) (Gimp *gimp); - void (* set_busy) (Gimp *gimp); - void (* unset_busy) (Gimp *gimp); + void (* set_busy) (Gimp *gimp); + void (* unset_busy) (Gimp *gimp); - void (* show_message) (Gimp *gimp, - GObject *handler, - GimpMessageSeverity severity, - const gchar *domain, - const gchar *message); - void (* help) (Gimp *gimp, - GimpProgress *progress, - const gchar *help_domain, - const gchar *help_id); + void (* show_message) (Gimp *gimp, + GObject *handler, + GimpMessageSeverity severity, + const gchar *domain, + const gchar *message); + void (* help) (Gimp *gimp, + GimpProgress *progress, + const gchar *help_domain, + const gchar *help_id); - const gchar * (* get_program_class) (Gimp *gimp); - gchar * (* get_display_name) (Gimp *gimp, - gint display_ID, - GObject **screen, - gint *monitor); - guint32 (* get_user_time) (Gimp *gimp); + const gchar * (* get_program_class) (Gimp *gimp); + gchar * (* get_display_name) (Gimp *gimp, + gint display_ID, + GObject **screen, + gint *monitor); + guint32 (* get_user_time) (Gimp *gimp); - const gchar * (* get_theme_dir) (Gimp *gimp); + const gchar * (* get_theme_dir) (Gimp *gimp); - GimpObject * (* get_window_strategy) (Gimp *gimp); - GimpObject * (* get_empty_display) (Gimp *gimp); - GimpObject * (* display_get_by_id) (Gimp *gimp, + GimpObject * (* get_window_strategy) (Gimp *gimp); + GimpObject * (* get_empty_display) (Gimp *gimp); + GimpObject * (* display_get_by_id) (Gimp *gimp, + gint ID); + gint (* display_get_id) (GimpObject *display); + guint32 (* display_get_window_id) (GimpObject *display); + GimpObject * (* display_create) (Gimp *gimp, + GimpImage *image, + GimpUnit unit, + gdouble scale, + GObject *screen, + gint monitor); + void (* display_delete) (GimpObject *display); + void (* displays_reconnect) (Gimp *gimp, + GimpImage *old_image, + GimpImage *new_image); + + GimpProgress * (* progress_new) (Gimp *gimp, + GimpObject *display); + void (* progress_free) (Gimp *gimp, + GimpProgress *progress); + + gboolean (* pdb_dialog_new) (Gimp *gimp, + GimpContext *context, + GimpProgress *progress, + GimpContainer *container, + const gchar *title, + const gchar *callback_name, + const gchar *object_name, + va_list args); + gboolean (* pdb_dialog_set) (Gimp *gimp, + GimpContainer *container, + const gchar *callback_name, + const gchar *object_name, + va_list args); + gboolean (* pdb_dialog_close) (Gimp *gimp, + GimpContainer *container, + const gchar *callback_name); + gboolean (* recent_list_add_file) (Gimp *gimp, + GFile *file, + const gchar *mime_type); + void (* recent_list_load) (Gimp *gimp); + + gboolean (* mount_enclosing_volume) (Gimp *gimp, + GFile *file, + GimpProgress *progress, + GError **error); +}; + + +void gimp_gui_init (Gimp *gimp); + +void gimp_gui_ungrab (Gimp *gimp); + +void gimp_threads_enter (Gimp *gimp); +void gimp_threads_leave (Gimp *gimp); + +GimpObject * gimp_get_window_strategy (Gimp *gimp); +GimpObject * gimp_get_empty_display (Gimp *gimp); +GimpObject * gimp_get_display_by_ID (Gimp *gimp, gint ID); - gint (* display_get_id) (GimpObject *display); - guint32 (* display_get_window_id) (GimpObject *display); - GimpObject * (* display_create) (Gimp *gimp, +gint gimp_get_display_ID (Gimp *gimp, + GimpObject *display); +guint32 gimp_get_display_window_id (Gimp *gimp, + GimpObject *display); +GimpObject * gimp_create_display (Gimp *gimp, GimpImage *image, GimpUnit unit, gdouble scale, GObject *screen, gint monitor); - void (* display_delete) (GimpObject *display); - void (* displays_reconnect) (Gimp *gimp, +void gimp_delete_display (Gimp *gimp, + GimpObject *display); +void gimp_reconnect_displays (Gimp *gimp, GimpImage *old_image, GimpImage *new_image); - GimpProgress * (* progress_new) (Gimp *gimp, +void gimp_set_busy (Gimp *gimp); +void gimp_set_busy_until_idle (Gimp *gimp); +void gimp_unset_busy (Gimp *gimp); + +void gimp_show_message (Gimp *gimp, + GObject *handler, + GimpMessageSeverity severity, + const gchar *domain, + const gchar *message); +void gimp_help (Gimp *gimp, + GimpProgress *progress, + const gchar *help_domain, + const gchar *help_id); + +GimpProgress * gimp_new_progress (Gimp *gimp, GimpObject *display); - void (* progress_free) (Gimp *gimp, +void gimp_free_progress (Gimp *gimp, GimpProgress *progress); - gboolean (* pdb_dialog_new) (Gimp *gimp, +const gchar * gimp_get_program_class (Gimp *gimp); +gchar * gimp_get_display_name (Gimp *gimp, + gint display_ID, + GObject **screen, + gint *monitor); +guint32 gimp_get_user_time (Gimp *gimp); +const gchar * gimp_get_theme_dir (Gimp *gimp); + +gboolean gimp_pdb_dialog_new (Gimp *gimp, GimpContext *context, GimpProgress *progress, GimpContainer *container, const gchar *title, const gchar *callback_name, const gchar *object_name, - va_list args); - gboolean (* pdb_dialog_set) (Gimp *gimp, + ...) G_GNUC_NULL_TERMINATED; +gboolean gimp_pdb_dialog_set (Gimp *gimp, GimpContainer *container, const gchar *callback_name, const gchar *object_name, - va_list args); - gboolean (* pdb_dialog_close) (Gimp *gimp, + ...) G_GNUC_NULL_TERMINATED; +gboolean gimp_pdb_dialog_close (Gimp *gimp, GimpContainer *container, const gchar *callback_name); - gboolean (* recent_list_add_file) (Gimp *gimp, +gboolean gimp_recent_list_add_file (Gimp *gimp, GFile *file, const gchar *mime_type); - void (* recent_list_load) (Gimp *gimp); +void gimp_recent_list_load (Gimp *gimp); -}; - - -void gimp_gui_init (Gimp *gimp); - -void gimp_gui_ungrab (Gimp *gimp); - -void gimp_threads_enter (Gimp *gimp); -void gimp_threads_leave (Gimp *gimp); - -GimpObject * gimp_get_window_strategy (Gimp *gimp); -GimpObject * gimp_get_empty_display (Gimp *gimp); -GimpObject * gimp_get_display_by_ID (Gimp *gimp, - gint ID); -gint gimp_get_display_ID (Gimp *gimp, - GimpObject *display); -guint32 gimp_get_display_window_id (Gimp *gimp, - GimpObject *display); -GimpObject * gimp_create_display (Gimp *gimp, - GimpImage *image, - GimpUnit unit, - gdouble scale, - GObject *screen, - gint monitor); -void gimp_delete_display (Gimp *gimp, - GimpObject *display); -void gimp_reconnect_displays (Gimp *gimp, - GimpImage *old_image, - GimpImage *new_image); - -void gimp_set_busy (Gimp *gimp); -void gimp_set_busy_until_idle (Gimp *gimp); -void gimp_unset_busy (Gimp *gimp); - -void gimp_show_message (Gimp *gimp, - GObject *handler, - GimpMessageSeverity severity, - const gchar *domain, - const gchar *message); -void gimp_help (Gimp *gimp, - GimpProgress *progress, - const gchar *help_domain, - const gchar *help_id); - -GimpProgress * gimp_new_progress (Gimp *gimp, - GimpObject *display); -void gimp_free_progress (Gimp *gimp, - GimpProgress *progress); - -const gchar * gimp_get_program_class (Gimp *gimp); -gchar * gimp_get_display_name (Gimp *gimp, - gint display_ID, - GObject **screen, - gint *monitor); -guint32 gimp_get_user_time (Gimp *gimp); -const gchar * gimp_get_theme_dir (Gimp *gimp); - -gboolean gimp_pdb_dialog_new (Gimp *gimp, - GimpContext *context, - GimpProgress *progress, - GimpContainer *container, - const gchar *title, - const gchar *callback_name, - const gchar *object_name, - ...) G_GNUC_NULL_TERMINATED; -gboolean gimp_pdb_dialog_set (Gimp *gimp, - GimpContainer *container, - const gchar *callback_name, - const gchar *object_name, - ...) G_GNUC_NULL_TERMINATED; -gboolean gimp_pdb_dialog_close (Gimp *gimp, - GimpContainer *container, - const gchar *callback_name); -gboolean gimp_recent_list_add_file (Gimp *gimp, - GFile *file, - const gchar *mime_type); -void gimp_recent_list_load (Gimp *gimp); +gboolean gimp_mount_enclosing_volume (Gimp *gimp, + GFile *file, + GimpProgress *progress, + GError **error); #endif /* __GIMP_GUI_H__ */ diff --git a/app/gui/gui-vtable.c b/app/gui/gui-vtable.c index 54632941b0..31b41ddb1e 100644 --- a/app/gui/gui-vtable.c +++ b/app/gui/gui-vtable.c @@ -84,63 +84,70 @@ /* local function prototypes */ -static void gui_ungrab (Gimp *gimp); +static void gui_ungrab (Gimp *gimp); -static void gui_threads_enter (Gimp *gimp); -static void gui_threads_leave (Gimp *gimp); -static void gui_set_busy (Gimp *gimp); -static void gui_unset_busy (Gimp *gimp); -static void gui_help (Gimp *gimp, - GimpProgress *progress, - const gchar *help_domain, - const gchar *help_id); -static const gchar * gui_get_program_class (Gimp *gimp); -static gchar * gui_get_display_name (Gimp *gimp, - gint display_ID, - GObject **screen, - gint *monitor); -static guint32 gui_get_user_time (Gimp *gimp); -static const gchar * gui_get_theme_dir (Gimp *gimp); -static GimpObject * gui_get_window_strategy (Gimp *gimp); -static GimpObject * gui_get_empty_display (Gimp *gimp); -static GimpObject * gui_display_get_by_ID (Gimp *gimp, - gint ID); -static gint gui_display_get_ID (GimpObject *display); -static guint32 gui_display_get_window_id (GimpObject *display); -static GimpObject * gui_display_create (Gimp *gimp, - GimpImage *image, - GimpUnit unit, - gdouble scale, - GObject *screen, - gint monitor); -static void gui_display_delete (GimpObject *display); -static void gui_displays_reconnect (Gimp *gimp, - GimpImage *old_image, - GimpImage *new_image); -static GimpProgress * gui_new_progress (Gimp *gimp, - GimpObject *display); -static void gui_free_progress (Gimp *gimp, - GimpProgress *progress); -static gboolean gui_pdb_dialog_new (Gimp *gimp, - GimpContext *context, - GimpProgress *progress, - GimpContainer *container, - const gchar *title, - const gchar *callback_name, - const gchar *object_name, - va_list args); -static gboolean gui_pdb_dialog_set (Gimp *gimp, - GimpContainer *container, - const gchar *callback_name, - const gchar *object_name, - va_list args); -static gboolean gui_pdb_dialog_close (Gimp *gimp, - GimpContainer *container, - const gchar *callback_name); -static gboolean gui_recent_list_add_file (Gimp *gimp, - GFile *file, - const gchar *mime_type); -static void gui_recent_list_load (Gimp *gimp); +static void gui_threads_enter (Gimp *gimp); +static void gui_threads_leave (Gimp *gimp); + +static void gui_set_busy (Gimp *gimp); +static void gui_unset_busy (Gimp *gimp); + +static void gui_help (Gimp *gimp, + GimpProgress *progress, + const gchar *help_domain, + const gchar *help_id); +static const gchar * gui_get_program_class (Gimp *gimp); +static gchar * gui_get_display_name (Gimp *gimp, + gint display_ID, + GObject **screen, + gint *monitor); +static guint32 gui_get_user_time (Gimp *gimp); +static const gchar * gui_get_theme_dir (Gimp *gimp); +static GimpObject * gui_get_window_strategy (Gimp *gimp); +static GimpObject * gui_get_empty_display (Gimp *gimp); +static GimpObject * gui_display_get_by_ID (Gimp *gimp, + gint ID); +static gint gui_display_get_ID (GimpObject *display); +static guint32 gui_display_get_window_id (GimpObject *display); +static GimpObject * gui_display_create (Gimp *gimp, + GimpImage *image, + GimpUnit unit, + gdouble scale, + GObject *screen, + gint monitor); +static void gui_display_delete (GimpObject *display); +static void gui_displays_reconnect (Gimp *gimp, + GimpImage *old_image, + GimpImage *new_image); +static GimpProgress * gui_new_progress (Gimp *gimp, + GimpObject *display); +static void gui_free_progress (Gimp *gimp, + GimpProgress *progress); +static gboolean gui_pdb_dialog_new (Gimp *gimp, + GimpContext *context, + GimpProgress *progress, + GimpContainer *container, + const gchar *title, + const gchar *callback_name, + const gchar *object_name, + va_list args); +static gboolean gui_pdb_dialog_set (Gimp *gimp, + GimpContainer *container, + const gchar *callback_name, + const gchar *object_name, + va_list args); +static gboolean gui_pdb_dialog_close (Gimp *gimp, + GimpContainer *container, + const gchar *callback_name); +static gboolean gui_recent_list_add_file (Gimp *gimp, + GFile *file, + const gchar *mime_type); +static void gui_recent_list_load (Gimp *gimp); + +static gboolean gui_mount_enclosing_volume (Gimp *gimp, + GFile *file, + GimpProgress *progress, + GError **error); /* public functions */ @@ -150,32 +157,33 @@ gui_vtable_init (Gimp *gimp) { g_return_if_fail (GIMP_IS_GIMP (gimp)); - gimp->gui.ungrab = gui_ungrab; - gimp->gui.threads_enter = gui_threads_enter; - gimp->gui.threads_leave = gui_threads_leave; - gimp->gui.set_busy = gui_set_busy; - gimp->gui.unset_busy = gui_unset_busy; - gimp->gui.show_message = gui_message; - gimp->gui.help = gui_help; - gimp->gui.get_program_class = gui_get_program_class; - gimp->gui.get_display_name = gui_get_display_name; - gimp->gui.get_user_time = gui_get_user_time; - gimp->gui.get_theme_dir = gui_get_theme_dir; - gimp->gui.get_window_strategy = gui_get_window_strategy; - gimp->gui.get_empty_display = gui_get_empty_display; - gimp->gui.display_get_by_id = gui_display_get_by_ID; - gimp->gui.display_get_id = gui_display_get_ID; - gimp->gui.display_get_window_id = gui_display_get_window_id; - gimp->gui.display_create = gui_display_create; - gimp->gui.display_delete = gui_display_delete; - gimp->gui.displays_reconnect = gui_displays_reconnect; - gimp->gui.progress_new = gui_new_progress; - gimp->gui.progress_free = gui_free_progress; - gimp->gui.pdb_dialog_new = gui_pdb_dialog_new; - gimp->gui.pdb_dialog_set = gui_pdb_dialog_set; - gimp->gui.pdb_dialog_close = gui_pdb_dialog_close; - gimp->gui.recent_list_add_file = gui_recent_list_add_file; - gimp->gui.recent_list_load = gui_recent_list_load; + gimp->gui.ungrab = gui_ungrab; + gimp->gui.threads_enter = gui_threads_enter; + gimp->gui.threads_leave = gui_threads_leave; + gimp->gui.set_busy = gui_set_busy; + gimp->gui.unset_busy = gui_unset_busy; + gimp->gui.show_message = gui_message; + gimp->gui.help = gui_help; + gimp->gui.get_program_class = gui_get_program_class; + gimp->gui.get_display_name = gui_get_display_name; + gimp->gui.get_user_time = gui_get_user_time; + gimp->gui.get_theme_dir = gui_get_theme_dir; + gimp->gui.get_window_strategy = gui_get_window_strategy; + gimp->gui.get_empty_display = gui_get_empty_display; + gimp->gui.display_get_by_id = gui_display_get_by_ID; + gimp->gui.display_get_id = gui_display_get_ID; + gimp->gui.display_get_window_id = gui_display_get_window_id; + gimp->gui.display_create = gui_display_create; + gimp->gui.display_delete = gui_display_delete; + gimp->gui.displays_reconnect = gui_displays_reconnect; + gimp->gui.progress_new = gui_new_progress; + gimp->gui.progress_free = gui_free_progress; + gimp->gui.pdb_dialog_new = gui_pdb_dialog_new; + gimp->gui.pdb_dialog_set = gui_pdb_dialog_set; + gimp->gui.pdb_dialog_close = gui_pdb_dialog_close; + gimp->gui.recent_list_add_file = gui_recent_list_add_file; + gimp->gui.recent_list_load = gui_recent_list_load; + gimp->gui.mount_enclosing_volume = gui_mount_enclosing_volume; } @@ -732,3 +740,46 @@ gui_recent_list_load (Gimp *gimp) gimp_container_thaw (gimp->documents); } + +static void +mount_volume_ready (GFile *file, + GAsyncResult *res, + GError **error) +{ + g_file_mount_enclosing_volume_finish (file, res, error); + + gtk_main_quit (); +} + +static gboolean +gui_mount_enclosing_volume (Gimp *gimp, + GFile *file, + GimpProgress *progress, + GError **error) +{ + GMountOperation *operation; + GtkWidget *toplevel = NULL; + GError *my_error = NULL; + + if (GTK_IS_WIDGET (progress)) + toplevel = gtk_widget_get_toplevel (GTK_WIDGET (progress)); + + operation = gtk_mount_operation_new (GTK_WINDOW (toplevel)); + + g_file_mount_enclosing_volume (file, G_MOUNT_MOUNT_NONE, + operation, + NULL, + (GAsyncReadyCallback) mount_volume_ready, + &my_error); + gtk_main (); + + g_object_unref (operation); + + if (my_error) + { + g_propagate_error (error, my_error); + return FALSE; + } + + return TRUE; +}