2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2005-04-05 06:34:29 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* image-properties-dialog.c
|
|
|
|
* Copyright (C) 2005 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"
|
|
|
|
|
2007-06-27 17:06:32 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2005-04-05 06:34:29 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2006-11-03 22:22:46 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2005-04-05 06:34:29 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "dialogs-types.h"
|
|
|
|
|
2006-09-01 19:26:54 +08:00
|
|
|
#include "core/gimpcontext.h"
|
2005-04-05 06:34:29 +08:00
|
|
|
#include "core/gimpimage.h"
|
|
|
|
|
|
|
|
#include "widgets/gimphelp-ids.h"
|
|
|
|
#include "widgets/gimpimagepropview.h"
|
2006-10-25 15:31:04 +08:00
|
|
|
#include "widgets/gimpimageprofileview.h"
|
2005-04-05 06:34:29 +08:00
|
|
|
#include "widgets/gimpviewabledialog.h"
|
|
|
|
|
|
|
|
#include "image-properties-dialog.h"
|
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
2007-06-27 17:06:32 +08:00
|
|
|
static GtkWidget * image_comment_view_new (GimpImage *image);
|
|
|
|
static void image_comment_view_update (GimpImageParasiteView *view,
|
|
|
|
GtkTextBuffer *buffer);
|
|
|
|
static void image_comment_buffer_changed (GtkTextBuffer *buffer,
|
|
|
|
GimpImageParasiteView *view);
|
2006-11-03 22:22:46 +08:00
|
|
|
|
|
|
|
|
2005-04-05 06:34:29 +08:00
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
GtkWidget *
|
2006-09-01 19:26:54 +08:00
|
|
|
image_properties_dialog_new (GimpImage *image,
|
|
|
|
GimpContext *context,
|
|
|
|
GtkWidget *parent)
|
2005-04-05 06:34:29 +08:00
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
2006-10-25 15:31:04 +08:00
|
|
|
GtkWidget *notebook;
|
2005-04-05 06:34:29 +08:00
|
|
|
GtkWidget *view;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
2006-10-15 02:15:41 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
2005-04-05 06:34:29 +08:00
|
|
|
g_return_val_if_fail (parent == NULL || GTK_IS_WIDGET (parent), NULL);
|
|
|
|
|
2006-09-01 19:26:54 +08:00
|
|
|
dialog = gimp_viewable_dialog_new (GIMP_VIEWABLE (image), context,
|
2005-04-05 06:34:29 +08:00
|
|
|
_("Image Properties"),
|
|
|
|
"gimp-image-properties",
|
2005-12-30 09:45:40 +08:00
|
|
|
GTK_STOCK_INFO,
|
2005-04-05 17:17:40 +08:00
|
|
|
_("Image Properties"),
|
2005-04-05 06:34:29 +08:00
|
|
|
parent,
|
|
|
|
gimp_standard_help_func,
|
|
|
|
GIMP_HELP_IMAGE_PROPERTIES,
|
|
|
|
|
|
|
|
GTK_STOCK_CLOSE, GTK_RESPONSE_OK,
|
|
|
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
|
|
|
|
|
|
|
|
g_signal_connect (dialog, "response",
|
|
|
|
G_CALLBACK (gtk_widget_destroy),
|
|
|
|
NULL);
|
|
|
|
|
2006-10-25 15:31:04 +08:00
|
|
|
notebook = gtk_notebook_new ();
|
|
|
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), notebook,
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (notebook);
|
|
|
|
|
2005-04-05 06:34:29 +08:00
|
|
|
view = gimp_image_prop_view_new (image);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (view), 12);
|
2006-10-25 15:31:04 +08:00
|
|
|
gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
|
|
|
|
view, gtk_label_new (_("Properties")));
|
|
|
|
gtk_widget_show (view);
|
|
|
|
|
|
|
|
view = gimp_image_profile_view_new (image);
|
|
|
|
gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
|
|
|
|
view, gtk_label_new (_("Color Profile")));
|
2005-04-05 06:34:29 +08:00
|
|
|
gtk_widget_show (view);
|
|
|
|
|
2007-06-26 23:07:58 +08:00
|
|
|
view = image_comment_view_new (image);
|
2006-11-03 22:22:46 +08:00
|
|
|
gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
|
|
|
|
view, gtk_label_new (_("Comment")));
|
2007-06-27 17:06:32 +08:00
|
|
|
gtk_widget_show (view);
|
2006-11-03 22:22:46 +08:00
|
|
|
|
2007-06-26 23:07:58 +08:00
|
|
|
gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), 0);
|
|
|
|
|
|
|
|
return dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
image_comment_view_new (GimpImage *image)
|
|
|
|
{
|
|
|
|
GtkWidget *view;
|
|
|
|
GtkWidget *scrolled_window;
|
|
|
|
GtkWidget *text_view;
|
|
|
|
GtkTextBuffer *buffer;
|
|
|
|
|
|
|
|
view = gimp_image_parasite_view_new (image, "gimp-comment");
|
|
|
|
|
|
|
|
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
|
|
|
|
GTK_POLICY_AUTOMATIC,
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 2);
|
|
|
|
gtk_container_add (GTK_CONTAINER (view), scrolled_window);
|
|
|
|
gtk_widget_show (scrolled_window);
|
|
|
|
|
|
|
|
text_view = gtk_text_view_new ();
|
2007-06-27 17:06:32 +08:00
|
|
|
|
|
|
|
gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), TRUE);
|
|
|
|
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), GTK_WRAP_WORD);
|
|
|
|
|
2007-06-27 06:09:43 +08:00
|
|
|
gtk_text_view_set_pixels_above_lines (GTK_TEXT_VIEW (text_view), 6);
|
|
|
|
gtk_text_view_set_left_margin (GTK_TEXT_VIEW (text_view), 6);
|
|
|
|
gtk_text_view_set_right_margin (GTK_TEXT_VIEW (text_view), 6);
|
2007-06-27 17:06:32 +08:00
|
|
|
|
2007-06-26 23:07:58 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (scrolled_window), text_view);
|
|
|
|
gtk_widget_show (text_view);
|
|
|
|
|
|
|
|
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
|
2006-11-03 22:22:46 +08:00
|
|
|
|
|
|
|
g_signal_connect (view, "update",
|
2007-06-26 23:07:58 +08:00
|
|
|
G_CALLBACK (image_comment_view_update),
|
|
|
|
buffer);
|
2006-11-03 22:22:46 +08:00
|
|
|
|
2007-06-27 17:06:32 +08:00
|
|
|
g_signal_connect (buffer, "changed",
|
|
|
|
G_CALLBACK (image_comment_buffer_changed),
|
|
|
|
view);
|
|
|
|
|
|
|
|
image_comment_view_update (GIMP_IMAGE_PARASITE_VIEW (view), buffer);
|
2006-11-03 22:22:46 +08:00
|
|
|
|
2007-06-26 23:07:58 +08:00
|
|
|
return view;
|
2005-04-05 06:34:29 +08:00
|
|
|
}
|
2006-11-03 22:22:46 +08:00
|
|
|
|
|
|
|
static void
|
2007-06-27 17:06:32 +08:00
|
|
|
image_comment_view_update (GimpImageParasiteView *view,
|
|
|
|
GtkTextBuffer *buffer)
|
2006-11-03 22:22:46 +08:00
|
|
|
{
|
2007-06-27 17:06:32 +08:00
|
|
|
GimpImage *image = gimp_image_parasite_view_get_image (view);
|
|
|
|
const GimpParasite *parasite;
|
|
|
|
|
|
|
|
g_signal_handlers_block_by_func (buffer,
|
|
|
|
image_comment_buffer_changed, image);
|
2006-11-03 22:22:46 +08:00
|
|
|
|
|
|
|
parasite = gimp_image_parasite_view_get_parasite (view);
|
|
|
|
|
|
|
|
if (parasite)
|
|
|
|
{
|
|
|
|
gchar *text = g_strndup (gimp_parasite_data (parasite),
|
|
|
|
gimp_parasite_data_size (parasite));
|
|
|
|
|
2006-11-03 22:37:01 +08:00
|
|
|
if (! g_utf8_validate (text, -1, NULL))
|
2006-11-03 22:22:46 +08:00
|
|
|
{
|
2006-11-03 22:37:01 +08:00
|
|
|
gchar *tmp = gimp_any_to_utf8 (text, -1, NULL);
|
|
|
|
|
|
|
|
g_free (text);
|
|
|
|
text = tmp;
|
2006-11-03 22:22:46 +08:00
|
|
|
}
|
|
|
|
|
2007-06-26 23:07:58 +08:00
|
|
|
gtk_text_buffer_set_text (buffer, text, -1);
|
2006-11-03 22:22:46 +08:00
|
|
|
g_free (text);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-06-26 23:07:58 +08:00
|
|
|
gtk_text_buffer_set_text (buffer, "", 0);
|
2006-11-03 22:22:46 +08:00
|
|
|
}
|
2007-06-27 17:06:32 +08:00
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (buffer,
|
|
|
|
image_comment_buffer_changed, image);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
image_comment_buffer_changed (GtkTextBuffer *buffer,
|
|
|
|
GimpImageParasiteView *view)
|
|
|
|
{
|
|
|
|
GimpImage *image = gimp_image_parasite_view_get_image (view);
|
|
|
|
gchar *text;
|
|
|
|
gint len;
|
|
|
|
GtkTextIter start;
|
|
|
|
GtkTextIter end;
|
|
|
|
|
|
|
|
g_signal_handlers_block_by_func (view,
|
|
|
|
image_comment_view_update, buffer);
|
|
|
|
|
|
|
|
gtk_text_buffer_get_bounds (buffer, &start, &end);
|
|
|
|
|
|
|
|
text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
|
|
|
|
|
|
|
|
len = text ? strlen (text) : 0;
|
|
|
|
|
|
|
|
if (len > 0)
|
|
|
|
{
|
|
|
|
GimpParasite *parasite;
|
|
|
|
|
|
|
|
parasite = gimp_parasite_new ("gimp-comment",
|
|
|
|
GIMP_PARASITE_PERSISTENT,
|
|
|
|
len + 1, text);
|
|
|
|
|
|
|
|
gimp_image_parasite_attach (image, parasite);
|
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_image_parasite_detach (image, "gimp-comment");
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (text);
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (view,
|
|
|
|
image_comment_view_update, buffer);
|
2006-11-03 22:22:46 +08:00
|
|
|
}
|