libgimpwidgets/Makefile.am libgimpwidgets/gimpwidgets.h

2007-08-14  Sven Neumann  <sven@gimp.org>

	* libgimpwidgets/Makefile.am
	* libgimpwidgets/gimpwidgets.h
	* libgimpwidgets/gimpwidgetstypes.h
	* libgimpwidgets/gimpcolorprofilecombobox.[ch]
	* libgimpwidgets/gimpcolorprofilestore.[ch]
	* libgimpwidgets/gimpcolorprofilestore-private.h: new widget to
	select color profiles.

	* libgimpwidgets/gimpwidgets.def: updated.

	* app/widgets/gimpprofilechooserdialog.[ch]: remember the name of
	the last previewed profile.

	* app/dialogs/preferences-dialog.c: use the new color profile
	combo-box.

	* plug-ins/common/lcms.c: use the new color profile combo-box.

svn path=/trunk/; revision=23253
This commit is contained in:
Sven Neumann 2007-08-14 16:01:04 +00:00 committed by Sven Neumann
parent 1e790b12fd
commit f3675a45ad
16 changed files with 1776 additions and 278 deletions

View File

@ -1,3 +1,23 @@
2007-08-14 Sven Neumann <sven@gimp.org>
* libgimpwidgets/Makefile.am
* libgimpwidgets/gimpwidgets.h
* libgimpwidgets/gimpwidgetstypes.h
* libgimpwidgets/gimpcolorprofilecombobox.[ch]
* libgimpwidgets/gimpcolorprofilestore.[ch]
* libgimpwidgets/gimpcolorprofilestore-private.h: new widget to
select color profiles.
* libgimpwidgets/gimpwidgets.def: updated.
* app/widgets/gimpprofilechooserdialog.[ch]: remember the name of
the last previewed profile.
* app/dialogs/preferences-dialog.c: use the new color profile
combo-box.
* plug-ins/common/lcms.c: use the new color profile combo-box.
2007-08-14 Michael Natterer <mitch@gimp.org>
* app/core/gimpimage-item-list.c: fixed API docs.

View File

