From 06ea7dbd96e0e7ee1e06339b2b6dc5d14feddc33 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Tue, 10 Aug 2004 22:21:56 +0000 Subject: [PATCH] app/widgets/Makefile.am app/widgets/widgets-types.h new GtkVBox subclass 2004-08-11 Michael Natterer * app/widgets/Makefile.am * app/widgets/widgets-types.h * app/widgets/gimpprogressbox.[ch]: new GtkVBox subclass featuring a label and a progressbar. Implements GimpProgressIterface. * app/widgets/gimpprogressdialog.[ch]: replaced label and progress by a GimpProgressBox. Delegate most progress functionality to it. * app/widgets/gimpwidgets-utils.[ch]: factored out utility function gimp_dialog_set_sensitive(). * app/widgets/gimpfiledialog.c (gimp_file_dialog_set_sensitive): use it. * app/gui/file-open-location-dialog.c (file_open_location_response): embed the called file procedure's progress using a GimpProgressBox. --- ChangeLog | 19 ++ app/dialogs/file-open-location-dialog.c | 122 +++++++------ app/gui/file-open-location-dialog.c | 122 +++++++------ app/widgets/Makefile.am | 2 + app/widgets/gimpfiledialog.c | 25 +-- app/widgets/gimpprogressbox.c | 219 ++++++++++++++++++++++++ app/widgets/gimpprogressbox.h | 64 +++++++ app/widgets/gimpprogressdialog.c | 87 +++------- app/widgets/gimpprogressdialog.h | 4 +- app/widgets/gimpwidgets-utils.c | 28 +++ app/widgets/gimpwidgets-utils.h | 3 + app/widgets/widgets-types.h | 1 + 12 files changed, 503 insertions(+), 193 deletions(-) create mode 100644 app/widgets/gimpprogressbox.c create mode 100644 app/widgets/gimpprogressbox.h diff --git a/ChangeLog b/ChangeLog index 3b6f81560f..0020599c50 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2004-08-11 Michael Natterer + + * app/widgets/Makefile.am + * app/widgets/widgets-types.h + * app/widgets/gimpprogressbox.[ch]: new GtkVBox subclass featuring + a label and a progressbar. Implements GimpProgressIterface. + + * app/widgets/gimpprogressdialog.[ch]: replaced label and progress + by a GimpProgressBox. Delegate most progress functionality to it. + + * app/widgets/gimpwidgets-utils.[ch]: factored out utility + function gimp_dialog_set_sensitive(). + + * app/widgets/gimpfiledialog.c (gimp_file_dialog_set_sensitive): + use it. + + * app/gui/file-open-location-dialog.c (file_open_location_response): + embed the called file procedure's progress using a GimpProgressBox. + 2004-08-10 Michael Natterer * app/widgets/gimpfiledialog.[ch] diff --git a/app/dialogs/file-open-location-dialog.c b/app/dialogs/file-open-location-dialog.c index 783bab89c1..7819768f03 100644 --- a/app/dialogs/file-open-location-dialog.c +++ b/app/dialogs/file-open-location-dialog.c @@ -28,19 +28,22 @@ #include "gui-types.h" #include "core/gimp.h" +#include "core/gimpprogress.h" #include "file/file-open.h" #include "file/file-utils.h" #include "widgets/gimpcontainerentry.h" #include "widgets/gimphelp-ids.h" +#include "widgets/gimpprogressbox.h" +#include "widgets/gimpwidgets-utils.h" #include "file-open-location-dialog.h" #include "gimp-intl.h" -static void file_open_location_response (GtkWidget *dialog, +static void file_open_location_response (GtkDialog *dialog, gint response_id, Gimp *gimp); @@ -123,65 +126,80 @@ file_open_location_dialog_show (Gimp *gimp, } static void -file_open_location_response (GtkWidget *dialog, +file_open_location_response (GtkDialog *dialog, gint response_id, Gimp *gimp) { - if (response_id == GTK_RESPONSE_OK) + GtkWidget *entry; + GtkWidget *box; + const gchar *text = NULL; + + if (response_id != GTK_RESPONSE_OK) { - GtkWidget *entry; - const gchar *text = NULL; + box = g_object_get_data (G_OBJECT (dialog), "progress-box"); - gtk_widget_set_sensitive (dialog, FALSE); + if (box && GIMP_PROGRESS_BOX (box)->active) + gimp_progress_cancel (GIMP_PROGRESS (box)); + else + gtk_widget_destroy (GTK_WIDGET (dialog)); - entry = g_object_get_data (G_OBJECT (dialog), "location-entry"); - - text = gtk_entry_get_text (GTK_ENTRY (entry)); - - if (text && strlen (text)) - { - GimpImage *image; - gchar *uri; - gchar *filename; - GError *error = NULL; - GimpPDBStatusType status; - - filename = g_filename_from_uri (text, NULL, NULL); - - if (filename) - { - uri = g_filename_to_uri (filename, NULL, NULL); - g_free (filename); - } - else - { - uri = file_utils_filename_to_uri (gimp->load_procs, text, NULL); - } -#ifdef __GNUC__ -#warning FIXME: add progress bar to open location dialog -#endif - image = file_open_with_proc_and_display (gimp, - gimp_get_user_context (gimp), - NULL, - uri, text, NULL, - &status, &error); - - if (image == NULL && status != GIMP_PDB_CANCEL) - { - gchar *filename = file_utils_uri_to_utf8_filename (uri); - - g_message (_("Opening '%s' failed:\n\n%s"), - filename, error->message); - g_clear_error (&error); - - g_free (filename); - } - - g_free (uri); - } + return; } - gtk_widget_destroy (dialog); + gimp_dialog_set_sensitive (dialog, FALSE); + + entry = g_object_get_data (G_OBJECT (dialog), "location-entry"); + + text = gtk_entry_get_text (GTK_ENTRY (entry)); + + if (text && strlen (text)) + { + GimpImage *image; + gchar *uri; + gchar *filename; + GError *error = NULL; + GimpPDBStatusType status; + + filename = g_filename_from_uri (text, NULL, NULL); + + if (filename) + { + uri = g_filename_to_uri (filename, NULL, NULL); + g_free (filename); + } + else + { + uri = file_utils_filename_to_uri (gimp->load_procs, text, NULL); + } + + box = gimp_progress_box_new (); + gtk_container_set_border_width (GTK_CONTAINER (box), 12); + gtk_box_pack_end (GTK_BOX (dialog->vbox), box, FALSE, FALSE, 0); + gtk_widget_show (box); + + g_object_set_data (G_OBJECT (dialog), "progress-box", box); + + image = file_open_with_proc_and_display (gimp, + gimp_get_user_context (gimp), + GIMP_PROGRESS (box), + uri, text, NULL, + &status, &error); + + if (image == NULL && status != GIMP_PDB_CANCEL) + { + gchar *filename = file_utils_uri_to_utf8_filename (uri); + + g_message (_("Opening '%s' failed:\n\n%s"), + filename, error->message); + g_clear_error (&error); + + g_free (filename); + } + + g_free (uri); + } + + gtk_widget_destroy (GTK_WIDGET (dialog)); } static gboolean diff --git a/app/gui/file-open-location-dialog.c b/app/gui/file-open-location-dialog.c index 783bab89c1..7819768f03 100644 --- a/app/gui/file-open-location-dialog.c +++ b/app/gui/file-open-location-dialog.c @@ -28,19 +28,22 @@ #include "gui-types.h" #include "core/gimp.h" +#include "core/gimpprogress.h" #include "file/file-open.h" #include "file/file-utils.h" #include "widgets/gimpcontainerentry.h" #include "widgets/gimphelp-ids.h" +#include "widgets/gimpprogressbox.h" +#include "widgets/gimpwidgets-utils.h" #include "file-open-location-dialog.h" #include "gimp-intl.h" -static void file_open_location_response (GtkWidget *dialog, +static void file_open_location_response (GtkDialog *dialog, gint response_id, Gimp *gimp); @@ -123,65 +126,80 @@ file_open_location_dialog_show (Gimp *gimp, } static void -file_open_location_response (GtkWidget *dialog, +file_open_location_response (GtkDialog *dialog, gint response_id, Gimp *gimp) { - if (response_id == GTK_RESPONSE_OK) + GtkWidget *entry; + GtkWidget *box; + const gchar *text = NULL; + + if (response_id != GTK_RESPONSE_OK) { - GtkWidget *entry; - const gchar *text = NULL; + box = g_object_get_data (G_OBJECT (dialog), "progress-box"); - gtk_widget_set_sensitive (dialog, FALSE); + if (box && GIMP_PROGRESS_BOX (box)->active) + gimp_progress_cancel (GIMP_PROGRESS (box)); + else + gtk_widget_destroy (GTK_WIDGET (dialog)); - entry = g_object_get_data (G_OBJECT (dialog), "location-entry"); - - text = gtk_entry_get_text (GTK_ENTRY (entry)); - - if (text && strlen (text)) - { - GimpImage *image; - gchar *uri; - gchar *filename; - GError *error = NULL; - GimpPDBStatusType status; - - filename = g_filename_from_uri (text, NULL, NULL); - - if (filename) - { - uri = g_filename_to_uri (filename, NULL, NULL); - g_free (filename); - } - else - { - uri = file_utils_filename_to_uri (gimp->load_procs, text, NULL); - } -#ifdef __GNUC__ -#warning FIXME: add progress bar to open location dialog -#endif - image = file_open_with_proc_and_display (gimp, - gimp_get_user_context (gimp), - NULL, - uri, text, NULL, - &status, &error); - - if (image == NULL && status != GIMP_PDB_CANCEL) - { - gchar *filename = file_utils_uri_to_utf8_filename (uri); - - g_message (_("Opening '%s' failed:\n\n%s"), - filename, error->message); - g_clear_error (&error); - - g_free (filename); - } - - g_free (uri); - } + return; } - gtk_widget_destroy (dialog); + gimp_dialog_set_sensitive (dialog, FALSE); + + entry = g_object_get_data (G_OBJECT (dialog), "location-entry"); + + text = gtk_entry_get_text (GTK_ENTRY (entry)); + + if (text && strlen (text)) + { + GimpImage *image; + gchar *uri; + gchar *filename; + GError *error = NULL; + GimpPDBStatusType status; + + filename = g_filename_from_uri (text, NULL, NULL); + + if (filename) + { + uri = g_filename_to_uri (filename, NULL, NULL); + g_free (filename); + } + else + { + uri = file_utils_filename_to_uri (gimp->load_procs, text, NULL); + } + + box = gimp_progress_box_new (); + gtk_container_set_border_width (GTK_CONTAINER (box), 12); + gtk_box_pack_end (GTK_BOX (dialog->vbox), box, FALSE, FALSE, 0); + gtk_widget_show (box); + + g_object_set_data (G_OBJECT (dialog), "progress-box", box); + + image = file_open_with_proc_and_display (gimp, + gimp_get_user_context (gimp), + GIMP_PROGRESS (box), + uri, text, NULL, + &status, &error); + + if (image == NULL && status != GIMP_PDB_CANCEL) + { + gchar *filename = file_utils_uri_to_utf8_filename (uri); + + g_message (_("Opening '%s' failed:\n\n%s"), + filename, error->message); + g_clear_error (&error); + + g_free (filename); + } + + g_free (uri); + } + + gtk_widget_destroy (GTK_WIDGET (dialog)); } static gboolean diff --git a/app/widgets/Makefile.am b/app/widgets/Makefile.am index 97b7df2f6c..de1fa26dc1 100644 --- a/app/widgets/Makefile.am +++ b/app/widgets/Makefile.am @@ -206,6 +206,8 @@ libappwidgets_a_sources = \ gimppreviewrendererlayer.h \ gimppreviewrenderervectors.c \ gimppreviewrenderervectors.h \ + gimpprogressbox.c \ + gimpprogressbox.h \ gimpprogressdialog.c \ gimpprogressdialog.h \ gimppropwidgets.c \ diff --git a/app/widgets/gimpfiledialog.c b/app/widgets/gimpfiledialog.c index 9a97199677..8d7106c16e 100644 --- a/app/widgets/gimpfiledialog.c +++ b/app/widgets/gimpfiledialog.c @@ -46,6 +46,7 @@ #include "gimppreview.h" #include "gimppreviewrendererimagefile.h" #include "gimpthumbbox.h" +#include "gimpwidgets-utils.h" #include "gimp-intl.h" @@ -336,31 +337,9 @@ void gimp_file_dialog_set_sensitive (GimpFileDialog *dialog, gboolean sensitive) { - GList *children; - GList *list; - g_return_if_fail (GIMP_IS_FILE_DIALOG (dialog)); - children = - gtk_container_get_children (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox)); - - for (list = children; list; list = g_list_next (list)) - { - /* skip the last item (the action area) */ - if (! g_list_next (list)) - break; - - gtk_widget_set_sensitive (list->data, sensitive); - } - - g_list_free (children); - - if (sensitive) - gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), - GTK_RESPONSE_CANCEL, sensitive); - - gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), - GTK_RESPONSE_OK, sensitive); + gimp_dialog_set_sensitive (GTK_DIALOG (dialog), sensitive); dialog->busy = ! sensitive; dialog->canceled = FALSE; diff --git a/app/widgets/gimpprogressbox.c b/app/widgets/gimpprogressbox.c new file mode 100644 index 0000000000..76efe1b19e --- /dev/null +++ b/app/widgets/gimpprogressbox.c @@ -0,0 +1,219 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * gimpprogressbox.c + * Copyright (C) 2004 Michael Natterer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include + +#include "libgimpwidgets/gimpwidgets.h" + +#include "widgets-types.h" + +#include "core/gimpprogress.h" + +#include "gimpprogressbox.h" + +#include "gimp-intl.h" + + +static void gimp_progress_box_class_init (GimpProgressBoxClass *klass); +static void gimp_progress_box_init (GimpProgressBox *box); +static void gimp_progress_box_progress_iface_init (GimpProgressInterface *progress_iface); + +static GimpProgress * + gimp_progress_box_progress_start (GimpProgress *progress, + const gchar *message, + gboolean cancelable); +static void gimp_progress_box_progress_end (GimpProgress *progress); +static void gimp_progress_box_progress_set_text (GimpProgress *progress, + const gchar *message); +static void gimp_progress_box_progress_set_value (GimpProgress *progress, + gdouble percentage); +static gdouble gimp_progress_box_progress_get_value (GimpProgress *progress); + + +static GtkVBoxClass *parent_class = NULL; + + +GType +gimp_progress_box_get_type (void) +{ + static GType box_type = 0; + + if (! box_type) + { + static const GTypeInfo box_info = + { + sizeof (GimpProgressBoxClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) gimp_progress_box_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (GimpProgressBox), + 0, /* n_preallocs */ + (GInstanceInitFunc) gimp_progress_box_init, + }; + + static const GInterfaceInfo progress_iface_info = + { + (GInterfaceInitFunc) gimp_progress_box_progress_iface_init, + NULL, /* iface_finalize */ + NULL /* iface_data */ + }; + + box_type = g_type_register_static (GTK_TYPE_VBOX, + "GimpProgressBox", + &box_info, 0); + + g_type_add_interface_static (box_type, GIMP_TYPE_PROGRESS, + &progress_iface_info); + } + + return box_type; +} + +static void +gimp_progress_box_class_init (GimpProgressBoxClass *klass) +{ + parent_class = g_type_class_peek_parent (klass); +} + +static void +gimp_progress_box_init (GimpProgressBox *box) +{ +} + +static void +gimp_progress_box_progress_iface_init (GimpProgressInterface *progress_iface) +{ + progress_iface->start = gimp_progress_box_progress_start; + progress_iface->end = gimp_progress_box_progress_end; + progress_iface->set_text = gimp_progress_box_progress_set_text; + progress_iface->set_value = gimp_progress_box_progress_set_value; + progress_iface->get_value = gimp_progress_box_progress_get_value; +} + +static GimpProgress * +gimp_progress_box_progress_start (GimpProgress *progress, + const gchar *message, + gboolean cancelable) +{ + GimpProgressBox *box = GIMP_PROGRESS_BOX (progress); + + if (! box->active) + { + GtkProgressBar *bar = GTK_PROGRESS_BAR (box->progress); + + gtk_label_set_text (GTK_LABEL (box->label), message); + gtk_progress_bar_set_fraction (bar, 0.0); + + box->active = TRUE; + box->cancelable = cancelable; + + return progress; + } + + return NULL; +} + +static void +gimp_progress_box_progress_end (GimpProgress *progress) +{ + GimpProgressBox *box = GIMP_PROGRESS_BOX (progress); + + if (box->active) + { + GtkProgressBar *bar = GTK_PROGRESS_BAR (box->progress); + + gtk_label_set_text (GTK_LABEL (box->label), ""); + gtk_progress_bar_set_fraction (bar, 0.0); + + box->active = FALSE; + box->cancelable = FALSE; + } +} + +static void +gimp_progress_box_progress_set_text (GimpProgress *progress, + const gchar *message) +{ + GimpProgressBox *box = GIMP_PROGRESS_BOX (progress); + + if (box->active) + { + gtk_label_set_text (GTK_LABEL (box->label), message); + } +} + +static void +gimp_progress_box_progress_set_value (GimpProgress *progress, + gdouble percentage) +{ + GimpProgressBox *box = GIMP_PROGRESS_BOX (progress); + + if (box->active) + { + GtkProgressBar *bar = GTK_PROGRESS_BAR (box->progress); + + gtk_progress_bar_set_fraction (bar, percentage); + + if (GTK_WIDGET_DRAWABLE (box->progress)) + gdk_window_process_updates (box->progress->window, TRUE); + } +} + +static gdouble +gimp_progress_box_progress_get_value (GimpProgress *progress) +{ + GimpProgressBox *box = GIMP_PROGRESS_BOX (progress); + + if (box->active) + { + GtkProgressBar *bar = GTK_PROGRESS_BAR (box->progress); + + return gtk_progress_bar_get_fraction (bar); + } + + return 0.0; +} + +GtkWidget * +gimp_progress_box_new (void) +{ + GimpProgressBox *box; + + box = g_object_new (GIMP_TYPE_PROGRESS_BOX, + "spacing", 12, + NULL); + + box->label = gtk_label_new (""); + gtk_misc_set_alignment (GTK_MISC (box->label), 0.0, 0.5); + gtk_box_pack_start (GTK_BOX (box), box->label, FALSE, FALSE, 0); + gtk_widget_show (box->label); + + box->progress = gtk_progress_bar_new (); + gtk_widget_set_size_request (box->progress, 150, 20); + gtk_box_pack_start (GTK_BOX (box), box->progress, FALSE, FALSE, 0); + gtk_widget_show (box->progress); + + return GTK_WIDGET (box); +} diff --git a/app/widgets/gimpprogressbox.h b/app/widgets/gimpprogressbox.h new file mode 100644 index 0000000000..6062cbdc26 --- /dev/null +++ b/app/widgets/gimpprogressbox.h @@ -0,0 +1,64 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * gimpprogressbox.h + * Copyright (C) 2004 Michael Natterer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __GIMP_PROGRESS_BOX_H__ +#define __GIMP_PROGRESS_BOX_H__ + +#include + +G_BEGIN_DECLS + + +#define GIMP_TYPE_PROGRESS_BOX (gimp_progress_box_get_type ()) +#define GIMP_PROGRESS_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_PROGRESS_BOX, GimpProgressBox)) +#define GIMP_PROGRESS_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_PROGRESS_BOX, GimpProgressBoxClass)) +#define GIMP_IS_PROGRESS_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_PROGRESS_BOX)) +#define GIMP_IS_PROGRESS_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_PROGRESS_BOX)) +#define GIMP_PROGRESS_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_PROGRESS_BOX, GimpProgressBoxClass)) + + +typedef struct _GimpProgressBoxClass GimpProgressBoxClass; + +struct _GimpProgressBox +{ + GtkVBox parent_instance; + + gboolean active; + gboolean cancelable; + + GtkWidget *label; + GtkWidget *progress; +}; + +struct _GimpProgressBoxClass +{ + GtkVBoxClass parent_class; +}; + + +GType gimp_progress_box_get_type (void) G_GNUC_CONST; + +GtkWidget * gimp_progress_box_new (void); + + +G_END_DECLS + +#endif /* __GIMP_PROGRESS_BOX_H__ */ diff --git a/app/widgets/gimpprogressdialog.c b/app/widgets/gimpprogressdialog.c index b658fc42e2..4649ef7e31 100644 --- a/app/widgets/gimpprogressdialog.c +++ b/app/widgets/gimpprogressdialog.c @@ -29,6 +29,7 @@ #include "core/gimpprogress.h" +#include "gimpprogressbox.h" #include "gimpprogressdialog.h" #include "gimp-intl.h" @@ -107,6 +108,15 @@ gimp_progress_dialog_class_init (GimpProgressDialogClass *klass) static void gimp_progress_dialog_init (GimpProgressDialog *dialog) { + dialog->box = gimp_progress_box_new (); + gtk_container_set_border_width (GTK_CONTAINER (dialog->box), 12); + gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), + dialog->box); + gtk_widget_show (dialog->box); + + gtk_dialog_add_button (GTK_DIALOG (dialog), + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); + gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL); } static void @@ -123,7 +133,9 @@ static void gimp_progress_dialog_response (GtkDialog *dialog, gint response_id) { - if (response_id == GTK_RESPONSE_CANCEL) + GimpProgressDialog *progress_dialog = GIMP_PROGRESS_DIALOG (dialog); + + if (GIMP_PROGRESS_BOX (progress_dialog->box)->cancelable) gimp_progress_cancel (GIMP_PROGRESS (dialog)); } @@ -134,19 +146,13 @@ gimp_progress_dialog_progress_start (GimpProgress *progress, { GimpProgressDialog *dialog = GIMP_PROGRESS_DIALOG (progress); - if (! dialog->progress_active) + if (gimp_progress_start (GIMP_PROGRESS (dialog->box), message, cancelable)) { - GtkProgressBar *bar = GTK_PROGRESS_BAR (dialog->progressbar); - - gtk_label_set_text (GTK_LABEL (dialog->label), message); - gtk_progress_bar_set_fraction (bar, 0.0); gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL, cancelable); gtk_window_present (GTK_WINDOW (dialog)); - dialog->progress_active = TRUE; - return progress; } @@ -158,18 +164,14 @@ gimp_progress_dialog_progress_end (GimpProgress *progress) { GimpProgressDialog *dialog = GIMP_PROGRESS_DIALOG (progress); - if (dialog->progress_active) + if (GIMP_PROGRESS_BOX (dialog->box)->active) { - GtkProgressBar *bar = GTK_PROGRESS_BAR (dialog->progressbar); + gimp_progress_end (GIMP_PROGRESS (dialog->box)); - gtk_label_set_text (GTK_LABEL (dialog->label), ""); - gtk_progress_bar_set_fraction (bar, 0.0); gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL, FALSE); gtk_widget_hide (GTK_WIDGET (dialog)); - - dialog->progress_active = FALSE; } } @@ -179,10 +181,7 @@ gimp_progress_dialog_progress_set_text (GimpProgress *progress, { GimpProgressDialog *dialog = GIMP_PROGRESS_DIALOG (progress); - if (dialog->progress_active) - { - gtk_label_set_text (GTK_LABEL (dialog->label), message); - } + gimp_progress_set_text (GIMP_PROGRESS (dialog->box), message); } static void @@ -191,15 +190,7 @@ gimp_progress_dialog_progress_set_value (GimpProgress *progress, { GimpProgressDialog *dialog = GIMP_PROGRESS_DIALOG (progress); - if (dialog->progress_active) - { - GtkProgressBar *bar = GTK_PROGRESS_BAR (dialog->progressbar); - - gtk_progress_bar_set_fraction (bar, percentage); - - if (GTK_WIDGET_DRAWABLE (dialog->progressbar)) - gdk_window_process_updates (dialog->progressbar->window, TRUE); - } + gimp_progress_set_value (GIMP_PROGRESS (dialog->box), percentage); } static gdouble @@ -207,45 +198,15 @@ gimp_progress_dialog_progress_get_value (GimpProgress *progress) { GimpProgressDialog *dialog = GIMP_PROGRESS_DIALOG (progress); - if (dialog->progress_active) - { - GtkProgressBar *bar = GTK_PROGRESS_BAR (dialog->progressbar); - - return gtk_progress_bar_get_fraction (bar); - } - - return 0.0; + return gimp_progress_get_value (GIMP_PROGRESS (dialog->box)); } GtkWidget * gimp_progress_dialog_new (void) { - GimpProgressDialog *dialog; - GtkWidget *vbox; - - dialog = g_object_new (GIMP_TYPE_PROGRESS_DIALOG, - "title", _("Progress"), - "role", "progress", - "resizable", FALSE, - NULL); - - gtk_dialog_add_button (GTK_DIALOG (dialog), - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); - - vbox = gtk_vbox_new (FALSE, 12); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 12); - gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), vbox); - gtk_widget_show (vbox); - - dialog->label = gtk_label_new (""); - gtk_misc_set_alignment (GTK_MISC (dialog->label), 0.0, 0.5); - gtk_box_pack_start (GTK_BOX (vbox), dialog->label, FALSE, FALSE, 0); - gtk_widget_show (dialog->label); - - dialog->progressbar = gtk_progress_bar_new (); - gtk_widget_set_size_request (dialog->progressbar, 150, 20); - gtk_box_pack_start (GTK_BOX (vbox), dialog->progressbar, FALSE, FALSE, 0); - gtk_widget_show (dialog->progressbar); - - return GTK_WIDGET (dialog); + return g_object_new (GIMP_TYPE_PROGRESS_DIALOG, + "title", _("Progress"), + "role", "progress", + "resizable", FALSE, + NULL); } diff --git a/app/widgets/gimpprogressdialog.h b/app/widgets/gimpprogressdialog.h index 8c83185a8c..25059436b5 100644 --- a/app/widgets/gimpprogressdialog.h +++ b/app/widgets/gimpprogressdialog.h @@ -41,9 +41,7 @@ struct _GimpProgressDialog { GimpDialog parent_instance; - gboolean progress_active; - GtkWidget *label; - GtkWidget *progressbar; + GtkWidget *box; }; struct _GimpProgressDialogClass diff --git a/app/widgets/gimpwidgets-utils.c b/app/widgets/gimpwidgets-utils.c index a8e1ce2042..38191a9c43 100644 --- a/app/widgets/gimpwidgets-utils.c +++ b/app/widgets/gimpwidgets-utils.c @@ -864,3 +864,31 @@ gimp_window_set_hint (GtkWindow *window, break; } } + +void +gimp_dialog_set_sensitive (GtkDialog *dialog, + gboolean sensitive) +{ + GList *children; + GList *list; + + g_return_if_fail (GTK_IS_DIALOG (dialog)); + + children = gtk_container_get_children (GTK_CONTAINER (dialog->vbox)); + + for (list = children; list; list = g_list_next (list)) + { + /* skip the last item (the action area) */ + if (! g_list_next (list)) + break; + + gtk_widget_set_sensitive (list->data, sensitive); + } + + g_list_free (children); + + if (sensitive) + gtk_dialog_set_response_sensitive (dialog, GTK_RESPONSE_CANCEL, sensitive); + + gtk_dialog_set_response_sensitive (dialog, GTK_RESPONSE_OK, sensitive); +} diff --git a/app/widgets/gimpwidgets-utils.h b/app/widgets/gimpwidgets-utils.h index 280f290d13..df2af53dd1 100644 --- a/app/widgets/gimpwidgets-utils.h +++ b/app/widgets/gimpwidgets-utils.h @@ -72,5 +72,8 @@ void gimp_rgb_set_gdk_color (GimpRGB *rgb, void gimp_window_set_hint (GtkWindow *window, GimpWindowHint hint); +void gimp_dialog_set_sensitive (GtkDialog *dialog, + gboolean sensitive); + #endif /* __GIMP_WIDGETS_UTILS_H__ */ diff --git a/app/widgets/widgets-types.h b/app/widgets/widgets-types.h index 54e54b5ed8..f9c0bea223 100644 --- a/app/widgets/widgets-types.h +++ b/app/widgets/widgets-types.h @@ -154,6 +154,7 @@ typedef struct _GimpFileProcView GimpFileProcView; typedef struct _GimpGridEditor GimpGridEditor; typedef struct _GimpHistogramBox GimpHistogramBox; typedef struct _GimpHistogramView GimpHistogramView; +typedef struct _GimpProgressBox GimpProgressBox; typedef struct _GimpStrokeEditor GimpStrokeEditor; typedef struct _GimpTemplateEditor GimpTemplateEditor; typedef struct _GimpThumbBox GimpThumbBox;