~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/widgets/gimpprofilechooserdialog.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GIMP - The GNU Image Manipulation Program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * GimpProfileChooserDialog
 
5
 * Copyright (C) 2006 Sven Neumann <sven@gimp.org>
 
6
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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.
 
20
 */
 
21
 
 
22
#include "config.h"
 
23
 
 
24
#include <gtk/gtk.h>
 
25
 
 
26
#include "widgets-types.h"
 
27
 
 
28
#include "core/gimp.h"
 
29
 
 
30
#include "plug-in/plug-in-icc-profile.h"
 
31
 
 
32
#include "gimpprofilechooserdialog.h"
 
33
 
 
34
#include "gimp-intl.h"
 
35
 
 
36
 
 
37
enum
 
38
{
 
39
  PROP_0,
 
40
  PROP_GIMP
 
41
};
 
42
 
 
43
 
 
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,
 
47
                                                          guint                     n_params,
 
48
                                                          GObjectConstructParam    *params);
 
49
 
 
50
static void   gimp_profile_chooser_dialog_dispose        (GObject                  *object);
 
51
static void   gimp_profile_chooser_dialog_set_property   (GObject                  *object,
 
52
                                                          guint                     prop_id,
 
53
                                                          const GValue             *value,
 
54
                                                          GParamSpec               *pspec);
 
55
static void   gimp_profile_chooser_dialog_get_property   (GObject                  *object,
 
56
                                                          guint                     prop_id,
 
57
                                                          GValue                   *value,
 
58
                                                          GParamSpec               *pspec);
 
59
 
 
60
static void   gimp_profile_chooser_dialog_style_set      (GtkWidget                *widget,
 
61
                                                          GtkStyle                 *prev_style);
 
62
 
 
63
static void   gimp_profile_chooser_dialog_update_preview (GimpProfileChooserDialog *dialog);
 
64
 
 
65
static GtkWidget * gimp_profile_view_new                 (GimpProfileChooserDialog *dialog);
 
66
static gboolean    gimp_profile_view_query               (GimpProfileChooserDialog *dialog);
 
67
 
 
68
 
 
69
G_DEFINE_TYPE (GimpProfileChooserDialog, gimp_profile_chooser_dialog,
 
70
               GTK_TYPE_FILE_CHOOSER_DIALOG);
 
71
 
 
72
#define parent_class gimp_profile_chooser_dialog_parent_class
 
73
 
 
74
 
 
75
static void
 
76
gimp_profile_chooser_dialog_class_init (GimpProfileChooserDialogClass *klass)
 
77
{
 
78
  GObjectClass   *object_class = G_OBJECT_CLASS (klass);
 
79
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
80
 
 
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;
 
85
 
 
86
  widget_class->style_set    = gimp_profile_chooser_dialog_style_set;
 
87
 
 
88
  g_object_class_install_property (object_class, PROP_GIMP,
 
89
                                   g_param_spec_object ("gimp",
 
90
                                                        NULL, NULL,
 
91
                                                        GIMP_TYPE_GIMP,
 
92
                                                        GIMP_PARAM_READWRITE |
 
93
                                                        G_PARAM_CONSTRUCT_ONLY));
 
94
}
 
95
 
 
96
static void
 
97
gimp_profile_chooser_dialog_init (GimpProfileChooserDialog *dialog)
 
98
{
 
99
  dialog->idle_id = 0;
 
100
 
 
101
  dialog->info_label = g_object_new (GTK_TYPE_LABEL,
 
102
                                     "xalign", 0.0,
 
103
                                     "yalign", 0.0,
 
104
                                     NULL);
 
105
 
 
106
  gtk_widget_set_size_request (dialog->info_label, 200, -1);
 
107
 
 
108
  dialog->preview = gimp_profile_view_new (dialog);
 
109
}
 
110
 
 
111
static GObject *
 
112
gimp_profile_chooser_dialog_constructor (GType                  type,
 
113
                                         guint                  n_params,
 
114
                                         GObjectConstructParam *params)
 
115
{
 
116
  GObject                  *object;
 
117
  GimpProfileChooserDialog *dialog;
 
118
  GtkFileFilter            *filter;
 
119
 
 
120
  object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
 
121
 
 
122
  dialog = GIMP_PROFILE_CHOOSER_DIALOG (object);
 
123
 
 
124
  gtk_window_set_role (GTK_WINDOW (dialog), "gimp-profile-chooser-dialog");
 
125
 
 
126
  gtk_dialog_add_buttons (GTK_DIALOG (dialog),
 
127
                          GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 
128
                          GTK_STOCK_OPEN,   GTK_RESPONSE_ACCEPT,
 
129
                          NULL);
 
130
 
 
131
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
 
132
                                           GTK_RESPONSE_ACCEPT,
 
133
                                           GTK_RESPONSE_CANCEL,
 
134
                                           -1);
 
135
 
 
136
  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
 
137
 
 
138
#ifndef G_OS_WIN32
 
139
  {
 
140
    const gchar folder[] = "/usr/share/color/icc";
 
141
 
 
142
    if (g_file_test (folder, G_FILE_TEST_IS_DIR))
 
143
      gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog),
 
144
                                            folder, NULL);
 
145
  }
 
146
#endif
 
147
 
 
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);
 
152
 
 
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);
 
158
 
 
159
  gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
 
160
 
 
161
  gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (dialog),
 
162
                                       dialog->preview);
 
163
 
 
164
  g_signal_connect (dialog, "update-preview",
 
165
                    G_CALLBACK (gimp_profile_chooser_dialog_update_preview),
 
166
                    NULL);
 