@ -969,80 +969,88 @@ prefs_table_new (gint rows,
return table;
}
typedef struct
static void
prefs_profile_combo_dialog_response (GimpProfileChooserDialog *dialog,
gint response,
GimpColorProfileComboBox *combo)
{
GObject *config;
gchar *property_name;
} PrefsPropertyData;
if (response == GTK_RESPONSE_ACCEPT)
{
gchar *uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
static PrefsPropertyData *
prefs_property_data_new (GObject *config,
const gchar *property_name)
{
PrefsPropertyData *data = g_slice_new (PrefsPropertyData);
if (uri)
{
gchar *label = gimp_profile_chooser_dialog_get_desc (dialog, uri);
data->config = config;
data->property_name = g_strdup (property_name);
gimp_color_profile_combo_box_set_active (combo, uri, label);
return data;
g_free (label);
g_free (uri);
}
}
gtk_widget_hide (GTK_WIDGET (dialog));
}
static void
prefs_property_data_free (PrefsPropertyData *data)
prefs_profile_combo_changed (GimpColorProfileComboBox *combo,
GObject *config)
{
g_free (data->property_name);
g_slice_free (PrefsPropertyData, data);
}
gchar *uri = gimp_color_profile_combo_box_get_active (combo);
gchar *filename = uri ? g_filename_from_uri (uri, NULL, NULL) : NULL;
static void
prefs_profile_chooser_clear (PrefsPropertyData *data)
{
g_object_set (data->config,
data->property_name, NULL,
g_object_set (config,
g_object_get_data (G_OBJECT (combo), "property-name"), filename,
NULL);
g_free (filename);
g_free (uri);
}
static GtkWidget *
prefs_profile_chooser_button_new (Gimp *gimp,
GObject *config,
const gchar *label,
const gchar *property_name)
prefs_profile_combo_box_new (Gimp *gimp,
GObject *config,
GtkListStore *store,
const gchar *label,
const gchar *property_name)
{
GtkWidget *hbox;
GtkWidget *dialog;
GtkWidget *chooser;
GtkWidget *button;
GtkWidget *image;
PrefsPropertyData *data;
GtkWidget *dialog = gimp_profile_chooser_dialog_new (gimp, label);
GtkWidget *combo;
gchar *filename;
gchar *uri = NULL;
hbox = gtk_hbox_new (FALSE, 6);
g_object_get (config, property_name, &filename, NULL);
dialog = gimp_profile_chooser_dialog_new (gimp, label);
chooser = gimp_prop_file_chooser_button_new_with_dialog (config,
property_name,
dialog);
combo = gimp_color_profile_combo_box_new_with_model (dialog,
GTK_TREE_MODEL (store));
g_object_unref (dialog);
gtk_box_pack_start (GTK_BOX (hbox), chooser, TRUE, TRUE, 0);
gtk_widget_show (chooser);
g_object_set_data (G_OBJECT (combo),
"property-name", (gpointer) property_name);
button = gtk_button_new ();
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
if (filename)
{
uri = g_filename_to_uri (filename, NULL, NULL);
image = gtk_image_new_from_stock (GTK_STOCK_CLEAR, GTK_ICON_SIZE_BUTTON);
gtk_container_add (GTK_CONTAINER (button), image);
gtk_widget_show (image);
if (! uri)
g_warning ("couldn't convert filename to URI");
data = prefs_property_data_new (config, property_name);
g_object_weak_ref (G_OBJECT (button),
(GWeakNotify) prefs_property_data_free, data);
g_free (filename);
}
g_signal_connect_swapped (button, "clicked",
G_CALLBACK (prefs_profile_chooser_clear),
data);
gimp_color_profile_combo_box_set_active (GIMP_COLOR_PROFILE_COMBO_BOX (combo),
uri, NULL);
g_free (uri);
return hbox;
g_signal_connect (dialog, "response",
G_CALLBACK (prefs_profile_combo_dialog_response),
combo);
g_signal_connect (combo, "changed",
G_CALLBACK (prefs_profile_combo_changed),
config);
return combo;
}
static GtkWidget *
@ -2391,8 +2399,10 @@ prefs_dialog_new (Gimp *gimp,
N_("Select Printer Color Profile"), "printer-profile" }
};
GObject *color_config;
gint row = 0;
GObject *color_config;
GtkListStore *store;
gchar *filename;
gint row = 0;
g_object_get (object, "color-management", &color_config, NULL);
@ -2401,12 +2411,19 @@ prefs_dialog_new (Gimp *gimp,
GTK_TABLE (table), row++, NULL);
gtk_table_set_row_spacing (GTK_TABLE (table), row - 1, 12);
filename = gimp_personal_rc_file ("profilerc");
store = gimp_color_profile_store_new (filename);
g_free (filename);
gimp_color_profile_store_add (GIMP_COLOR_PROFILE_STORE (store), NULL, NULL);
for (i = 0; i < G_N_ELEMENTS (profiles); i++)
{
button = prefs_profile_chooser_button_new (gimp,
color_config,
gettext (profiles[i].fs_label),
profiles[i].property_name);
button = prefs_profile_combo_box_new (gimp,
color_config,
store,
gettext (profiles[i].fs_label),
profiles[i].property_name);
gimp_table_attach_aligned (GTK_TABLE (table), 0, row++,
gettext (profiles[i].label), 0.0, 0.5,
@ -2445,6 +2462,7 @@ prefs_dialog_new (Gimp *gimp,
gtk_table_set_row_spacing (GTK_TABLE (table), row - 1, 12);
g_object_unref (store);
g_object_unref (color_config);
button = prefs_enum_combo_box_add (object, "color-profile-policy", 0, 0,

View File

@ -236,11 +236,29 @@ gimp_profile_chooser_dialog_new (Gimp *gimp,
NULL);
}
gchar *
gimp_profile_chooser_dialog_get_desc (GimpProfileChooserDialog *dialog,
const gchar *uri)
{
g_return_val_if_fail (GIMP_IS_PROFILE_CHOOSER_DIALOG (dialog), NULL);
if (uri && dialog->uri && strcmp (uri, dialog->uri) == 0)
return g_strdup (dialog->desc);
return NULL;
}
static void
gimp_profile_chooser_dialog_update_preview (GimpProfileChooserDialog *dialog)
{
gtk_text_buffer_set_text (dialog->buffer, "", 0);
g_free (dialog->uri);
dialog->uri = NULL;
g_free (dialog->desc);
dialog->desc = NULL;
if (dialog->idle_id)
g_source_remove (dialog->idle_id);
@ -296,13 +314,15 @@ gimp_profile_view_query (GimpProfileChooserDialog *dialog)
if (filename)
{
gchar *name = NULL;
gchar *desc = NULL;
gchar *info = NULL;
if (plug_in_icc_profile_file_info (dialog->gimp,
gimp_get_user_context (dialog->gimp),
NULL,
filename,
NULL, NULL, &info,
&name, &desc, &info,
NULL))
{
gsize info_len = strlen (info);
@ -318,6 +338,23 @@ gimp_profile_view_query (GimpProfileChooserDialog *dialog)
}
gtk_text_buffer_set_text (dialog->buffer, info, info_len);
if (desc)
{
dialog->desc = desc;
desc = NULL;
}
else if (name)
{
dialog->desc = name;
name = NULL;
}
dialog->uri = uri;
uri = NULL;
g_free (name);
g_free (desc);
g_free (info);
}

View File

@ -41,6 +41,10 @@ struct _GimpProfileChooserDialog
Gimp *gimp;
GtkTextBuffer *buffer;
gchar *uri;
gchar *desc;
guint idle_id;
};
@ -50,10 +54,12 @@ struct _GimpProfileChooserDialogClass
};
GType gimp_profile_chooser_dialog_get_type (void) G_GNUC_CONST;
GType gimp_profile_chooser_dialog_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_profile_chooser_dialog_new (Gimp *gimp,
const gchar *title);
GtkWidget * gimp_profile_chooser_dialog_new (Gimp *gimp,
const gchar *title);
gchar * gimp_profile_chooser_dialog_get_desc (GimpProfileChooserDialog *dialog,
const gchar *uri);
#endif /* __GIMP_PROFILE_CHOOSER_DIALOG_H__ */

View File

@ -59,103 +59,108 @@ INCLUDES = \
lib_LTLIBRARIES = libgimpwidgets-2.0.la
libgimpwidgets_2_0_la_sources = \
gimpwidgets.c \
gimpwidgets.h \
gimpwidgetsenums.h \
gimpwidgetstypes.h \
gimpbrowser.c \
gimpbrowser.h \
gimpbutton.c \
gimpbutton.h \
gimpcellrenderercolor.c \
gimpcellrenderercolor.h \
gimpcellrenderertoggle.c\
gimpcellrenderertoggle.h\
gimpchainbutton.c \
gimpchainbutton.h \
gimpcolorarea.c \
gimpcolorarea.h \
gimpcolorbutton.c \
gimpcolorbutton.h \
gimpcolordisplay.c \
gimpcolordisplay.h \
gimpcolordisplaystack.c \
gimpcolordisplaystack.h \
gimpenumwidgets.c \
gimpenumwidgets.h \
gimpcolorhexentry.c \
gimpcolorhexentry.h \
gimpcolornotebook.c \
gimpcolornotebook.h \
gimpcolorscale.c \
gimpcolorscale.h \
gimpcolorscales.c \
gimpcolorscales.h \
gimpcolorselector.c \
gimpcolorselector.h \
gimpcolorselect.c \
gimpcolorselect.h \
gimpcolorselection.c \
gimpcolorselection.h \
gimpcontroller.c \
gimpcontroller.h \
gimpdialog.c \
gimpdialog.h \
gimpenumstore.c \
gimpenumstore.h \
gimpenumcombobox.c \
gimpenumcombobox.h \
gimpenumlabel.c \
gimpenumlabel.h \
gimpfileentry.c \
gimpfileentry.h \
gimpframe.c \
gimpframe.h \
gimphelpui.c \
gimphelpui.h \
gimphintbox.c \
gimphintbox.h \
gimpintcombobox.c \
gimpintcombobox.h \
gimpintstore.c \
gimpintstore.h \
gimpmemsizeentry.c \
gimpmemsizeentry.h \
gimpnumberpairentry.c \
gimpnumberpairentry.h \
gimpoldwidgets.c \
gimpoldwidgets.h \
gimpoffsetarea.c \
gimpoffsetarea.h \
gimppageselector.c \
gimppageselector.h \
gimppatheditor.c \
gimppatheditor.h \
gimppickbutton.c \
gimppickbutton.h \
gimppixmap.c \
gimppixmap.h \
gimppreview.c \
gimppreview.h \
gimppreviewarea.c \
gimppreviewarea.h \
gimppropwidgets.c \
gimppropwidgets.h \
gimpquerybox.c \
gimpquerybox.h \
gimpscrolledpreview.c \
gimpscrolledpreview.h \
gimpsizeentry.c \
gimpsizeentry.h \
gimpstock.c \
gimpstock.h \
gimpstringcombobox.c \
gimpstringcombobox.h \
gimpunitmenu.c \
gimpunitmenu.h \
gimpzoommodel.c \
gimpzoommodel.h \
gimpwidgets-private.c \
gimpwidgets.c \
gimpwidgets.h \
gimpwidgetsenums.h \
gimpwidgetstypes.h \
gimpbrowser.c \
gimpbrowser.h \
gimpbutton.c \
gimpbutton.h \
gimpcellrenderercolor.c \
gimpcellrenderercolor.h \
gimpcellrenderertoggle.c \
gimpcellrenderertoggle.h \
gimpchainbutton.c \
gimpchainbutton.h \
gimpcolorarea.c \
gimpcolorarea.h \
gimpcolorbutton.c \
gimpcolorbutton.h \
gimpcolordisplay.c \
gimpcolordisplay.h \
gimpcolordisplaystack.c \
gimpcolordisplaystack.h \
gimpenumwidgets.c \
gimpenumwidgets.h \
gimpcolorhexentry.c \
gimpcolorhexentry.h \
gimpcolorprofilecombobox.c \
gimpcolorprofilecombobox.h \
gimpcolorprofilestore.c \
gimpcolorprofilestore.h \
gimpcolorprofilestore-private.h \
gimpcolornotebook.c \
gimpcolornotebook.h \
gimpcolorscale.c \
gimpcolorscale.h \
gimpcolorscales.c \
gimpcolorscales.h \
gimpcolorselector.c \
gimpcolorselector.h \
gimpcolorselect.c \
gimpcolorselect.h \
gimpcolorselection.c \
gimpcolorselection.h \
gimpcontroller.c \
gimpcontroller.h \
gimpdialog.c \
gimpdialog.h \
gimpenumstore.c \
gimpenumstore.h \
gimpenumcombobox.c \
gimpenumcombobox.h \
gimpenumlabel.c \
gimpenumlabel.h \
gimpfileentry.c \
gimpfileentry.h \
gimpframe.c \
gimpframe.h \
gimphelpui.c \
gimphelpui.h \
gimphintbox.c \
gimphintbox.h \
gimpintcombobox.c \
gimpintcombobox.h \
gimpintstore.c \
gimpintstore.h \
gimpmemsizeentry.c \
gimpmemsizeentry.h \
gimpnumberpairentry.c \
gimpnumberpairentry.h \
gimpoldwidgets.c \
gimpoldwidgets.h \
gimpoffsetarea.c \
gimpoffsetarea.h \
gimppageselector.c \
gimppageselector.h \
gimppatheditor.c \
gimppatheditor.h \
gimppickbutton.c \
gimppickbutton.h \
gimppixmap.c \
gimppixmap.h \
gimppreview.c \
gimppreview.h \
gimppreviewarea.c \
gimppreviewarea.h \
gimppropwidgets.c \
gimppropwidgets.h \
gimpquerybox.c \
gimpquerybox.h \
gimpscrolledpreview.c \
gimpscrolledpreview.h \
gimpsizeentry.c \
gimpsizeentry.h \
gimpstock.c \
gimpstock.h \
gimpstringcombobox.c \
gimpstringcombobox.h \
gimpunitmenu.c \
gimpunitmenu.h \
gimpzoommodel.c \
gimpzoommodel.h \
gimpwidgets-private.c \
gimpwidgets-private.h
libgimpwidgets_2_0_la_built_sources = \
@ -171,66 +176,68 @@ libgimpwidgets_2_0_la_SOURCES = \
$(libgimpwidgets_2_0_la_sources)
libgimpwidgetsinclude_HEADERS = \
gimpwidgets.h \
gimpwidgetsenums.h \
gimpwidgetstypes.h \
gimpbrowser.h \
gimpbutton.h \
gimpcellrenderercolor.h \
gimpcellrenderertoggle.h\
gimpchainbutton.h \
gimpcolorarea.h \
gimpcolorbutton.h \
gimpcolordisplay.h \
gimpcolordisplaystack.h \
gimpcolorhexentry.h \
gimpcolornotebook.h \
gimpcolorscale.h \
gimpcolorscales.h \
gimpcolorselector.h \
gimpcolorselect.h \
gimpcolorselection.h \
gimpcontroller.h \
gimpdialog.h \
gimpenumcombobox.h \
gimpenumlabel.h \
gimpenumstore.h \
gimpenumwidgets.h \
gimpfileentry.h \
gimpframe.h \
gimphelpui.h \
gimphintbox.h \
gimpintcombobox.h \
gimpintstore.h \
gimpmemsizeentry.h \
gimpnumberpairentry.h \
gimpoldwidgets.h \
gimpoffsetarea.h \
gimppageselector.h \
gimppatheditor.h \
gimppickbutton.h \
gimppixmap.h \
gimppreview.h \
gimppreviewarea.h \
gimppropwidgets.h \
gimpquerybox.h \
gimpscrolledpreview.h \
gimpsizeentry.h \
gimpstock.h \
gimpstringcombobox.h \
gimpunitmenu.h \
gimpwidgets.h \
gimpwidgetsenums.h \
gimpwidgetstypes.h \
gimpbrowser.h \
gimpbutton.h \
gimpcellrenderercolor.h \
gimpcellrenderertoggle.h \
gimpchainbutton.h \
gimpcolorarea.h \
gimpcolorbutton.h \
gimpcolorprofilecombobox.h \
gimpcolorprofilestore.h \
gimpcolordisplay.h \
gimpcolordisplaystack.h \
gimpcolorhexentry.h \
gimpcolornotebook.h \
gimpcolorscale.h \
gimpcolorscales.h \
gimpcolorselector.h \
gimpcolorselect.h \
gimpcolorselection.h \
gimpcontroller.h \
gimpdialog.h \
gimpenumcombobox.h \
gimpenumlabel.h \
gimpenumstore.h \
gimpenumwidgets.h \
gimpfileentry.h \
gimpframe.h \
gimphelpui.h \
gimphintbox.h \
gimpintcombobox.h \
gimpintstore.h \
gimpmemsizeentry.h \
gimpnumberpairentry.h \
gimpoldwidgets.h \
gimpoffsetarea.h \
gimppageselector.h \
gimppatheditor.h \
gimppickbutton.h \
gimppixmap.h \
gimppreview.h \
gimppreviewarea.h \
gimppropwidgets.h \
gimpquerybox.h \
gimpscrolledpreview.h \
gimpsizeentry.h \
gimpstock.h \
gimpstringcombobox.h \
gimpunitmenu.h \
gimpzoommodel.h
libgimpwidgets_2_0_la_LDFLAGS = \
-version-info $(LT_VERSION_INFO) \
$(no_undefined) \
-version-info $(LT_VERSION_INFO)\
$(no_undefined) \
$(libgimpwidgets_export_symbols)
libgimpwidgets_2_0_la_LIBADD = \
$(libgimpcolor) \
$(libgimpconfig) \
$(libgimpbase) \
$(GTK_LIBS) \
$(libgimpcolor) \
$(libgimpconfig) \
$(libgimpbase) \
$(GTK_LIBS) \
$(libm)
libgimpwidgets_2_0_la_DEPENDENCIES = $(gimpwidgets_def)

View File

@ -0,0 +1,394 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpcolorprofilecombobox.c
* Copyright (C) 2007 Sven Neumann <sven@gimp.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; 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 "gimpwidgetstypes.h"
#include "gimpcolorprofilecombobox.h"
#include "gimpcolorprofilestore.h"
#include "gimpcolorprofilestore-private.h"
enum
{
PROP_0,
PROP_DIALOG,
PROP_MODEL
};
typedef struct
{
GtkTreePath *last_path;
} GimpColorProfileComboBoxPrivate;
#define GIMP_COLOR_PROFILE_COMBO_BOX_GET_PRIVATE(obj) \
G_TYPE_INSTANCE_GET_PRIVATE (obj, \
GIMP_TYPE_COLOR_PROFILE_COMBO_BOX, \
GimpColorProfileComboBoxPrivate)
static void gimp_color_profile_combo_box_finalize (GObject *object);
static void gimp_color_profile_combo_box_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_color_profile_combo_box_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_color_profile_combo_box_changed (GtkComboBox *combo);
static gboolean gimp_color_profile_row_separator_func (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer data);
G_DEFINE_TYPE (GimpColorProfileComboBox,
gimp_color_profile_combo_box, GTK_TYPE_COMBO_BOX)
#define parent_class gimp_color_profile_combo_box_parent_class
static void
gimp_color_profile_combo_box_class_init (GimpColorProfileComboBoxClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkComboBoxClass *combo_class = GTK_COMBO_BOX_CLASS (klass);
object_class->set_property = gimp_color_profile_combo_box_set_property;
object_class->get_property = gimp_color_profile_combo_box_get_property;
object_class->finalize = gimp_color_profile_combo_box_finalize;
combo_class->changed = gimp_color_profile_combo_box_changed;
g_object_class_install_property (object_class,
PROP_DIALOG,
g_param_spec_object ("dialog", NULL, NULL,
GTK_TYPE_DIALOG,
G_PARAM_CONSTRUCT_ONLY |
GIMP_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_MODEL,
g_param_spec_object ("model", NULL, NULL,
GIMP_TYPE_COLOR_PROFILE_STORE,
GIMP_PARAM_READWRITE));
g_type_class_add_private (object_class,
sizeof (GimpColorProfileComboBoxPrivate));
}
static void
gimp_color_profile_combo_box_init (GimpColorProfileComboBox *combo_box)
{
GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell,
"text", GIMP_COLOR_PROFILE_STORE_LABEL,
NULL);
gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo_box),
gimp_color_profile_row_separator_func,
NULL, NULL);
}
static void
gimp_color_profile_combo_box_finalize (GObject *object)
{
GimpColorProfileComboBox *combo;
GimpColorProfileComboBoxPrivate *priv;
combo = GIMP_COLOR_PROFILE_COMBO_BOX (object);
if (combo->dialog)
{
g_object_unref (combo->dialog);
combo->dialog = NULL;
}
priv = GIMP_COLOR_PROFILE_COMBO_BOX_GET_PRIVATE (combo);
if (priv->last_path)
{
gtk_tree_path_free (priv->last_path);
priv->last_path = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_color_profile_combo_box_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpColorProfileComboBox *combo_box = GIMP_COLOR_PROFILE_COMBO_BOX (object);
switch (property_id)
{
case PROP_DIALOG:
g_return_if_fail (combo_box->dialog == NULL);
combo_box->dialog = (GtkWidget *) g_value_dup_object (value);
break;
case PROP_MODEL:
gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box),
g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_color_profile_combo_box_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpColorProfileComboBox *combo_box = GIMP_COLOR_PROFILE_COMBO_BOX (object);
switch (property_id)
{
case PROP_DIALOG:
g_value_set_object (value, combo_box->dialog);
break;
case PROP_MODEL:
g_value_set_object (value,
gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_color_profile_combo_box_changed (GtkComboBox *combo)
{
GimpColorProfileComboBoxPrivate *priv;
GtkTreeModel *model = gtk_combo_box_get_model (combo);
GtkTreeIter iter;
gint type;
if (! gtk_combo_box_get_active_iter (combo, &iter))
return;
gtk_tree_model_get (model, &iter,
GIMP_COLOR_PROFILE_STORE_ITEM_TYPE, &type,
-1);
priv = GIMP_COLOR_PROFILE_COMBO_BOX_GET_PRIVATE (combo);
switch (type)
{
case GIMP_COLOR_PROFILE_STORE_ITEM_DIALOG:
{
GtkWidget *dialog = GIMP_COLOR_PROFILE_COMBO_BOX (combo)->dialog;
GtkWidget *parent = gtk_widget_get_toplevel (GTK_WIDGET (combo));
if (GTK_IS_WINDOW (parent))
gtk_window_set_transient_for (GTK_WINDOW (dialog),
GTK_WINDOW (parent));
gtk_window_present (GTK_WINDOW (dialog));
if (priv->last_path &&
gtk_tree_model_get_iter (model, &iter, priv->last_path))
{
gtk_combo_box_set_active_iter (combo, &iter);
}
}
break;
case GIMP_COLOR_PROFILE_STORE_ITEM_FILE:
if (priv->last_path)
gtk_tree_path_free (priv->last_path);
priv->last_path = gtk_tree_model_get_path (model, &iter);
/* FIXME: update order of history */
break;
default:
break;
}
}
/**
* gimp_color_profile_combo_box_new:
* @dialog:
* @history:
*
* Return value: a new #GimpColorProfileComboBox.
*
* Since: GIMP 2.4
**/
GtkWidget *
gimp_color_profile_combo_box_new (GtkWidget *dialog,
const gchar *history)
{
g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL);
return g_object_new (GIMP_TYPE_COLOR_PROFILE_COMBO_BOX,
"dialog", dialog,
"model", gimp_color_profile_store_new (history),
NULL);
}
/**
* gimp_color_profile_combo_box_new_with_model:
* @dialog:
* @model:
*
* Return value: a new #GimpColorProfileComboBox.
*
* Since: GIMP 2.4
**/
GtkWidget *
gimp_color_profile_combo_box_new_with_model (GtkWidget *dialog,
GtkTreeModel *model)
{
g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL);
g_return_val_if_fail (GIMP_IS_COLOR_PROFILE_STORE (model), NULL);
return g_object_new (GIMP_TYPE_COLOR_PROFILE_COMBO_BOX,
"dialog", dialog,
"model", model,
NULL);
}
/**
* gimp_color_profile_combo_box_add:
* @combo:
* @uri:
* @label:
*
* Since: GIMP 2.4
**/
void
gimp_color_profile_combo_box_add (GimpColorProfileComboBox *combo,
const gchar *uri,
const gchar *label)
{
GtkTreeModel *model;
g_return_if_fail (GIMP_IS_COLOR_PROFILE_COMBO_BOX (combo));
g_return_if_fail (label != NULL || uri == NULL);
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
gimp_color_profile_store_add (GIMP_COLOR_PROFILE_STORE (model), uri, label);
}
/**
* gimp_color_profile_combo_box_set_active:
* @combo:
* @uri:
* @label:
*
* Since: GIMP 2.4
**/
void
gimp_color_profile_combo_box_set_active (GimpColorProfileComboBox *combo,
const gchar *uri,
const gchar *label)
{
GtkTreeModel *model;
GtkTreeIter iter;
g_return_if_fail (GIMP_IS_COLOR_PROFILE_COMBO_BOX (combo));
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
if (_gimp_color_profile_store_history_add (GIMP_COLOR_PROFILE_STORE (model),
uri, label, &iter))
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter);
}
/**
* gimp_color_profile_combo_box_get_active:
* @combo:
*
* Since: GIMP 2.4
**/
gchar *
gimp_color_profile_combo_box_get_active (GimpColorProfileComboBox *combo)
{
GtkTreeModel *model;
GtkTreeIter iter;
g_return_val_if_fail (GIMP_IS_COLOR_PROFILE_COMBO_BOX (combo), NULL);
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter))
{
gchar *uri;
gint type;
gtk_tree_model_get (model, &iter,
GIMP_COLOR_PROFILE_STORE_ITEM_TYPE, &type,
GIMP_COLOR_PROFILE_STORE_URI, &uri,
-1);
if (type == GIMP_COLOR_PROFILE_STORE_ITEM_FILE)
return uri;
g_free (uri);
}
return NULL;
}
static gboolean
gimp_color_profile_row_separator_func (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer data)
{
gint type;
gtk_tree_model_get (model, iter,
GIMP_COLOR_PROFILE_STORE_ITEM_TYPE, &type,
-1);
switch (type)
{
case GIMP_COLOR_PROFILE_STORE_ITEM_SEPARATOR_TOP:
case GIMP_COLOR_PROFILE_STORE_ITEM_SEPARATOR_BOTTOM:
return TRUE;
default:
return FALSE;
}
}

