Gimp/app/tools/gimpimagemaptool-settings.c
Sven Neumann 4762b73403 bumped minimum required version of GLib to 2.18.0.
2008-11-04  Sven Neumann  <sven@sven>

	* configure.in: bumped minimum required version of GLib to 
2.18.0.

	* INSTALL: document the updated dependency.

	* app/core/gimp.[ch]: introduced gimp_message_literal(), a 
variant
	of gimp_message() that takes a literal string.

	* app/errors.[ch]: removed format arguments from 
gimp_fatal_error()
	and gimp_terminate() and let them take a literal string instead.

	* app/tools/gimptool.[ch]: introduced 
gimp_tool_message_literal(),
	a variant of gimp_tool_message() that takes a literal string.

	* app/actions/documents-commands.c
	* app/actions/drawable-commands.c
	* app/actions/edit-commands.c
	* app/actions/error-console-commands.c
	* app/actions/file-commands.c
	* app/actions/gradients-commands.c
	* app/actions/image-commands.c
	* app/actions/layers-commands.c
	* app/actions/palettes-commands.c
	* app/actions/plug-in-commands.c
	* app/actions/select-commands.c
	* app/actions/vectors-commands.c
	* app/config/gimprc.c
	* app/core/gimp-modules.c
	* app/core/gimp-parasites.c
	* app/core/gimp-templates.c
	* app/core/gimp-units.c
	* app/core/gimpchannel.c
	* app/core/gimpcontainer-filter.c
	* app/core/gimpdrawable-bucket-fill.c
	* app/core/gimpimage-convert.c
	* app/core/gimpimage-merge.c
	* app/core/gimpimage.c
	* app/core/gimpimagefile.c
	* app/core/gimplayer-floating-sel.c
	* app/core/gimplayer.c
	* app/core/gimpselection.c
	* app/dialogs/convert-dialog.c
	* app/dialogs/dialogs.c
	* app/dialogs/palette-import-dialog.c
	* app/dialogs/preferences-dialog.c
	* app/dialogs/quit-dialog.c
	* app/dialogs/stroke-dialog.c
	* app/display/gimpdisplayshell-dnd.c
	* app/file/file-open.c
	* app/file/file-procedure.c
	* app/file/file-save.c
	* app/file/file-utils.c
	* app/gegl/gimpcurvesconfig.c
	* app/gegl/gimplevelsconfig.c
	* app/gui/gui-message.c
	* app/gui/gui.c
	* app/gui/session.c
	* app/paint/gimpbrushcore.c
	* app/paint/gimpclone.c
	* app/paint/gimpheal.c
	* app/paint/gimpperspectiveclone.c
	* app/paint/gimpsourcecore.c
	* app/pdb/gimppdb-utils.c
	* app/pdb/gimpprocedure.c
	* app/plug-in/gimpplugin-message.c
	* app/plug-in/gimpplugin.c
	* app/plug-in/gimppluginmanager-restore.c
	* app/plug-in/gimppluginprocedure.c
	* app/text/gimptextlayer.c
	* app/tools/gimp-tools.c
	* app/tools/gimpaligntool.c
	* app/tools/gimpblendtool.c
	* app/tools/gimpbrightnesscontrasttool.c
	* app/tools/gimpbucketfilltool.c
	* app/tools/gimpcolorbalancetool.c
	* app/tools/gimpcolorpickertool.c
	* app/tools/gimpcurvestool.c
	* app/tools/gimpdesaturatetool.c
	* app/tools/gimpeditselectiontool.c
	* app/tools/gimpforegroundselecttool.c
	* app/tools/gimpfreeselecttool.c
	* app/tools/gimpgegltool.c
	* app/tools/gimphuesaturationtool.c
	* app/tools/gimpimagemaptool-settings.c
	* app/tools/gimpiscissorstool.c
	* app/tools/gimplevelstool.c
	* app/tools/gimpmeasuretool.c
	* app/tools/gimppainttool.c
	* app/tools/gimpposterizetool.c
	* app/tools/gimpselectiontool.c
	* app/tools/gimpsourcetool.c
	* app/tools/gimpthresholdtool.c
	* app/tools/gimptransformtool.c
	* app/tools/gimpvectortool.c
	* app/widgets/gimpactionview.c
	* app/widgets/gimpcontrollerlist.c
	* app/widgets/gimpcontrollers.c
	* app/widgets/gimpdataeditor.c
	* app/widgets/gimpdevices.c
	* app/widgets/gimpdnd-xds.c
	* app/widgets/gimperrordialog.c
	* app/widgets/gimphelp.c
	* app/widgets/gimpitemtreeview.c
	* app/widgets/gimppdbdialog.c
	* app/widgets/gimpsettingsbox.c
	* app/widgets/gimpvectorstreeview.c
	* app/widgets/gimpwidgets-utils.c
	* app/xcf/xcf-load.c
	* tools/pdbgen/pdb/convert.pdb
	* tools/pdbgen/pdb/edit.pdb
	* tools/pdbgen/pdb/floating_sel.pdb
	* tools/pdbgen/pdb/image.pdb: use the _literal variants for
	g_set_error(), gimp_message() and gimp_tool_message().

	* app/pdb/convert-cmds.c
	* app/pdb/edit-cmds.c
	* app/pdb/floating-sel-cmds.c
	* app/pdb/image-cmds.c: regenerated.


svn path=/trunk/; revision=27548
2008-11-04 12:33:09 +00:00

232 lines
7.7 KiB
C

