2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-07-09 05:44:52 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
2004-04-20 21:25:55 +08:00
|
|
|
#include "actions-types.h"
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2006-10-10 02:49:15 +08:00
|
|
|
#include "core/gimp.h"
|
2004-07-22 21:58:29 +08:00
|
|
|
#include "core/gimpgradient-save.h"
|
2001-07-09 05:44:52 +08:00
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
|
2003-01-13 22:08:10 +08:00
|
|
|
#include "widgets/gimpcontainereditor.h"
|
2001-07-09 05:44:52 +08:00
|
|
|
#include "widgets/gimpcontainerview.h"
|
2003-08-21 23:54:47 +08:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
2001-07-09 05:44:52 +08:00
|
|
|
|
|
|
|
#include "gradients-commands.h"
|
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2001-07-09 05:44:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* local function prototypes */
|
|
|
|
|
2004-10-18 19:29:58 +08:00
|
|
|
static void gradients_save_as_pov_ray_response (GtkWidget *dialog,
|
|
|
|
gint response_id,
|
|
|
|
GimpGradient *gradient);
|
2001-07-09 05:44:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
void
|
2004-04-29 20:52:29 +08:00
|
|
|
gradients_save_as_pov_ray_cmd_callback (GtkAction *action,
|
2006-04-12 20:49:29 +08:00
|
|
|
gpointer data)
|
2001-07-09 05:44:52 +08:00
|
|
|
{
|
2004-02-01 04:23:53 +08:00
|
|
|
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
|
2004-10-18 19:29:58 +08:00
|
|
|
GimpContext *context;
|
|
|
|
GimpGradient *gradient;
|
|
|
|
GtkFileChooser *chooser;
|
|
|
|
gchar *title;
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2004-05-11 01:16:50 +08:00
|
|
|
context = gimp_container_view_get_context (editor->view);
|
|
|
|
|
|
|
|
gradient = gimp_context_get_gradient (context);
|
2001-07-09 05:44:52 +08:00
|
|
|
|
|
|
|
if (! gradient)
|
|
|
|
return;
|
|
|
|
|
2003-11-18 02:29:59 +08:00
|
|
|
title = g_strdup_printf (_("Save '%s' as POV-Ray"),
|
2006-04-12 20:49:29 +08:00
|
|
|
GIMP_OBJECT (gradient)->name);
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2004-04-16 00:28:26 +08:00
|
|
|
chooser = GTK_FILE_CHOOSER
|
|
|
|
(gtk_file_chooser_dialog_new (title, NULL,
|
|
|
|
GTK_FILE_CHOOSER_ACTION_SAVE,
|
|
|
|
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_SAVE, GTK_RESPONSE_OK,
|
|
|
|
|
|
|
|
NULL));
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2005-02-10 19:00:46 +08:00
|
|
|
gtk_dialog_set_alternative_button_order (GTK_DIALOG (chooser),
|
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
|
|
|
|
2006-10-10 02:49:15 +08:00
|
|
|
g_object_set_data (G_OBJECT (chooser), "gimp", context->gimp);
|
|
|
|
|
2001-07-09 05:44:52 +08:00
|
|
|
g_free (title);
|
|
|
|
|
2004-04-16 00:28:26 +08:00
|
|
|
gtk_window_set_screen (GTK_WINDOW (chooser),
|
2003-11-10 06:05:37 +08:00
|
|
|
gtk_widget_get_screen (GTK_WIDGET (editor)));
|
|
|
|
|
2004-04-16 00:28:26 +08:00
|
|
|
gtk_window_set_role (GTK_WINDOW (chooser), "gimp-gradient-save-pov");
|
|
|
|
gtk_window_set_position (GTK_WINDOW (chooser), GTK_WIN_POS_MOUSE);
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2007-02-02 15:50:36 +08:00
|
|
|
gtk_dialog_set_default_response (GTK_DIALOG (chooser), GTK_RESPONSE_OK);
|
|
|
|
gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
|
|
|
|
|
2004-04-16 00:28:26 +08:00
|
|
|
g_signal_connect (chooser, "response",
|
2004-10-18 19:29:58 +08:00
|
|
|
G_CALLBACK (gradients_save_as_pov_ray_response),
|
2001-07-28 03:41:54 +08:00
|
|
|
gradient);
|
2005-05-28 00:51:39 +08:00
|
|
|
g_signal_connect (chooser, "delete-event",
|
2004-04-16 00:28:26 +08:00
|
|
|
G_CALLBACK (gtk_true),
|
|
|
|
NULL);
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_object_ref (gradient);
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2004-04-16 00:28:26 +08:00
|
|
|
g_signal_connect_object (chooser, "destroy",
|
2001-07-28 03:41:54 +08:00
|
|
|
G_CALLBACK (g_object_unref),
|
2003-11-08 01:29:02 +08:00
|
|
|
gradient,
|
2001-07-28 03:41:54 +08:00
|
|
|
G_CONNECT_SWAPPED);
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2004-04-16 00:28:26 +08:00
|
|
|
gimp_help_connect (GTK_WIDGET (chooser), gimp_standard_help_func,
|
2006-04-12 20:49:29 +08:00
|
|
|
GIMP_HELP_GRADIENT_SAVE_AS_POV, NULL);
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2004-04-16 00:28:26 +08:00
|
|
|
gtk_widget_show (GTK_WIDGET (chooser));
|
2001-07-09 05:44:52 +08:00
|
|
|
}
|
|
|
|
|
2004-10-18 19:29:58 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2001-07-09 05:44:52 +08:00
|
|
|
static void
|
2004-10-18 19:29:58 +08:00
|
|
|
gradients_save_as_pov_ray_response (GtkWidget *dialog,
|
|
|
|
gint response_id,
|
|
|
|
GimpGradient *gradient)
|
2001-07-09 05:44:52 +08:00
|
|
|
{
|
2003-11-18 02:29:59 +08:00
|
|
|
if (response_id == GTK_RESPONSE_OK)
|
|
|
|
{
|
|
|
|
const gchar *filename;
|
|
|
|
GError *error = NULL;
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2004-04-16 00:28:26 +08:00
|
|
|
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2006-10-03 20:38:36 +08:00
|
|
|
if (! gimp_gradient_save_pov (gradient, filename, &error))
|
2003-11-18 02:29:59 +08:00
|
|
|
{
|
2008-11-04 20:33:09 +08:00
|
|
|
gimp_message_literal (g_object_get_data (G_OBJECT (dialog), "gimp"),
|
|
|
|
G_OBJECT (dialog), GIMP_MESSAGE_ERROR,
|
|
|
|
error->message);
|
2003-11-18 02:29:59 +08:00
|
|
|
g_clear_error (&error);
|
2006-10-10 02:49:15 +08:00
|
|
|
return;
|
2003-11-18 02:29:59 +08:00
|
|
|
}
|
2001-07-09 05:44:52 +08:00
|
|
|
}
|
|
|
|
|
2003-11-18 02:29:59 +08:00
|
|
|
gtk_widget_destroy (dialog);
|
2001-07-09 05:44:52 +08:00
|
|
|
}
|