libgimpwidgets: port GimpColorProfileStore and -ComboBox to GFile

and deprecate the old filename-based API. Port everything to use the
new GFile functions.
This commit is contained in:
Michael Natterer
2015-08-01 16:11:37 +02:00
parent 35a766d4db
commit 5672e80ea1
9 changed files with 302 additions and 104 deletions

View File

@ -788,23 +788,30 @@ static void prefs_profile_combo_notify (GObject *config,
prefs_profile_combo_changed (GimpColorProfileComboBox *combo, prefs_profile_combo_changed (GimpColorProfileComboBox *combo,
GObject *config) GObject *config)
{ {
gchar *filename = gimp_color_profile_combo_box_get_active (combo); GFile *file = gimp_color_profile_combo_box_get_active_file (combo);
gchar *path = NULL;
if (! filename) if (file)
path = g_file_get_path (file);
if (! path)
g_signal_handlers_block_by_func (config, g_signal_handlers_block_by_func (config,
prefs_profile_combo_notify, prefs_profile_combo_notify,
combo); combo);
g_object_set (config, g_object_set (config,
g_object_get_data (G_OBJECT (combo), "property-name"), filename, g_object_get_data (G_OBJECT (combo), "property-name"), path,
NULL); NULL);
if (! filename) if (! path)
g_signal_handlers_unblock_by_func (config, g_signal_handlers_unblock_by_func (config,
prefs_profile_combo_notify, prefs_profile_combo_notify,
combo); combo);
g_free (filename); g_free (path);
if (file)
g_object_unref (file);
} }
static void static void
@ -812,23 +819,31 @@ prefs_profile_combo_notify (GObject *config,
const GParamSpec *param_spec, const GParamSpec *param_spec,
GimpColorProfileComboBox *combo) GimpColorProfileComboBox *combo)
{ {
gchar *filename; gchar *path;
GFile *file = NULL;
g_object_get (config, g_object_get (config,
param_spec->name, &filename, param_spec->name, &path,
NULL); NULL);
if (path)
{
file = g_file_new_for_path (path);
g_free (path);
}
g_signal_handlers_block_by_func (combo, g_signal_handlers_block_by_func (combo,
prefs_profile_combo_changed, prefs_profile_combo_changed,
config); config);
gimp_color_profile_combo_box_set_active (combo, filename, NULL); gimp_color_profile_combo_box_set_active_file (combo, file, NULL);
g_signal_handlers_unblock_by_func (combo, g_signal_handlers_unblock_by_func (combo,
prefs_profile_combo_changed, prefs_profile_combo_changed,
config); config);
g_free (filename); if (file)
g_object_unref (file);
} }
static void static void
@ -856,10 +871,17 @@ prefs_profile_combo_box_new (GObject *config,
{ {
GtkWidget *dialog = gimp_color_profile_chooser_dialog_new (label); GtkWidget *dialog = gimp_color_profile_chooser_dialog_new (label);
GtkWidget *combo; GtkWidget *combo;
gchar *filename; gchar *path;
gchar *notify_name; gchar *notify_name;
GFile *file = NULL;
g_object_get (config, property_name, &filename, NULL); g_object_get (config, property_name, &path, NULL);
if (path)
{
file = g_file_new_for_path (path);
g_free (path);
}
combo = gimp_color_profile_combo_box_new_with_model (dialog, combo = gimp_color_profile_combo_box_new_with_model (dialog,
GTK_TREE_MODEL (store)); GTK_TREE_MODEL (store));
@ -867,10 +889,11 @@ prefs_profile_combo_box_new (GObject *config,
g_object_set_data (G_OBJECT (combo), g_object_set_data (G_OBJECT (combo),
"property-name", (gpointer) property_name); "property-name", (gpointer) property_name);
gimp_color_profile_combo_box_set_active (GIMP_COLOR_PROFILE_COMBO_BOX (combo), gimp_color_profile_combo_box_set_active_file (GIMP_COLOR_PROFILE_COMBO_BOX (combo),
filename, NULL); file, NULL);
g_free (filename); if (file)
g_object_unref (file);
g_signal_connect (combo, "changed", g_signal_connect (combo, "changed",
G_CALLBACK (prefs_profile_combo_changed), G_CALLBACK (prefs_profile_combo_changed),
@ -2377,7 +2400,8 @@ prefs_dialog_new (Gimp *gimp,
store = gimp_color_profile_store_new (filename); store = gimp_color_profile_store_new (filename);
g_free (filename); g_free (filename);
gimp_color_profile_store_add (GIMP_COLOR_PROFILE_STORE (store), NULL, NULL); gimp_color_profile_store_add_file (GIMP_COLOR_PROFILE_STORE (store),
NULL, NULL);
for (i = 0; i < G_N_ELEMENTS (profiles); i++) for (i = 0; i < G_N_ELEMENTS (profiles); i++)
{ {

View File

@ -376,7 +376,9 @@ gimp_color_profile_combo_box_new_with_model (GtkWidget *dialog,
* *
* This function delegates to the underlying * This function delegates to the underlying
* #GimpColorProfileStore. Please refer to the documentation of * #GimpColorProfileStore. Please refer to the documentation of
* gimp_color_profile_store_add() for details. * gimp_color_profile_store_add_file() for details.
*
* Deprecated: use gimp_color_profile_combo_box_add_file() instead.
* *
* Since: 2.4 * Since: 2.4
**/ **/
@ -385,15 +387,48 @@ gimp_color_profile_combo_box_add (GimpColorProfileComboBox *combo,
const gchar *filename, const gchar *filename,
const gchar *label) const gchar *label)
{ {
GtkTreeModel *model; GFile *file = NULL;
g_return_if_fail (GIMP_IS_COLOR_PROFILE_COMBO_BOX (combo)); g_return_if_fail (GIMP_IS_COLOR_PROFILE_COMBO_BOX (combo));
g_return_if_fail (label != NULL || filename == NULL); g_return_if_fail (label != NULL || filename == NULL);
if (filename)
file = g_file_new_for_path (filename);
gimp_color_profile_combo_box_add_file (combo, file, label);
if (file)
g_object_unref (file);
}
/**
* gimp_color_profile_combo_box_add_file:
* @combo: a #GimpColorProfileComboBox
* @file: file of the profile to add (or %NULL)
* @label: label to use for the profile
* (may only be %NULL if @file is %NULL)
*
* This function delegates to the underlying
* #GimpColorProfileStore. Please refer to the documentation of
* gimp_color_profile_store_add_file() for details.
*
* Since: 2.10
**/
void
gimp_color_profile_combo_box_add_file (GimpColorProfileComboBox *combo,
GFile *file,
const gchar *label)
{
GtkTreeModel *model;
g_return_if_fail (GIMP_IS_COLOR_PROFILE_COMBO_BOX (combo));
g_return_if_fail (label != NULL || file == NULL);
g_return_if_fail (file == NULL || G_IS_FILE (file));
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo)); model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
gimp_color_profile_store_add (GIMP_COLOR_PROFILE_STORE (model), gimp_color_profile_store_add_file (GIMP_COLOR_PROFILE_STORE (model),
filename, label); file, label);
} }
/** /**
@ -406,29 +441,59 @@ gimp_color_profile_combo_box_add (GimpColorProfileComboBox *combo,
* item. If the profile is not listed in the @combo, then it is added * item. If the profile is not listed in the @combo, then it is added
* with the given @label (or @filename in case that @label is %NULL). * with the given @label (or @filename in case that @label is %NULL).
* *
* Deprecated: use gimp_color_profile_combo_box_set_active_file() instead.
*
* Since: 2.4 * Since: 2.4
**/ **/
void void
gimp_color_profile_combo_box_set_active (GimpColorProfileComboBox *combo, gimp_color_profile_combo_box_set_active (GimpColorProfileComboBox *combo,
const gchar *filename, const gchar *filename,
const gchar *label) const gchar *label)
{
GFile *file = NULL;
g_return_if_fail (GIMP_IS_COLOR_PROFILE_COMBO_BOX (combo));
if (filename)
file = g_file_new_for_path (filename);
gimp_color_profile_combo_box_set_active_file (combo, file, label);
if (file)
g_object_unref (file);
}
/**
* gimp_color_profile_combo_box_set_active_file:
* @combo: a #GimpColorProfileComboBox
* @file: file of the profile to select
* @label: label to use when adding a new entry (can be %NULL)
*
* Selects a color profile from the @combo and makes it the active
* item. If the profile is not listed in the @combo, then it is added
* with the given @label (or @file in case that @label is %NULL).
*
* Since: 2.10
**/
void
gimp_color_profile_combo_box_set_active_file (GimpColorProfileComboBox *combo,
GFile *file,
const gchar *label)
{ {
GimpColorProfile *profile = NULL; GimpColorProfile *profile = NULL;
GtkTreeModel *model; GtkTreeModel *model;
GtkTreeIter iter; GtkTreeIter iter;
g_return_if_fail (GIMP_IS_COLOR_PROFILE_COMBO_BOX (combo)); g_return_if_fail (GIMP_IS_COLOR_PROFILE_COMBO_BOX (combo));
g_return_if_fail (file == NULL || G_IS_FILE (file));
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo)); model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
if (filename && ! (label && *label)) if (file && ! (label && *label))
{ {
GFile *file;
GError *error = NULL; GError *error = NULL;
file = g_file_new_for_path (filename);
profile = gimp_color_profile_new_from_file (file, &error); profile = gimp_color_profile_new_from_file (file, &error);
g_object_unref (file);
if (! profile) if (! profile)
{ {
@ -442,7 +507,7 @@ gimp_color_profile_combo_box_set_active (GimpColorProfileComboBox *combo,
} }
if (_gimp_color_profile_store_history_add (GIMP_COLOR_PROFILE_STORE (model), if (_gimp_color_profile_store_history_add (GIMP_COLOR_PROFILE_STORE (model),
filename, label, &iter)) file, label, &iter))
{ {
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter); gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter);
} }
@ -455,14 +520,45 @@ gimp_color_profile_combo_box_set_active (GimpColorProfileComboBox *combo,
* gimp_color_profile_combo_box_get_active: * gimp_color_profile_combo_box_get_active:
* @combo: a #GimpColorProfileComboBox * @combo: a #GimpColorProfileComboBox
* *
* Return value: The filename of the currently selected color profile. * Return value: The filename of the currently selected color profile,
* This is a newly allocated string and should be released * This is a newly allocated string and should be released
* using g_free() when it is not any longer needed. * using g_free() when it is not any longer needed.
* *
* Deprecated: use gimp_color_profile_combo_box_get_active_file() inatead.
*
* Since: 2.4 * Since: 2.4
**/ **/
gchar * gchar *
gimp_color_profile_combo_box_get_active (GimpColorProfileComboBox *combo) gimp_color_profile_combo_box_get_active (GimpColorProfileComboBox *combo)
{
GFile *file;
gchar *path = NULL;
g_return_val_if_fail (GIMP_IS_COLOR_PROFILE_COMBO_BOX (combo), NULL);
file = gimp_color_profile_combo_box_get_active_file (combo);
if (file)
{
path = g_file_get_path (file);
g_object_unref (file);
}
return path;
}
/**
* gimp_color_profile_combo_box_get_active_file:
* @combo: a #GimpColorProfileComboBox
*
* Return value: The file of the currently selected color profile,
* release using g_object_unref() when it is not any
* longer needed.
*
* Since: 2.10
**/
GFile *
gimp_color_profile_combo_box_get_active_file (GimpColorProfileComboBox *combo)
{ {
GtkTreeModel *model; GtkTreeModel *model;
GtkTreeIter iter; GtkTreeIter iter;
@ -473,18 +569,19 @@ gimp_color_profile_combo_box_get_active (GimpColorProfileComboBox *combo)
if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter)) if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter))
{ {
gchar *filename; GFile *file;
gint type; gint type;
gtk_tree_model_get (model, &iter, gtk_tree_model_get (model, &iter,
GIMP_COLOR_PROFILE_STORE_ITEM_TYPE, &type, GIMP_COLOR_PROFILE_STORE_ITEM_TYPE, &type,
GIMP_COLOR_PROFILE_STORE_FILENAME, &filename, GIMP_COLOR_PROFILE_STORE_FILE, &file,
-1); -1);
if (type == GIMP_COLOR_PROFILE_STORE_ITEM_FILE) if (type == GIMP_COLOR_PROFILE_STORE_ITEM_FILE)
return filename; return file;
g_free (filename); if (file)
g_object_unref (file);
} }
return NULL; return NULL;
@ -519,15 +616,15 @@ gimp_color_profile_combo_dialog_response (GimpColorProfileChooserDialog *dialog,
{ {
if (response == GTK_RESPONSE_ACCEPT) if (response == GTK_RESPONSE_ACCEPT)
{ {
gchar *filename; GFile *file;
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
if (filename) if (file)
{ {
gimp_color_profile_combo_box_set_active (combo, filename, NULL); gimp_color_profile_combo_box_set_active_file (combo, file, NULL);
g_free (filename); g_object_unref (file);
} }
} }

View File

@ -64,13 +64,25 @@ GtkWidget * gimp_color_profile_combo_box_new (GtkWidget *dialog,
GtkWidget * gimp_color_profile_combo_box_new_with_model (GtkWidget *dialog, GtkWidget * gimp_color_profile_combo_box_new_with_model (GtkWidget *dialog,
GtkTreeModel *model); GtkTreeModel *model);
GIMP_DEPRECATED_FOR (gimp_color_profile_combo_box_add_file)
void gimp_color_profile_combo_box_add (GimpColorProfileComboBox *combo, void gimp_color_profile_combo_box_add (GimpColorProfileComboBox *combo,
const gchar *filename, const gchar *filename,
const gchar *label); const gchar *label);
void gimp_color_profile_combo_box_add_file (GimpColorProfileComboBox *combo,
GFile *file,
const gchar *label);
GIMP_DEPRECATED_FOR (gimp_color_profile_combo_box_set_active_file)
void gimp_color_profile_combo_box_set_active (GimpColorProfileComboBox *combo, void gimp_color_profile_combo_box_set_active (GimpColorProfileComboBox *combo,
const gchar *filename, const gchar *filename,
const gchar *label); const gchar *label);
void gimp_color_profile_combo_box_set_active_file (GimpColorProfileComboBox *combo,
GFile *file,
const gchar *label);
GIMP_DEPRECATED_FOR (gimp_color_profile_combo_box_get_active_file)
gchar * gimp_color_profile_combo_box_get_active (GimpColorProfileComboBox *combo); gchar * gimp_color_profile_combo_box_get_active (GimpColorProfileComboBox *combo);
GFile * gimp_color_profile_combo_box_get_active_file (GimpColorProfileComboBox *combo);
G_END_DECLS G_END_DECLS

View File

@ -35,13 +35,13 @@ typedef enum
{ {
GIMP_COLOR_PROFILE_STORE_ITEM_TYPE, GIMP_COLOR_PROFILE_STORE_ITEM_TYPE,
GIMP_COLOR_PROFILE_STORE_LABEL, GIMP_COLOR_PROFILE_STORE_LABEL,
GIMP_COLOR_PROFILE_STORE_FILENAME, GIMP_COLOR_PROFILE_STORE_FILE,
GIMP_COLOR_PROFILE_STORE_INDEX GIMP_COLOR_PROFILE_STORE_INDEX
} GimpColorProfileStoreColumns; } GimpColorProfileStoreColumns;
G_GNUC_INTERNAL gboolean _gimp_color_profile_store_history_add (GimpColorProfileStore *store, G_GNUC_INTERNAL gboolean _gimp_color_profile_store_history_add (GimpColorProfileStore *store,
const gchar *filename, GFile *file,
const gchar *label, const gchar *label,
GtkTreeIter *iter); GtkTreeIter *iter);

View File

@ -68,7 +68,7 @@ static void gimp_color_profile_store_get_property (GObject
static gboolean gimp_color_profile_store_history_insert (GimpColorProfileStore *store, static gboolean gimp_color_profile_store_history_insert (GimpColorProfileStore *store,
GtkTreeIter *iter, GtkTreeIter *iter,
const gchar *filename, GFile *file,
const gchar *label, const gchar *label,
gint index); gint index);
static void gimp_color_profile_store_get_separator (GimpColorProfileStore *store, static void gimp_color_profile_store_get_separator (GimpColorProfileStore *store,
@ -121,7 +121,7 @@ gimp_color_profile_store_init (GimpColorProfileStore *store)
{ {
G_TYPE_INT, /* GIMP_COLOR_PROFILE_STORE_ITEM_TYPE */ G_TYPE_INT, /* GIMP_COLOR_PROFILE_STORE_ITEM_TYPE */
G_TYPE_STRING, /* GIMP_COLOR_PROFILE_STORE_LABEL */ G_TYPE_STRING, /* GIMP_COLOR_PROFILE_STORE_LABEL */
G_TYPE_STRING, /* GIMP_COLOR_PROFILE_STORE_FILENAME */ G_TYPE_FILE, /* GIMP_COLOR_PROFILE_STORE_FILE */
G_TYPE_INT /* GIMP_COLOR_PROFILE_STORE_INDEX */ G_TYPE_INT /* GIMP_COLOR_PROFILE_STORE_INDEX */
}; };
@ -262,6 +262,8 @@ gimp_color_profile_store_new (const gchar *history)
* @label will be set to the string "None" for you (and translated for * @label will be set to the string "None" for you (and translated for
* the user). * the user).
* *
* Deprecated: use gimp_color_profile_store_add_file() instead.
*
* Since: 2.4 * Since: 2.4
**/ **/
void void
@ -269,13 +271,49 @@ gimp_color_profile_store_add (GimpColorProfileStore *store,
const gchar *filename, const gchar *filename,
const gchar *label) const gchar *label)
{ {
GtkTreeIter separator; GFile *file = NULL;
GtkTreeIter iter;
g_return_if_fail (GIMP_IS_COLOR_PROFILE_STORE (store)); g_return_if_fail (GIMP_IS_COLOR_PROFILE_STORE (store));
g_return_if_fail (label != NULL || filename == NULL); g_return_if_fail (label != NULL || filename == NULL);
if (! filename && ! label) if (filename)
file = g_file_new_for_path (filename);
gimp_color_profile_store_add_file (store, file, label);
g_object_unref (file);
}
/**
* gimp_color_profile_store_add_file:
* @store: a #GimpColorProfileStore
* @file: file of the profile to add (or %NULL)
* @label: label to use for the profile
* (may only be %NULL if @filename is %NULL)
*
* Adds a color profile item to the #GimpColorProfileStore. Items
* added with this function will be kept at the top, separated from
* the history of last used color profiles.
*
* This function is often used to add a selectable item for the %NULL
* file. If you pass %NULL for both @file and @label, the @label will
* be set to the string "None" for you (and translated for the user).
*
* Since: 2.10
**/
void
gimp_color_profile_store_add_file (GimpColorProfileStore *store,
GFile *file,
const gchar *label)
{
GtkTreeIter separator;
GtkTreeIter iter;
g_return_if_fail (GIMP_IS_COLOR_PROFILE_STORE (store));
g_return_if_fail (label != NULL || file == NULL);
g_return_if_fail (file == NULL || G_IS_FILE (file));
if (! file && ! label)
label = C_("profile", "None"); label = C_("profile", "None");
gimp_color_profile_store_get_separator (store, &separator, TRUE); gimp_color_profile_store_get_separator (store, &separator, TRUE);
@ -284,7 +322,7 @@ gimp_color_profile_store_add (GimpColorProfileStore *store,
gtk_list_store_set (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_TYPE,
GIMP_COLOR_PROFILE_STORE_ITEM_FILE, GIMP_COLOR_PROFILE_STORE_ITEM_FILE,
GIMP_COLOR_PROFILE_STORE_FILENAME, filename, GIMP_COLOR_PROFILE_STORE_FILE, file,
GIMP_COLOR_PROFILE_STORE_LABEL, label, GIMP_COLOR_PROFILE_STORE_LABEL, label,
GIMP_COLOR_PROFILE_STORE_INDEX, -1, GIMP_COLOR_PROFILE_STORE_INDEX, -1,
-1); -1);
@ -293,7 +331,7 @@ gimp_color_profile_store_add (GimpColorProfileStore *store,
/** /**
* _gimp_color_profile_store_history_add: * _gimp_color_profile_store_history_add:
* @store: a #GimpColorProfileStore * @store: a #GimpColorProfileStore
* @filename: filename of the profile to add (or %NULL) * @file: file of the profile to add (or %NULL)
* @label: label to use for the profile (or %NULL) * @label: label to use for the profile (or %NULL)
* @iter: a #GtkTreeIter * @iter: a #GtkTreeIter
* *
@ -303,7 +341,7 @@ gimp_color_profile_store_add (GimpColorProfileStore *store,
**/ **/
gboolean gboolean
_gimp_color_profile_store_history_add (GimpColorProfileStore *store, _gimp_color_profile_store_history_add (GimpColorProfileStore *store,
const gchar *filename, GFile *file,
const gchar *label, const gchar *label,
GtkTreeIter *iter) GtkTreeIter *iter)
{ {
@ -322,7 +360,7 @@ _gimp_color_profile_store_history_add (GimpColorProfileStore *store,
{ {
gint type; gint type;
gint index; gint index;
gchar *this; GFile *this;
gtk_tree_model_get (model, iter, gtk_tree_model_get (model, iter,
GIMP_COLOR_PROFILE_STORE_ITEM_TYPE, &type, GIMP_COLOR_PROFILE_STORE_ITEM_TYPE, &type,
@ -337,11 +375,11 @@ _gimp_color_profile_store_history_add (GimpColorProfileStore *store,
/* check if we found a filename match */ /* check if we found a filename match */
gtk_tree_model_get (model, iter, gtk_tree_model_get (model, iter,
GIMP_COLOR_PROFILE_STORE_FILENAME, &this, GIMP_COLOR_PROFILE_STORE_FILE, &this,
-1); -1);
if ((this && filename && strcmp (filename, this) == 0) || if ((this && file && g_file_equal (this, file)) ||
(! this && ! filename)) (! this && ! file))
{ {
/* update the label */ /* update the label */
if (label && *label) if (label && *label)
@ -349,26 +387,32 @@ _gimp_color_profile_store_history_add (GimpColorProfileStore *store,
GIMP_COLOR_PROFILE_STORE_LABEL, label, GIMP_COLOR_PROFILE_STORE_LABEL, label,
-1); -1);
g_free (this); if (this)
g_object_unref (this);
return TRUE; return TRUE;
} }
if (this)
g_object_unref (this);
} }
if (! filename) if (! file)
return FALSE; return FALSE;
if (label && *label) if (label && *label)
{ {
iter_valid = gimp_color_profile_store_history_insert (store, iter, iter_valid = gimp_color_profile_store_history_insert (store, iter,
filename, label, file, label,
++max); ++max);
} }
else else
{ {
gchar *basename = g_filename_display_basename (filename); const gchar *utf8 = gimp_file_get_utf8_name (file);
gchar *basename = g_path_get_basename (utf8);
iter_valid = gimp_color_profile_store_history_insert (store, iter, iter_valid = gimp_color_profile_store_history_insert (store, iter,
filename, basename, file, basename,
++max); ++max);
g_free (basename); g_free (basename);
} }
@ -438,7 +482,7 @@ _gimp_color_profile_store_history_reorder (GimpColorProfileStore *store,
static gboolean static gboolean
gimp_color_profile_store_history_insert (GimpColorProfileStore *store, gimp_color_profile_store_history_insert (GimpColorProfileStore *store,
GtkTreeIter *iter, GtkTreeIter *iter,
const gchar *filename, GFile *file,
const gchar *label, const gchar *label,
gint index) gint index)
{ {
@ -446,7 +490,7 @@ gimp_color_profile_store_history_insert (GimpColorProfileStore *store,
GtkTreeIter sibling; GtkTreeIter sibling;
gboolean iter_valid; gboolean iter_valid;
g_return_val_if_fail (filename != NULL, FALSE); g_return_val_if_fail (G_IS_FILE (file), FALSE);
g_return_val_if_fail (label != NULL, FALSE); g_return_val_if_fail (label != NULL, FALSE);
g_return_val_if_fail (index > -1, FALSE); g_return_val_if_fail (index > -1, FALSE);
@ -495,7 +539,7 @@ gimp_color_profile_store_history_insert (GimpColorProfileStore *store,
gtk_list_store_set (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_TYPE,
GIMP_COLOR_PROFILE_STORE_ITEM_FILE, GIMP_COLOR_PROFILE_STORE_ITEM_FILE,
GIMP_COLOR_PROFILE_STORE_FILENAME, filename, GIMP_COLOR_PROFILE_STORE_FILE, file,
GIMP_COLOR_PROFILE_STORE_LABEL, label, GIMP_COLOR_PROFILE_STORE_LABEL, label,
GIMP_COLOR_PROFILE_STORE_INDEX, index, GIMP_COLOR_PROFILE_STORE_INDEX, index,
-1); -1);
@ -587,15 +631,19 @@ gimp_color_profile_store_load_profile (GimpColorProfileStore *store,
if (gimp_scanner_parse_string (scanner, &label) && if (gimp_scanner_parse_string (scanner, &label) &&
gimp_scanner_parse_string (scanner, &uri)) gimp_scanner_parse_string (scanner, &uri))
{ {
gchar *filename = g_filename_from_uri (uri, NULL, NULL); GFile *file = g_file_new_for_uri (uri);
if (filename && g_file_test (filename, G_FILE_TEST_IS_REGULAR)) if (file)
{
if (g_file_query_file_type (file, 0, NULL) == G_FILE_TYPE_REGULAR)
{ {
gimp_color_profile_store_history_insert (store, &iter, gimp_color_profile_store_history_insert (store, &iter,
filename, label, index); file, label, index);
}
g_object_unref (file);
} }
g_free (filename);
g_free (label); g_free (label);
g_free (uri); g_free (uri);
@ -669,7 +717,7 @@ gimp_color_profile_store_save (GimpColorProfileStore *store,
GtkTreeModel *model; GtkTreeModel *model;
GtkTreeIter iter; GtkTreeIter iter;
gchar *labels[HISTORY_SIZE] = { NULL, }; gchar *labels[HISTORY_SIZE] = { NULL, };
gchar *filenames[HISTORY_SIZE] = { NULL, }; GFile *files[HISTORY_SIZE] = { NULL, };
gboolean iter_valid; gboolean iter_valid;
gint i; gint i;
@ -698,14 +746,14 @@ gimp_color_profile_store_save (GimpColorProfileStore *store,
index >= 0 && index >= 0 &&
index < HISTORY_SIZE) index < HISTORY_SIZE)
{ {
if (labels[index] || filenames[index]) if (labels[index] || files[index])
g_warning ("%s: double index %d", G_STRFUNC, index); g_warning ("%s: double index %d", G_STRFUNC, index);
gtk_tree_model_get (model, &iter, gtk_tree_model_get (model, &iter,
GIMP_COLOR_PROFILE_STORE_LABEL, GIMP_COLOR_PROFILE_STORE_LABEL,
&labels[index], &labels[index],
GIMP_COLOR_PROFILE_STORE_FILENAME, GIMP_COLOR_PROFILE_STORE_FILE,
&filenames[index], &files[index],
-1); -1);
} }
} }
@ -713,9 +761,9 @@ gimp_color_profile_store_save (GimpColorProfileStore *store,
for (i = 0; i < HISTORY_SIZE; i++) for (i = 0; i < HISTORY_SIZE; i++)
{ {
if (filenames[i] && labels[i]) if (files[i] && labels[i])
{ {
gchar *uri = g_filename_to_uri (filenames[i], NULL, NULL); gchar *uri = g_file_get_uri (files[i]);
if (uri) if (uri)
{ {
@ -728,7 +776,9 @@ gimp_color_profile_store_save (GimpColorProfileStore *store,
} }
} }
g_free (filenames[i]); if (files[i])
g_object_unref (files[i]);
g_free (labels[i]); g_free (labels[i]);
} }

View File

@ -61,10 +61,15 @@ GType gimp_color_profile_store_get_type (void) G_GNUC_CONST;
GtkListStore * gimp_color_profile_store_new (const gchar *history); GtkListStore * gimp_color_profile_store_new (const gchar *history);
GIMP_DEPRECATED_FOR(gimp_color_profile_store_add_file)
void gimp_color_profile_store_add (GimpColorProfileStore *store, void gimp_color_profile_store_add (GimpColorProfileStore *store,
const gchar *filename, const gchar *filename,
const gchar *label); const gchar *label);
void gimp_color_profile_store_add_file (GimpColorProfileStore *store,
GFile *file,
const gchar *label);
G_END_DECLS G_END_DECLS

View File

@ -76,12 +76,16 @@ EXPORTS
gimp_color_profile_chooser_dialog_get_type gimp_color_profile_chooser_dialog_get_type
gimp_color_profile_chooser_dialog_new gimp_color_profile_chooser_dialog_new
gimp_color_profile_combo_box_add gimp_color_profile_combo_box_add
gimp_color_profile_combo_box_add_file
gimp_color_profile_combo_box_get_active gimp_color_profile_combo_box_get_active
gimp_color_profile_combo_box_get_active_file
gimp_color_profile_combo_box_get_type gimp_color_profile_combo_box_get_type
gimp_color_profile_combo_box_new gimp_color_profile_combo_box_new
gimp_color_profile_combo_box_new_with_model gimp_color_profile_combo_box_new_with_model
gimp_color_profile_combo_box_set_active gimp_color_profile_combo_box_set_active
gimp_color_profile_combo_box_set_active_file
gimp_color_profile_store_add gimp_color_profile_store_add
gimp_color_profile_store_add_file
gimp_color_profile_store_get_type gimp_color_profile_store_get_type
gimp_color_profile_store_new gimp_color_profile_store_new
gimp_color_profile_view_get_type gimp_color_profile_view_get_type

View File

@ -261,15 +261,22 @@ static void
cdisplay_proof_profile_changed (GtkWidget *combo, cdisplay_proof_profile_changed (GtkWidget *combo,
CdisplayProof *proof) CdisplayProof *proof)
{ {
gchar *profile; GFile *file;
gchar *path = NULL;
profile = gimp_color_profile_combo_box_get_active (GIMP_COLOR_PROFILE_COMBO_BOX (combo)); file = gimp_color_profile_combo_box_get_active_file (GIMP_COLOR_PROFILE_COMBO_BOX (combo));
if (file)
{
path = g_file_get_path (file);
g_object_unref (file);
}
g_object_set (proof, g_object_set (proof,
"profile", profile, "profile", path,
NULL); NULL);
g_free (profile); g_free (path);
} }
static GtkWidget * static GtkWidget *
@ -297,8 +304,13 @@ cdisplay_proof_configure (GimpColorDisplay *display)
proof); proof);
if (proof->profile) if (proof->profile)
gimp_color_profile_combo_box_set_active (GIMP_COLOR_PROFILE_COMBO_BOX (combo), {
proof->profile, NULL); GFile *file = g_file_new_for_path (proof->profile);
gimp_color_profile_combo_box_set_active_file (GIMP_COLOR_PROFILE_COMBO_BOX (combo),
file, NULL);
g_object_unref (file);
}
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0, gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("_Profile:"), 0.0, 0.5, _("_Profile:"), 0.0, 0.5,

View File

@ -637,14 +637,13 @@ lcms_icc_apply_dialog (gint32 image,
} }
static GtkWidget * static GtkWidget *
lcms_icc_combo_box_new (GimpColorConfig *config, lcms_icc_combo_box_new (GimpColorConfig *config)
const gchar *filename)
{ {
GtkWidget *combo; GtkWidget *combo;
GtkWidget *dialog; GtkWidget *dialog;
gchar *history; gchar *history;
gchar *label; gchar *label;
const gchar *rgb_filename = NULL; GFile *rgb_file = NULL;
GimpColorProfile *profile = NULL; GimpColorProfile *profile = NULL;
GError *error = NULL; GError *error = NULL;
@ -658,7 +657,7 @@ lcms_icc_combo_box_new (GimpColorConfig *config,
if (profile) if (profile)
{ {
rgb_filename = config->rgb_profile; rgb_file = g_file_new_for_path (config->rgb_profile);
} }
else if (error) else if (error)
{ {
@ -674,12 +673,14 @@ lcms_icc_combo_box_new (GimpColorConfig *config,
g_object_unref (profile); g_object_unref (profile);
gimp_color_profile_combo_box_add (GIMP_COLOR_PROFILE_COMBO_BOX (combo), gimp_color_profile_combo_box_add_file (GIMP_COLOR_PROFILE_COMBO_BOX (combo),
rgb_filename, label); rgb_file, label);
if (rgb_file)
g_object_unref (rgb_file);
g_free (label); g_free (label);
gimp_color_profile_combo_box_set_active (GIMP_COLOR_PROFILE_COMBO_BOX (combo), gimp_color_profile_combo_box_set_active_file (GIMP_COLOR_PROFILE_COMBO_BOX (combo),
filename, NULL); NULL, NULL);
return combo; return combo;
} }
@ -745,7 +746,7 @@ lcms_dialog (GimpColorConfig *config,
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame); gtk_widget_show (frame);
combo = lcms_icc_combo_box_new (config, NULL); combo = lcms_icc_combo_box_new (config);
gtk_container_add (GTK_CONTAINER (frame), combo); gtk_container_add (GTK_CONTAINER (frame), combo);
gtk_widget_show (combo); gtk_widget_show (combo);
@ -793,18 +794,11 @@ lcms_dialog (GimpColorConfig *config,
while ((run = gimp_dialog_run (GIMP_DIALOG (dialog))) == GTK_RESPONSE_OK) while ((run = gimp_dialog_run (GIMP_DIALOG (dialog))) == GTK_RESPONSE_OK)
{ {
gchar *filename = gimp_color_profile_combo_box_get_active (box); GFile *file = gimp_color_profile_combo_box_get_active_file (box);
GFile *file = NULL;
GimpColorProfile *dest_profile; GimpColorProfile *dest_profile;
gtk_widget_set_sensitive (dialog, FALSE); gtk_widget_set_sensitive (dialog, FALSE);
if (filename)
{
file = g_file_new_for_path (filename);
g_free (filename);
}
if (file) if (file)
{ {
GError *error = NULL; GError *error = NULL;