1
/* GIMP - The GNU Image Manipulation Program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* GimpProfileChooserDialog
5
* Copyright (C) 2006 Sven Neumann <sven@gimp.org>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
#include "widgets-types.h"
28
#include "core/gimp.h"
30
#include "plug-in/plug-in-icc-profile.h"
32
#include "gimpprofilechooserdialog.h"
34
#include "gimp-intl.h"
44
static void gimp_profile_chooser_dialog_class_init (GimpProfileChooserDialogClass *klass);
45
static void gimp_profile_chooser_dialog_init (GimpProfileChooserDialog *dialog);
46
static GObject * gimp_profile_chooser_dialog_constructor (GType type,
48
GObjectConstructParam *params);
50
static void gimp_profile_chooser_dialog_dispose (GObject *object);
51
static void gimp_profile_chooser_dialog_set_property (GObject *object,
55
static void gimp_profile_chooser_dialog_get_property (GObject *object,
60
static void gimp_profile_chooser_dialog_style_set (GtkWidget *widget,
61
GtkStyle *prev_style);
63
static void gimp_profile_chooser_dialog_update_preview (GimpProfileChooserDialog *dialog);
65
static GtkWidget * gimp_profile_view_new (GimpProfileChooserDialog *dialog);
66
static gboolean gimp_profile_view_query (GimpProfileChooserDialog *dialog);
69
G_DEFINE_TYPE (GimpProfileChooserDialog, gimp_profile_chooser_dialog,
70
GTK_TYPE_FILE_CHOOSER_DIALOG);
72
#define parent_class gimp_profile_chooser_dialog_parent_class
76
gimp_profile_chooser_dialog_class_init (GimpProfileChooserDialogClass *klass)
78
GObjectClass *object_class = G_OBJECT_CLASS (klass);
79
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
81
object_class->constructor = gimp_profile_chooser_dialog_constructor;
82
object_class->dispose = gimp_profile_chooser_dialog_dispose;
83
object_class->get_property = gimp_profile_chooser_dialog_get_property;
84
object_class->set_property = gimp_profile_chooser_dialog_set_property;
86
widget_class->style_set = gimp_profile_chooser_dialog_style_set;
88
g_object_class_install_property (object_class, PROP_GIMP,
89
g_param_spec_object ("gimp",
92
GIMP_PARAM_READWRITE |
93
G_PARAM_CONSTRUCT_ONLY));
97
gimp_profile_chooser_dialog_init (GimpProfileChooserDialog *dialog)
101
dialog->info_label = g_object_new (GTK_TYPE_LABEL,
106
gtk_widget_set_size_request (dialog->info_label, 200, -1);
108
dialog->preview = gimp_profile_view_new (dialog);
112
gimp_profile_chooser_dialog_constructor (GType type,
114
GObjectConstructParam *params)
117
GimpProfileChooserDialog *dialog;
118
GtkFileFilter *filter;
120
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
122
dialog = GIMP_PROFILE_CHOOSER_DIALOG (object);
124
gtk_window_set_role (GTK_WINDOW (dialog), "gimp-profile-chooser-dialog");
126
gtk_dialog_add_buttons (GTK_DIALOG (dialog),
127
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
128
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
131
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
136
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
140
const gchar folder[] = "/usr/share/color/icc";
142
if (g_file_test (folder, G_FILE_TEST_IS_DIR))
143
gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog),
148
filter = gtk_file_filter_new ();
149
gtk_file_filter_set_name (filter, _("All files (*.*)"));
150
gtk_file_filter_add_pattern (filter, "*");
151
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
153
filter = gtk_file_filter_new ();
154
gtk_file_filter_set_name (filter, _("ICC color profile (*.icc, *.icm)"));
155
gtk_file_filter_add_pattern (filter, "*.[Ii][Cc][Cc]");
156
gtk_file_filter_add_pattern (filter, "*.[Ii][Cc][Mm]");
157
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
159
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
161
gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (dialog),
164
g_signal_connect (dialog, "update-preview",
165
G_CALLBACK (gimp_profile_chooser_dialog_update_preview),
172
gimp_profile_chooser_dialog_dispose (GObject *object)
174
GimpProfileChooserDialog *dialog = GIMP_PROFILE_CHOOSER_DIALOG (object);
178
g_source_remove (dialog->idle_id);
182
G_OBJECT_CLASS (parent_class)->dispose (object);
186
gimp_profile_chooser_dialog_set_property (GObject *object,
191
GimpProfileChooserDialog *dialog = GIMP_PROFILE_CHOOSER_DIALOG (object);
196
dialog->gimp = g_value_get_object (value);
199
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
205
gimp_profile_chooser_dialog_get_property (GObject *object,
210
GimpProfileChooserDialog *dialog = GIMP_PROFILE_CHOOSER_DIALOG (object);
215
g_value_set_object (value, dialog->gimp);
218
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
224
gimp_profile_chooser_dialog_style_set (GtkWidget *widget,
225
GtkStyle *prev_style)
227
GimpProfileChooserDialog *dialog = GIMP_PROFILE_CHOOSER_DIALOG (widget);
230
GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style);
232
gtk_widget_modify_bg (dialog->preview, GTK_STATE_NORMAL,
233
&widget->style->base[GTK_STATE_NORMAL]);
234
gtk_widget_modify_bg (dialog->preview, GTK_STATE_INSENSITIVE,
235
&widget->style->base[GTK_STATE_NORMAL]);
237
ebox = gtk_bin_get_child (GTK_BIN (widget));
239
gtk_widget_modify_bg (ebox, GTK_STATE_NORMAL,
240
&widget->style->base[GTK_STATE_NORMAL]);
241
gtk_widget_modify_bg (ebox, GTK_STATE_INSENSITIVE,
242
&widget->style->base[GTK_STATE_NORMAL]);
246
gimp_profile_chooser_dialog_new (Gimp *gimp,
249
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
251
return g_object_new (GIMP_TYPE_PROFILE_CHOOSER_DIALOG,
258
gimp_profile_chooser_dialog_update_preview (GimpProfileChooserDialog *dialog)
260
gtk_label_set_text (GTK_LABEL (dialog->info_label), "");
263
g_source_remove (dialog->idle_id);
265
dialog->idle_id = g_idle_add ((GSourceFunc) gimp_profile_view_query,
270
gimp_profile_view_new (GimpProfileChooserDialog *dialog)
276
frame = gtk_frame_new (NULL);
277
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
279
ebox = gtk_event_box_new ();
280
gtk_container_add (GTK_CONTAINER (frame), ebox);
281
gtk_widget_show (ebox);
283
vbox = gtk_vbox_new (FALSE, 12);
284
gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
285
gtk_container_add (GTK_CONTAINER (ebox), vbox);
286
gtk_widget_show (vbox);
288
gtk_box_pack_start (GTK_BOX (vbox), dialog->info_label, FALSE, FALSE, 0);
289
gtk_widget_show (dialog->info_label);
295
gimp_profile_view_query (GimpProfileChooserDialog *dialog)
300
uri = gtk_file_chooser_get_preview_uri (GTK_FILE_CHOOSER (dialog));
304
filename = g_filename_from_uri (uri, NULL, NULL);
310
if (plug_in_icc_profile_file_info (dialog->gimp,
311
gimp_get_user_context (dialog->gimp),
317
gtk_label_set_text (GTK_LABEL (dialog->info_label), info);