167
 
 
168
  return object;
 
169
}
 
170
 
 
171
static void
 
172
gimp_profile_chooser_dialog_dispose (GObject *object)
 
173
{
 
174
  GimpProfileChooserDialog *dialog = GIMP_PROFILE_CHOOSER_DIALOG (object);
 
175
 
 
176
  if (dialog->idle_id)
 
177
    {
 
178
      g_source_remove (dialog->idle_id);
 
179
      dialog->idle_id = 0;
 
180
    }
 
181
 
 
182
  G_OBJECT_CLASS (parent_class)->dispose (object);
 
183
}
 
184
 
 
185
static void
 
186
gimp_profile_chooser_dialog_set_property (GObject      *object,
 
187
                                          guint         prop_id,
 
188
                                          const GValue *value,
 
189
                                          GParamSpec   *pspec)
 
190
{
 
191
  GimpProfileChooserDialog *dialog = GIMP_PROFILE_CHOOSER_DIALOG (object);
 
192
 
 
193
  switch (prop_id)
 
194
    {
 
195
    case PROP_GIMP:
 
196
      dialog->gimp = g_value_get_object (value);
 
197
      break;
 
198
    default:
 
199
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
200
      break;
 
201
    }
 
202
}
 
203
 
 
204
static void
 
205
gimp_profile_chooser_dialog_get_property (GObject    *object,
 
206
                                          guint       prop_id,
 
207
                                          GValue     *value,
 
208
                                          GParamSpec *pspec)
 
209
{
 
210
  GimpProfileChooserDialog *dialog = GIMP_PROFILE_CHOOSER_DIALOG (object);
 
211
 
 
212
  switch (prop_id)
 
213
    {
 
214
    case PROP_GIMP:
 
215
      g_value_set_object (value, dialog->gimp);
 
216
      break;
 
217
    default:
 
218
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
219
      break;
 
220
    }
 
221
}
 
222
 
 
223
static void
 
224
gimp_profile_chooser_dialog_style_set (GtkWidget *widget,
 
225
                                       GtkStyle  *prev_style)
 
226
{
 
227
  GimpProfileChooserDialog *dialog = GIMP_PROFILE_CHOOSER_DIALOG (widget);
 
228
  GtkWidget                *ebox;
 
229
 
 
230
  GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style);
 
231
 
 
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]);
 
236
 
 
237
  ebox = gtk_bin_get_child (GTK_BIN (widget));
 
238
 
 
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]);
 
243
}
 
244
 
 
245
GtkWidget *
 
246
gimp_profile_chooser_dialog_new (Gimp        *gimp,
 
247
                                 const gchar *title)
 
248
{
 
249
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
 
250
 
 
251
  return g_object_new (GIMP_TYPE_PROFILE_CHOOSER_DIALOG,
 
252
                       "gimp",  gimp,
 
253
                       "title", title,
 
254
                       NULL);
 
255
}
 
256
 
 
257
static void
 
258
gimp_profile_chooser_dialog_update_preview (GimpProfileChooserDialog *dialog)
 
259
{
 
260
  gtk_label_set_text (GTK_LABEL (dialog->info_label), "");
 
261
 
 
262
  if (dialog->idle_id)
 
263
    g_source_remove (dialog->idle_id);
 
264
 
 
265
  dialog->idle_id = g_idle_add ((GSourceFunc) gimp_profile_view_query,
 
266
                                dialog);
 
267
}
 
268
 
 
269
static GtkWidget *
 
270
gimp_profile_view_new (GimpProfileChooserDialog *dialog)
 
271
{
 
272
  GtkWidget *frame;
 
273
  GtkWidget *ebox;
 
274
  GtkWidget *vbox;
 
275
 
 
276
  frame = gtk_frame_new (NULL);
 
277
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
 
278
 
 
279
  ebox = gtk_event_box_new ();
 
280
  gtk_container_add (GTK_CONTAINER (frame), ebox);
 
281
  gtk_widget_show (ebox);
 
282
 
 
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);
 
287
 
 
288
  gtk_box_pack_start (GTK_BOX (vbox), dialog->info_label, FALSE, FALSE, 0);
 
289
  gtk_widget_show (dialog->info_label);
 
290
 
 
291
  return frame;
 
292
}
 
293
 
 
294
static gboolean
 
295
gimp_profile_view_query (GimpProfileChooserDialog *dialog)
 
296
{
 
297
  gchar  *uri;
 
298
  gchar  *filename;
 
299
 
 
300
  uri = gtk_file_chooser_get_preview_uri (GTK_FILE_CHOOSER (dialog));
 
301
  if (! uri)
 
302
    return FALSE;
 
303
 
 
304
  filename = g_filename_from_uri (uri, NULL, NULL);
 
305
 
 
306
  if (filename)
 
307
    {
 
308
      gchar *info = NULL;
 
309
 
 
310
      if (plug_in_icc_profile_file_info (dialog->gimp,
 
311
                                         gimp_get_user_context (dialog->gimp),
 
312
                                         NULL,
 
313
                                         filename,
 
314
                                         NULL, NULL, &info,
 
315
                                         NULL))
 
316
        {
 
317
          gtk_label_set_text (GTK_LABEL (dialog->info_label), info);
 
318
          g_free (info);
 
319
        }
 
320
 
 
321
      g_free (filename);
 
322
    }
 
323
 
 
324
  g_free (uri);
 
325
 
 
326
  return FALSE;
 
327
}