Commit 06ea7dbd authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

app/widgets/Makefile.am app/widgets/widgets-types.h new GtkVBox subclass

2004-08-11  Michael Natterer  <mitch@gimp.org>

	* 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.
parent 95607cce
2004-08-11 Michael Natterer <mitch@gimp.org>
* 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 <mitch@gimp.org>
* app/widgets/gimpfiledialog.[ch]
......
......@@ -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)
{
box = g_object_get_data (G_OBJECT (dialog), "progress-box");
if (box && GIMP_PROGRESS_BOX (box)->active)
gimp_progress_cancel (GIMP_PROGRESS (box));
else
gtk_widget_destroy (GTK_WIDGET (dialog));
return;
}
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))
{
GtkWidget *entry;
const gchar *text = NULL;
GimpImage *image;
gchar *uri;
gchar *filename;
GError *error = NULL;
GimpPDBStatusType status;
gtk_widget_set_sensitive (dialog, FALSE);
filename = g_filename_from_uri (text, NULL, NULL);
entry = g_object_get_data (G_OBJECT (dialog), "location-entry");
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);
text = gtk_entry_get_text (GTK_ENTRY (entry));
g_object_set_data (G_OBJECT (dialog), "progress-box", box);
if (text && strlen (text))
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)
{
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);
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 (dialog);
gtk_widget_destroy (GTK_WIDGET (dialog));
}
static gboolean
......
......@@ -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)
{
box = g_object_get_data (G_OBJECT (dialog), "progress-box");
if (box && GIMP_PROGRESS_BOX (box)->active)
gimp_progress_cancel (GIMP_PROGRESS (box));
else
gtk_widget_destroy (GTK_WIDGET (dialog));
return;
}
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))
{
GtkWidget *entry;
const gchar *text = NULL;
GimpImage *image;
gchar *uri;
gchar *filename;
GError *error = NULL;
GimpPDBStatusType status;
gtk_widget_set_sensitive (dialog, FALSE);
filename = g_filename_from_uri (text, NULL, NULL);
entry = g_object_get_data (G_OBJECT (dialog), "location-entry");
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);
text = gtk_entry_get_text (GTK_ENTRY (entry));
g_object_set_data (G_OBJECT (dialog), "progress-box", box);
if (text && strlen (text))
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)
{
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);
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 (dialog);
gtk_widget_destroy (GTK_WIDGET (dialog));
}
static gboolean
......
......@@ -206,6 +206,8 @@ libappwidgets_a_sources = \
gimppreviewrendererlayer.h \
gimppreviewrenderervectors.c \
gimppreviewrenderervectors.h \
gimpprogressbox.c \
gimpprogressbox.h \
gimpprogressdialog.c \
gimpprogressdialog.h \
gimppropwidgets.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;
......
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpprogressbox.c
* Copyright (C) 2004 Michael Natterer <mitch@gimp.org>
*
* 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 <gtk/gtk.h>
#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);
}
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpprogressbox.h
* Copyright (C) 2004 Michael Natterer <mitch@gimp.org>
*
* 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.
*