View File

@ -0,0 +1,77 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpcolorprofilecombobox.h
* Copyright (C) 2007 Sven Neumann <sven@gimp.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_COLOR_PROFILE_COMBO_BOX_H__
#define __GIMP_COLOR_PROFILE_COMBO_BOX_H__
#include <gtk/gtkcombobox.h>
G_BEGIN_DECLS
#define GIMP_TYPE_COLOR_PROFILE_COMBO_BOX (gimp_color_profile_combo_box_get_type ())
#define GIMP_COLOR_PROFILE_COMBO_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_COLOR_PROFILE_COMBO_BOX, GimpColorProfileComboBox))
#define GIMP_COLOR_PROFILE_COMBO_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_COLOR_PROFILE_COMBO_BOX, GimpColorProfileComboBoxClass))
#define GIMP_IS_COLOR_PROFILE_COMBO_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_COLOR_PROFILE_COMBO_BOX))
#define GIMP_IS_COLOR_PROFILE_COMBO_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_COLOR_PROFILE_COMBO_BOX))
#define GIMP_COLOR_PROFILE_COMBO_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_COLOR_PROFILE_COMBO_BOX, GimpColorProfileComboBoxClass))
typedef struct _GimpColorProfileComboBoxClass GimpColorProfileComboBoxClass;
struct _GimpColorProfileComboBox
{
GtkComboBox parent_instance;
GtkWidget *dialog;
};
struct _GimpColorProfileComboBoxClass
{
GtkComboBoxClass parent_class;
/* Padding for future expansion */
void (* _gimp_reserved1) (void);
void (* _gimp_reserved2) (void);
void (* _gimp_reserved3) (void);
void (* _gimp_reserved4) (void);
};
GType gimp_color_profile_combo_box_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_color_profile_combo_box_new (GtkWidget *dialog,
const gchar *history);
GtkWidget * gimp_color_profile_combo_box_new_with_model (GtkWidget *dialog,
GtkTreeModel *model);
void gimp_color_profile_combo_box_add (GimpColorProfileComboBox *combo,
const gchar *uri,
const gchar *label);
void gimp_color_profile_combo_box_set_active (GimpColorProfileComboBox *combo,
const gchar *uri,
const gchar *label);
gchar * gimp_color_profile_combo_box_get_active (GimpColorProfileComboBox *combo);
G_END_DECLS
#endif /* __GIMP_COLOR_PROFILE_COMBO_BOX_H__ */