/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpimagemaptool-settings.c
*
* 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 <errno.h>
#include <glib/gstdio.h>
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpconfig/gimpconfig.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "tools-types.h"
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimpimagemapconfig.h"
#include "core/gimplist.h"
#include "core/gimptoolinfo.h"
#include "widgets/gimpsettingsbox.h"
#include "gimpimagemapoptions.h"
#include "gimpimagemaptool.h"
#include "gimpimagemaptool-settings.h"
#include "gimp-intl.h"
/* local function prototypes */
static gboolean gimp_image_map_tool_settings_import (GimpSettingsBox *box,
const gchar *filename,
GimpImageMapTool *tool);
static gboolean gimp_image_map_tool_settings_export (GimpSettingsBox *box,
const gchar *filename,
GimpImageMapTool *tool);
/* public functions */
gboolean
gimp_image_map_tool_add_settings_gui (GimpImageMapTool *image_map_tool)
{
GimpImageMapToolClass *klass;
GimpToolInfo *tool_info;
GtkWidget *hbox;
GtkWidget *label;
gchar *filename;
gchar *folder;
klass = GIMP_IMAGE_MAP_TOOL_GET_CLASS (image_map_tool);
tool_info = GIMP_TOOL (image_map_tool)->tool_info;
hbox = gtk_hbox_new (FALSE, 6);
gtk_box_pack_start (GTK_BOX (image_map_tool->main_vbox), hbox,
FALSE, FALSE, 0);
gtk_widget_show (hbox);
label = gtk_label_new_with_mnemonic (_("Pre_sets:"));
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
image_map_tool->label_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
gtk_size_group_add_widget (image_map_tool->label_group, label);
g_object_unref (image_map_tool->label_group);
filename = gimp_tool_info_build_options_filename (tool_info, ".settings");
folder = g_build_filename (gimp_directory (), klass->settings_name, NULL);
image_map_tool->settings_box = gimp_settings_box_new (tool_info->gimp,
image_map_tool->config,
klass->recent_settings,
filename,
klass->import_dialog_title,
klass->export_dialog_title,
tool_info->help_id,
folder,
NULL);
gtk_box_pack_start (GTK_BOX (hbox), image_map_tool->settings_box,
TRUE, TRUE, 0);
gtk_widget_show (image_map_tool->settings_box);
g_free (filename);
g_free (folder);
gtk_label_set_mnemonic_widget (GTK_LABEL (label),
GIMP_SETTINGS_BOX (image_map_tool->settings_box)->combo);
g_signal_connect (image_map_tool->settings_box, "import",
G_CALLBACK (gimp_image_map_tool_settings_import),
image_map_tool);
g_signal_connect (image_map_tool->settings_box, "export",
G_CALLBACK (gimp_image_map_tool_settings_export),
image_map_tool);
return TRUE;
}
gboolean
gimp_image_map_tool_real_settings_import (GimpImageMapTool *tool,
const gchar *filename,
GError **error)
{
gboolean success;
if (GIMP_TOOL (tool)->tool_info->gimp->be_verbose)
g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));
success = gimp_config_deserialize_file (GIMP_CONFIG (tool->config),
filename,
NULL, error);
return success;
}
gboolean
gimp_image_map_tool_real_settings_export (GimpImageMapTool *tool,
const gchar *filename,
GError **error)
{
GimpImageMapToolClass *klass = GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool);
gchar *header;
gchar *footer;
gboolean success;
header = g_strdup_printf ("GIMP %s tool settings", klass->settings_name);
footer = g_strdup_printf ("end of %s tool settings", klass->settings_name);
if (GIMP_TOOL (tool)->tool_info->gimp->be_verbose)
g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename));
success = gimp_config_serialize_to_file (GIMP_CONFIG (tool->config),
filename,
header, footer,
NULL, error);
g_free (header);
g_free (footer);
return success;
}
/* private functions */
static gboolean
gimp_image_map_tool_settings_import (GimpSettingsBox *box,
const gchar *filename,
GimpImageMapTool *tool)
{
GimpImageMapToolClass *tool_class = GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool);
GError *error = NULL;
g_return_val_if_fail (tool_class->settings_import != NULL, FALSE);
if (! tool_class->settings_import (tool, filename, &error))
{
gimp_message_literal (GIMP_TOOL (tool)->tool_info->gimp,
G_OBJECT (tool->shell),
GIMP_MESSAGE_ERROR, error->message);
g_clear_error (&error);
return FALSE;
}
gimp_image_map_tool_preview (tool);
g_object_set (GIMP_TOOL_GET_OPTIONS (tool),
"settings", filename,
NULL);
return TRUE;
}
static gboolean
gimp_image_map_tool_settings_export (GimpSettingsBox *box,
const gchar *filename,
GimpImageMapTool *tool)
{
GimpImageMapToolClass *tool_class = GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool);
GError *error = NULL;
gchar *display_name;
g_return_val_if_fail (tool_class->settings_export != NULL, FALSE);
if (! tool_class->settings_export (tool, filename, &error))
{
gimp_message_literal (GIMP_TOOL (tool)->tool_info->gimp,
G_OBJECT (tool->shell),
GIMP_MESSAGE_ERROR, error->message);
g_clear_error (&error);
return FALSE;
}
display_name = g_filename_display_name (filename);
gimp_message (GIMP_TOOL (tool)->tool_info->gimp,
G_OBJECT (GIMP_TOOL (tool)->display),
GIMP_MESSAGE_INFO,
_("Settings saved to '%s'"),
display_name);
g_free (display_name);
g_object_set (GIMP_TOOL_GET_OPTIONS (tool),
"settings", filename,
NULL);
return TRUE;
}