View File

@ -0,0 +1,51 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpprofilestore-private.h
* Copyright (C) 2007 Sven Neumann <sven@gimp.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_COLOR_PROFILE_STORE_PRIVATE_H__
#define __GIMP_COLOR_PROFILE_STORE_PRIVATE_H__
G_BEGIN_DECLS
typedef enum
{
GIMP_COLOR_PROFILE_STORE_ITEM_FILE,
GIMP_COLOR_PROFILE_STORE_ITEM_SEPARATOR_TOP,
GIMP_COLOR_PROFILE_STORE_ITEM_SEPARATOR_BOTTOM,
GIMP_COLOR_PROFILE_STORE_ITEM_DIALOG
} GimpColorProfileStoreItemType;
typedef enum
{
GIMP_COLOR_PROFILE_STORE_ITEM_TYPE,
GIMP_COLOR_PROFILE_STORE_LABEL,
GIMP_COLOR_PROFILE_STORE_URI,
GIMP_COLOR_PROFILE_STORE_INDEX
} GimpColorProfileStoreColumns;
G_GNUC_INTERNAL gboolean _gimp_color_profile_store_history_add (GimpColorProfileStore *store,
const gchar *uri,
const gchar *label,
GtkTreeIter *iter);
#endif /* __GIMP_COLOR_PROFILE_STORE_PRIVATE_H__ */

View File

@ -0,0 +1,633 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpprofilestore.c
* Copyright (C) 2004-2007 Sven Neumann <sven@gimp.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpconfig/gimpconfig.h"
#include "gimpwidgetstypes.h"
#include "gimpcolorprofilestore.h"
#include "gimpcolorprofilestore-private.h"
#include "libgimp/libgimp-intl.h"
enum
{
PROP_0,
PROP_HISTORY
};
static GObject * gimp_color_profile_store_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_color_profile_store_dispose (GObject *object);
static void gimp_color_profile_store_finalize (GObject *object);
static void gimp_color_profile_store_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_color_profile_store_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static gboolean gimp_color_profile_store_history_insert (GimpColorProfileStore *store,
GtkTreeIter *iter,
const gchar *uri,
const gchar *label,
gint index);
static void gimp_color_profile_store_get_separator (GimpColorProfileStore *store,
GtkTreeIter *iter,
gboolean top);
static gboolean gimp_color_profile_store_save (GimpColorProfileStore *store,
const gchar *filename,
GError **error);
static gboolean gimp_color_profile_store_load (GimpColorProfileStore *store,
const gchar *filename,
GError **error);
G_DEFINE_TYPE (GimpColorProfileStore,
gimp_color_profile_store, GTK_TYPE_LIST_STORE)
#define parent_class gimp_color_profile_store_parent_class
static void
gimp_color_profile_store_class_init (GimpColorProfileStoreClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructor = gimp_color_profile_store_constructor;
object_class->dispose = gimp_color_profile_store_dispose;
object_class->finalize = gimp_color_profile_store_finalize;
object_class->set_property = gimp_color_profile_store_set_property;
object_class->get_property = gimp_color_profile_store_get_property;
/**
* GimpColorProfileStore:history:
*
*
* Since: GIMP 2.4
*/
g_object_class_install_property (object_class,
PROP_HISTORY,
g_param_spec_string ("history", NULL, NULL,
NULL,
G_PARAM_CONSTRUCT_ONLY |
GIMP_PARAM_READWRITE));
}
static void
gimp_color_profile_store_init (GimpColorProfileStore *store)
{
GType types[] =
{
G_TYPE_INT, /* GIMP_COLOR_PROFILE_STORE_ITEM_TYPE */
G_TYPE_STRING, /* GIMP_COLOR_PROFILE_STORE_LABEL */
G_TYPE_STRING, /* GIMP_COLOR_PROFILE_STORE_URI */
G_TYPE_INT /* GIMP_COLOR_PROFILE_STORE_INDEX */
};
gtk_list_store_set_column_types (GTK_LIST_STORE (store),
G_N_ELEMENTS (types), types);
}
static GObject *
gimp_color_profile_store_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
GimpColorProfileStore *store;
GtkTreeIter iter;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
store = GIMP_COLOR_PROFILE_STORE (object);
gtk_list_store_append (GTK_LIST_STORE (store), &iter);
gtk_list_store_set (GTK_LIST_STORE (store), &iter,
GIMP_COLOR_PROFILE_STORE_ITEM_TYPE,
GIMP_COLOR_PROFILE_STORE_ITEM_DIALOG,
GIMP_COLOR_PROFILE_STORE_LABEL,
_("Select color profile from disk..."),
-1);
if (store->history)
{
gimp_color_profile_store_load (store, store->history, NULL);
}
return object;
}
static void
gimp_color_profile_store_dispose (GObject *object)
{
GimpColorProfileStore *store = GIMP_COLOR_PROFILE_STORE (object);
if (store->history)
{
gimp_color_profile_store_save (store, store->history, NULL);
}
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
gimp_color_profile_store_finalize (GObject *object)
{
GimpColorProfileStore *store = GIMP_COLOR_PROFILE_STORE (object);
if (store->history)
{
g_free (store->history);
store->history = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_color_profile_store_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpColorProfileStore *store = GIMP_COLOR_PROFILE_STORE (object);
switch (property_id)
{
case PROP_HISTORY:
g_return_if_fail (store->history == NULL);
store->history = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_color_profile_store_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpColorProfileStore *store = GIMP_COLOR_PROFILE_STORE (object);
switch (property_id)
{
case PROP_HISTORY:
g_value_set_string (value, store->history);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
/**
* gimp_color_profile_store_new:
* @history:
*
* Return value: a new #GimpColorProfileStore.
*
* Since: GIMP 2.4
**/
GtkListStore *
gimp_color_profile_store_new (const gchar *history)
{
return g_object_new (GIMP_TYPE_COLOR_PROFILE_STORE,
"history", history,
NULL);
}
/**
* gimp_color_profile_store_add:
* @store:
* @label:
* @uri:
*
* Since: GIMP 2.4
**/
void
gimp_color_profile_store_add (GimpColorProfileStore *store,
const gchar *uri,
const gchar *label)
{
GtkTreeIter separator;
GtkTreeIter iter;
g_return_if_fail (GIMP_IS_COLOR_PROFILE_STORE (store));
g_return_if_fail (label != NULL || uri == NULL);
if (uri == NULL && label == NULL)
label = Q_("profile|None");
gimp_color_profile_store_get_separator (store, &separator, TRUE);
gtk_list_store_insert_before (GTK_LIST_STORE (store), &iter, &separator);
gtk_list_store_set (GTK_LIST_STORE (store), &iter,
GIMP_COLOR_PROFILE_STORE_ITEM_TYPE,
GIMP_COLOR_PROFILE_STORE_ITEM_FILE,
GIMP_COLOR_PROFILE_STORE_URI, uri,
GIMP_COLOR_PROFILE_STORE_LABEL, label,
GIMP_COLOR_PROFILE_STORE_INDEX, -1,
-1);
}
/**
* _gimp_color_profile_store_history_add:
* @store:
* @uri:
* @label:
* @iter:
*
* Return value: %TRUE if the iter is valid and pointing to the item
*
* Since: GIMP 2.4
**/
gboolean
_gimp_color_profile_store_history_add (GimpColorProfileStore *store,
const gchar *uri,
const gchar *label,
GtkTreeIter *iter)
{
GtkTreeModel *model;
gboolean iter_valid;
gint max = -1;
g_return_val_if_fail (GIMP_IS_COLOR_PROFILE_STORE (store), FALSE);
g_return_val_if_fail (iter != NULL, FALSE);
model = GTK_TREE_MODEL (store);
for (iter_valid = gtk_tree_model_get_iter_first (model, iter);
iter_valid;
iter_valid = gtk_tree_model_iter_next (model, iter))
{
gint type;
gint index;
gchar *this_uri;
gtk_tree_model_get (model, iter,
GIMP_COLOR_PROFILE_STORE_ITEM_TYPE, &type,
GIMP_COLOR_PROFILE_STORE_INDEX, &index,
-1);
if (type != GIMP_COLOR_PROFILE_STORE_ITEM_FILE)
continue;
if (index > max)
max = index;
/* check if we found an URI match */
gtk_tree_model_get (model, iter,
GIMP_COLOR_PROFILE_STORE_URI, &this_uri,
-1);
if ((this_uri && uri && strcmp (uri, this_uri) == 0) ||
(! this_uri && ! uri))
{
/* update the label */
if (label && *label)
gtk_list_store_set (GTK_LIST_STORE (store), iter,
GIMP_COLOR_PROFILE_STORE_LABEL, label,
-1);
g_free (this_uri);
return TRUE;
}
}
if (label && *label)
{
iter_valid = gimp_color_profile_store_history_insert (store, iter,
uri, label,
++max);
}
else if (uri)
{
gchar *filename = g_filename_from_uri (uri, NULL, NULL);
gchar *basename = g_filename_display_basename (filename);
iter_valid = gimp_color_profile_store_history_insert (store, iter,
uri, basename,
++max);
g_free (basename);
g_free (filename);
}
else
{
return FALSE;
}
return iter_valid;
}
static gboolean
gimp_color_profile_store_history_insert (GimpColorProfileStore *store,
GtkTreeIter *iter,
const gchar *uri,
const gchar *label,
gint index)
{
GtkTreeModel *model = GTK_TREE_MODEL (store);
GtkTreeIter sibling;
gboolean iter_valid;
g_return_val_if_fail (uri != NULL, FALSE);
g_return_val_if_fail (label != NULL, FALSE);
g_return_val_if_fail (index > -1, FALSE);
gimp_color_profile_store_get_separator (store, iter, FALSE);
for (iter_valid = gtk_tree_model_get_iter_first (model, &sibling);
iter_valid;
iter_valid = gtk_tree_model_iter_next (model, &sibling))
{
gint type;
gint this_index;
gtk_tree_model_get (model, &sibling,
GIMP_COLOR_PROFILE_STORE_ITEM_TYPE, &type,
GIMP_COLOR_PROFILE_STORE_INDEX, &this_index,
-1);
if (type == GIMP_COLOR_PROFILE_STORE_ITEM_SEPARATOR_BOTTOM)
{
gtk_list_store_insert_before (GTK_LIST_STORE (store),
iter, &sibling);
break;
}
if (type == GIMP_COLOR_PROFILE_STORE_ITEM_FILE && this_index > -1)
{
gchar *this_label;
gtk_tree_model_get (model, &sibling,
GIMP_COLOR_PROFILE_STORE_LABEL, &this_label,
-1);
if (this_label && g_utf8_collate (label, this_label) < 0)
{
gtk_list_store_insert_before (GTK_LIST_STORE (store),
iter, &sibling);
g_free (this_label);
break;
}
g_free (this_label);
}
}
if (iter_valid)
gtk_list_store_set (GTK_LIST_STORE (store), iter,
GIMP_COLOR_PROFILE_STORE_ITEM_TYPE,
GIMP_COLOR_PROFILE_STORE_ITEM_FILE,
GIMP_COLOR_PROFILE_STORE_URI, uri,
GIMP_COLOR_PROFILE_STORE_LABEL, label,
GIMP_COLOR_PROFILE_STORE_INDEX, index,
-1);
return iter_valid;
}
static void
gimp_color_profile_store_create_separator (GimpColorProfileStore *store,
GtkTreeIter *iter,
gboolean top)
{
if (top)
{
gtk_list_store_prepend (GTK_LIST_STORE (store), iter);
}
else
{
GtkTreeModel *model = GTK_TREE_MODEL (store);
GtkTreeIter sibling;
gboolean iter_valid;
for (iter_valid = gtk_tree_model_get_iter_first (model, &sibling);
iter_valid;
iter_valid = gtk_tree_model_iter_next (model, &sibling))
{
gint type;
gtk_tree_model_get (model, &sibling,
GIMP_COLOR_PROFILE_STORE_ITEM_TYPE, &type,
-1);
if (type == GIMP_COLOR_PROFILE_STORE_ITEM_DIALOG)
break;
}
if (iter_valid)
gtk_list_store_insert_before (GTK_LIST_STORE (store), iter, &sibling);
}
gtk_list_store_set (GTK_LIST_STORE (store), iter,
GIMP_COLOR_PROFILE_STORE_ITEM_TYPE,
top ?
GIMP_COLOR_PROFILE_STORE_ITEM_SEPARATOR_TOP :
GIMP_COLOR_PROFILE_STORE_ITEM_SEPARATOR_BOTTOM,
GIMP_COLOR_PROFILE_STORE_INDEX, -1,
-1);
}
static void
gimp_color_profile_store_get_separator (GimpColorProfileStore *store,
GtkTreeIter *iter,
gboolean top)
{
GtkTreeModel *model = GTK_TREE_MODEL (store);
gboolean iter_valid;
gint needle;
needle = (top ?
GIMP_COLOR_PROFILE_STORE_ITEM_SEPARATOR_TOP :
GIMP_COLOR_PROFILE_STORE_ITEM_SEPARATOR_BOTTOM);
for (iter_valid = gtk_tree_model_get_iter_first (model, iter);
iter_valid;
iter_valid = gtk_tree_model_iter_next (model, iter))
{
gint type;
gtk_tree_model_get (model, iter,
GIMP_COLOR_PROFILE_STORE_ITEM_TYPE, &type,
-1);
if (type == needle)
return;
}
gimp_color_profile_store_create_separator (store, iter, top);
}
static GTokenType
gimp_color_profile_store_load_profile (GimpColorProfileStore *store,
GScanner *scanner,
gint index)
{
GtkTreeIter iter;
gchar *label = NULL;
gchar *uri = NULL;
if (gimp_scanner_parse_string (scanner, &label) &&
gimp_scanner_parse_string (scanner, &uri))
{
gimp_color_profile_store_history_insert (store, &iter, uri, label, index);
g_free (label);
g_free (uri);
return G_TOKEN_RIGHT_PAREN;
}
g_free (label);
g_free (uri);
return G_TOKEN_STRING;
}
static gboolean
gimp_color_profile_store_load (GimpColorProfileStore *store,
const gchar *filename,
GError **error)
{
GScanner *scanner;
GTokenType token;
gint i = 0;
scanner = gimp_scanner_new_file (filename, error);
if (! scanner)
return FALSE;
g_scanner_scope_add_symbol (scanner, 0, "color-profile", 0);
token = G_TOKEN_LEFT_PAREN;
while (g_scanner_peek_next_token (scanner) == token)
{
token = g_scanner_get_next_token (scanner);
switch (token)
{
case G_TOKEN_LEFT_PAREN:
token = G_TOKEN_SYMBOL;
break;
case G_TOKEN_SYMBOL:
token = gimp_color_profile_store_load_profile (store, scanner, i++);
break;
case G_TOKEN_RIGHT_PAREN:
token = G_TOKEN_LEFT_PAREN;
break;
default: /* do nothing */
break;
}
}
if (token != G_TOKEN_LEFT_PAREN)
{
g_scanner_get_next_token (scanner);
g_scanner_unexp_token (scanner, token, NULL, NULL, NULL,
_("fatal parse error"), TRUE);
}
gimp_scanner_destroy (scanner);
return TRUE;
}
static gboolean
gimp_color_profile_store_save (GimpColorProfileStore *store,
const gchar *filename,
GError **error)
{
GimpConfigWriter *writer;
GtkTreeModel *model = GTK_TREE_MODEL (store);
GtkTreeIter iter;
gboolean iter_valid;
writer = gimp_config_writer_new_file (filename,
TRUE,
"GIMP color profile history",
error);
if (! writer)
return FALSE;
/* FIXME: store the history in MRU order */
for (iter_valid = gtk_tree_model_get_iter_first (model, &iter);
iter_valid;
iter_valid = gtk_tree_model_iter_next (model, &iter))
{
gint type;
gtk_tree_model_get (model, &iter,
GIMP_COLOR_PROFILE_STORE_ITEM_TYPE, &type,
-1);
if (type == GIMP_COLOR_PROFILE_STORE_ITEM_FILE)
{
gchar *label;
gchar *uri;
gtk_tree_model_get (model, &iter,
GIMP_COLOR_PROFILE_STORE_LABEL, &label,
GIMP_COLOR_PROFILE_STORE_URI, &uri,
-1);
if (uri && label)
{
gimp_config_writer_open (writer, "color-profile");
gimp_config_writer_string (writer, label);
gimp_config_writer_string (writer, uri);
gimp_config_writer_close (writer);
}
g_free (uri);
g_free (label);
}
}
return gimp_config_writer_finish (writer,
"end of color profile history", error);
}

View File

@ -0,0 +1,68 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpprofilestore.h
* Copyright (C) 2007 Sven Neumann <sven@gimp.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_COLOR_PROFILE_STORE_H__
#define __GIMP_COLOR_PROFILE_STORE_H__
#include <gtk/gtkliststore.h>
G_BEGIN_DECLS
#define GIMP_TYPE_COLOR_PROFILE_STORE (gimp_color_profile_store_get_type ())
#define GIMP_COLOR_PROFILE_STORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_COLOR_PROFILE_STORE, GimpColorProfileStore))
#define GIMP_COLOR_PROFILE_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_COLOR_PROFILE_STORE, GimpColorProfileStoreClass))
#define GIMP_IS_COLOR_PROFILE_STORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_COLOR_PROFILE_STORE))
#define GIMP_IS_COLOR_PROFILE_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_COLOR_PROFILE_STORE))
#define GIMP_COLOR_PROFILE_STORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_COLOR_PROFILE_STORE, GimpColorProfileStoreClass))
typedef struct _GimpColorProfileStoreClass GimpColorProfileStoreClass;
struct _GimpColorProfileStore
{
GtkListStore parent_instance;
gchar *history;
};
struct _GimpColorProfileStoreClass
{
GtkListStoreClass parent_class;
void (* _gimp_reserved1) (void);
void (* _gimp_reserved2) (void);
void (* _gimp_reserved3) (void);
void (* _gimp_reserved4) (void);
};
GType gimp_color_profile_store_get_type (void) G_GNUC_CONST;
GtkListStore * gimp_color_profile_store_new (const gchar *history);
void gimp_color_profile_store_add (GimpColorProfileStore *store,
const gchar *uri,
const gchar *label);
#endif /* __GIMP_COLOR_PROFILE_STORE_H__ */

View File

@ -62,6 +62,15 @@ EXPORTS
gimp_color_hex_entry_set_color
gimp_color_notebook_get_type
gimp_color_notebook_set_has_page
gimp_color_profile_combo_box_add
gimp_color_profile_combo_box_get_active
gimp_color_profile_combo_box_get_type
gimp_color_profile_combo_box_new
gimp_color_profile_combo_box_new_with_model
gimp_color_profile_combo_box_set_active
gimp_color_profile_store_add
gimp_color_profile_store_get_type
gimp_color_profile_store_new
gimp_color_scale_entry_new
gimp_color_scale_get_type
gimp_color_scale_new

View File

@ -37,6 +37,8 @@
#include <libgimpwidgets/gimpcolordisplaystack.h>
#include <libgimpwidgets/gimpcolorhexentry.h>
#include <libgimpwidgets/gimpcolornotebook.h>
#include <libgimpwidgets/gimpcolorprofilecombobox.h>
#include <libgimpwidgets/gimpcolorprofilestore.h>
#include <libgimpwidgets/gimpcolorscale.h>
#include <libgimpwidgets/gimpcolorscales.h>
#include <libgimpwidgets/gimpcolorselector.h>

View File

@ -31,45 +31,47 @@ G_BEGIN_DECLS
/* For information look into the html documentation */
typedef struct _GimpBrowser GimpBrowser;
typedef struct _GimpButton GimpButton;
typedef struct _GimpCellRendererColor GimpCellRendererColor;
typedef struct _GimpCellRendererToggle GimpCellRendererToggle;
typedef struct _GimpChainButton GimpChainButton;
typedef struct _GimpColorArea GimpColorArea;
typedef struct _GimpColorButton GimpColorButton;
typedef struct _GimpColorDisplay GimpColorDisplay;
typedef struct _GimpColorDisplayStack GimpColorDisplayStack;
typedef struct _GimpColorHexEntry GimpColorHexEntry;
typedef struct _GimpColorNotebook GimpColorNotebook;
typedef struct _GimpColorScale GimpColorScale;
typedef struct _GimpColorScales GimpColorScales;
typedef struct _GimpColorSelector GimpColorSelector;
typedef struct _GimpColorSelect GimpColorSelect;
typedef struct _GimpColorSelection GimpColorSelection;
typedef struct _GimpController GimpController;
typedef struct _GimpDialog GimpDialog;
typedef struct _GimpEnumStore GimpEnumStore;
typedef struct _GimpEnumComboBox GimpEnumComboBox;
typedef struct _GimpEnumLabel GimpEnumLabel;
typedef struct _GimpFileEntry GimpFileEntry;
typedef struct _GimpFrame GimpFrame;
typedef struct _GimpIntComboBox GimpIntComboBox;
typedef struct _GimpIntStore GimpIntStore;
typedef struct _GimpMemsizeEntry GimpMemsizeEntry;
typedef struct _GimpNumberPairEntry GimpNumberPairEntry;
typedef struct _GimpOffsetArea GimpOffsetArea;
typedef struct _GimpPageSelector GimpPageSelector;
typedef struct _GimpPathEditor GimpPathEditor;
typedef struct _GimpPickButton GimpPickButton;
typedef struct _GimpPreview GimpPreview;
typedef struct _GimpPreviewArea GimpPreviewArea;
typedef struct _GimpPixmap GimpPixmap;
typedef struct _GimpScrolledPreview GimpScrolledPreview;
typedef struct _GimpSizeEntry GimpSizeEntry;
typedef struct _GimpStringComboBox GimpStringComboBox;
typedef struct _GimpUnitMenu GimpUnitMenu;
typedef struct _GimpZoomModel GimpZoomModel;
typedef struct _GimpBrowser GimpBrowser;
typedef struct _GimpButton GimpButton;
typedef struct _GimpCellRendererColor GimpCellRendererColor;
typedef struct _GimpCellRendererToggle GimpCellRendererToggle;
typedef struct _GimpChainButton GimpChainButton;
typedef struct _GimpColorArea GimpColorArea;
typedef struct _GimpColorButton GimpColorButton;
typedef struct _GimpColorDisplay GimpColorDisplay;
typedef struct _GimpColorDisplayStack GimpColorDisplayStack;
typedef struct _GimpColorHexEntry GimpColorHexEntry;
typedef struct _GimpColorNotebook GimpColorNotebook;
typedef struct _GimpColorProfileComboBox GimpColorProfileComboBox;
typedef struct _GimpColorProfileStore GimpColorProfileStore;
typedef struct _GimpColorScale GimpColorScale;
typedef struct _GimpColorScales GimpColorScales;
typedef struct _GimpColorSelector GimpColorSelector;
typedef struct _GimpColorSelect GimpColorSelect;
typedef struct _GimpColorSelection GimpColorSelection;
typedef struct _GimpController GimpController;
typedef struct _GimpDialog GimpDialog;
typedef struct _GimpEnumStore GimpEnumStore;
typedef struct _GimpEnumComboBox GimpEnumComboBox;
typedef struct _GimpEnumLabel GimpEnumLabel;
typedef struct _GimpFileEntry GimpFileEntry;
typedef struct _GimpFrame GimpFrame;
typedef struct _GimpIntComboBox GimpIntComboBox;
typedef struct _GimpIntStore GimpIntStore;
typedef struct _GimpMemsizeEntry GimpMemsizeEntry;
typedef struct _GimpNumberPairEntry GimpNumberPairEntry;
typedef struct _GimpOffsetArea GimpOffsetArea;
typedef struct _GimpPageSelector GimpPageSelector;
typedef struct _GimpPathEditor GimpPathEditor;
typedef struct _GimpPickButton GimpPickButton;
typedef struct _GimpPreview GimpPreview;
typedef struct _GimpPreviewArea GimpPreviewArea;
typedef struct _GimpPixmap GimpPixmap;
typedef struct _GimpScrolledPreview GimpScrolledPreview;
typedef struct _GimpSizeEntry GimpSizeEntry;
typedef struct _GimpStringComboBox GimpStringComboBox;
typedef struct _GimpUnitMenu GimpUnitMenu;
typedef struct _GimpZoomModel GimpZoomModel;
typedef void (* GimpHelpFunc) (const gchar *help_id,

View File

@ -538,7 +538,7 @@ lcms_icc_apply (GimpColorConfig *config,
cmsCloseProfile (src_profile);
cmsCloseProfile (dest_profile);
g_printerr ("skipping conversion because profiles seem to be equal:\n");
g_printerr ("lcms: skipping conversion because profiles seem to be equal:\n");
g_printerr (" %s\n", src_desc);
g_printerr (" %s\n", dest_desc);
@ -1160,6 +1160,158 @@ lcms_icc_apply_dialog (gint32 image,
return run;
}
static void
lcms_icc_combo_box_set_active (GimpColorProfileComboBox *combo,
const gchar *uri)
{
cmsHPROFILE profile;
gchar *filename = g_filename_from_uri (uri, NULL, NULL);
gchar *name = NULL;
profile = lcms_load_profile (filename, NULL);
if (profile)
{
name = lcms_icc_profile_get_desc (profile);
if (! name)
name = lcms_icc_profile_get_name (profile);
cmsCloseProfile (profile);
}
g_free (filename);
gimp_color_profile_combo_box_set_active (combo, uri, name);
g_free (name);
}
static void
lcms_icc_file_chooser_dialog_response (GtkFileChooser *dialog,
gint response,
GimpColorProfileComboBox *combo)
{
if (response == GTK_RESPONSE_ACCEPT)
{
gchar *uri = gtk_file_chooser_get_uri (dialog);
if (uri)
{
lcms_icc_combo_box_set_active (combo, uri);
g_free (uri);
}
}
gtk_widget_hide (GTK_WIDGET (dialog));
}
static GtkWidget *
lcms_icc_file_chooser_dialog_new (void)
{
GtkWidget *dialog;
GtkFileFilter *filter;
dialog = gtk_file_chooser_dialog_new (_("Select destination profile"),
NULL,
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL);
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
GTK_RESPONSE_ACCEPT,
GTK_RESPONSE_CANCEL,
-1);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
#ifndef G_OS_WIN32
{
const gchar folder[] = "/usr/share/color/icc";
if (g_file_test (folder, G_FILE_TEST_IS_DIR))
gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog),
folder, NULL);
}
#endif
filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, _("All files (*.*)"));
gtk_file_filter_add_pattern (filter, "*");
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, _("ICC color profile (*.icc, *.icm)"));
gtk_file_filter_add_pattern (filter, "*.[Ii][Cc][Cc]");
gtk_file_filter_add_pattern (filter, "*.[Ii][Cc][Mm]");
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
return dialog;
}
static GtkWidget *
lcms_icc_combo_box_new (GimpColorConfig *config,
const gchar *filename)
{
GtkWidget *combo;
GtkWidget *dialog;
gchar *history;
gchar *label;
gchar *name;
cmsHPROFILE profile;
dialog = lcms_icc_file_chooser_dialog_new ();
history = gimp_personal_rc_file ("profilerc");
combo = gimp_color_profile_combo_box_new (dialog, history);
g_free (history);
g_signal_connect (dialog, "response",
G_CALLBACK (lcms_icc_file_chooser_dialog_response),
combo);
g_object_unref (dialog);
if (config->rgb_profile)
profile = lcms_load_profile (config->rgb_profile, NULL);
else
profile = cmsCreate_sRGBProfile ();
name = lcms_icc_profile_get_desc (profile);
if (! name)
name = lcms_icc_profile_get_name (profile);
cmsCloseProfile (profile);
label = g_strdup_printf (_("RGB workspace (%s)"), name);
g_free (name);
gimp_color_profile_combo_box_add (GIMP_COLOR_PROFILE_COMBO_BOX (combo),
config->rgb_profile, label);
g_free (label);
if (filename)
{
gchar *uri = g_filename_to_uri (filename, NULL, NULL);
if (uri)
{
lcms_icc_combo_box_set_active (GIMP_COLOR_PROFILE_COMBO_BOX (combo),
uri);
g_free (uri);
}
}
else
{
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
}
return combo;
}
static gboolean
lcms_dialog (GimpColorConfig *config,
gint32 image,
@ -1169,10 +1321,9 @@ lcms_dialog (GimpColorConfig *config,
GtkWidget *vbox;
GtkWidget *frame;
GtkWidget *label;
GtkWidget *combo;
cmsHPROFILE src_profile;
cmsHPROFILE dest_profile;
gchar *name;
gchar *filename = NULL;
gboolean success = TRUE;
gboolean run;
@ -1190,8 +1341,6 @@ lcms_dialog (GimpColorConfig *config,
if (! src_profile)
src_profile = cmsCreate_sRGBProfile ();
dest_profile = cmsCreate_sRGBProfile ();
gimp_ui_init (PLUG_IN_BINARY, FALSE);
dialog = gimp_dialog_new (apply ?
@ -1221,7 +1370,7 @@ lcms_dialog (GimpColorConfig *config,
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), vbox);
gtk_widget_show (vbox);
frame = gimp_frame_new ("Current Color Profile");
frame = gimp_frame_new (_("Current Color Profile"));
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
@ -1236,39 +1385,58 @@ lcms_dialog (GimpColorConfig *config,
g_free (name);
frame = gimp_frame_new (apply ? "Convert to" : "Assign");
frame = gimp_frame_new (apply ? _("Convert to") : _("Assign"));
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
name = lcms_icc_profile_get_desc (dest_profile);
if (! name)
name = lcms_icc_profile_get_name (dest_profile);
label = gtk_label_new (name);
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_container_add (GTK_CONTAINER (frame), label);
gtk_widget_show (label);
g_free (name);
combo = lcms_icc_combo_box_new (config, NULL);
gtk_container_add (GTK_CONTAINER (frame), combo);
gtk_widget_show (combo);
run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
gtk_widget_destroy (dialog);
gtk_widget_hide (dialog);
if (run)
{
if (apply)
success = lcms_image_apply_profile (image,
src_profile, dest_profile,
filename);
cmsHPROFILE dest_profile;
gchar *filename = NULL;
gchar *uri;
uri = gimp_color_profile_combo_box_get_active (GIMP_COLOR_PROFILE_COMBO_BOX (combo));
if (uri)
{
filename = g_filename_from_uri (uri, NULL, NULL);
g_free (uri);
dest_profile = lcms_load_profile (filename, NULL);
}
else
success = lcms_image_set_profile (image, dest_profile, filename);
{
dest_profile = cmsCreate_sRGBProfile ();
}
if (lcms_icc_profile_is_rgb (dest_profile))
{
if (apply)
success = lcms_image_apply_profile (image,
src_profile, dest_profile,
filename);
else
success = lcms_image_set_profile (image, dest_profile, filename);
}
else
{
gimp_message (_("Destination profile is not for RGB color space."));
}
cmsCloseProfile (dest_profile);
}
cmsCloseProfile (src_profile);
cmsCloseProfile (dest_profile);
gtk_widget_destroy (dialog);
g_free (filename);
cmsCloseProfile (src_profile);
return success;
}

View File

@ -1,3 +1,8 @@
2007-08-14 Sven Neumann <sven@gimp.org>
* po-libgimp/POTFILES.in: added new file
libgimpwidgets/gimpcolorprofilestore.c.
2007-08-14 Marco Ciampa <ciampix@libero.it>
* it.po: updated italian.

View File

@ -37,6 +37,7 @@ libgimpthumb/gimpthumbnail.c
libgimpwidgets/gimpbrowser.c
libgimpwidgets/gimpcolorbutton.c
libgimpwidgets/gimpcolorprofilestore.c
libgimpwidgets/gimpcolorscales.c
libgimpwidgets/gimpcolorselect.c
libgimpwidgets/gimpcolorselection.c