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

« back to all changes in this revision

Viewing changes to app/dialogs/quit-dialog.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
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * Copyright (C) 2004  Sven Neumann <sven@gimp.org>
29
29
#include "config/gimpcoreconfig.h"
30
30
 
31
31
#include "core/gimp.h"
 
32
#include "core/gimpcontext.h"
32
33
#include "core/gimplist.h"
33
34
 
34
35
#include "display/gimpdisplay.h"
35
36
#include "display/gimpdisplay-foreach.h"
36
37
 
37
38
#include "widgets/gimpcontainertreeview.h"
 
39
#include "widgets/gimpcontainerview.h"
 
40
#include "widgets/gimpdnd.h"
38
41
#include "widgets/gimphelp-ids.h"
39
42
#include "widgets/gimpmessagebox.h"
40
43
#include "widgets/gimpmessagedialog.h"
44
47
#include "gimp-intl.h"
45
48
 
46
49
 
47
 
static void  quit_dialog_response          (GtkWidget         *dialog,
48
 
                                            gint               response_id,
49
 
                                            Gimp              *gimp);
50
 
static void  quit_dialog_container_changed (GimpContainer     *images,
51
 
                                            GimpObject        *image,
52
 
                                            GimpMessageBox    *box);
53
 
static void  quit_dialog_image_activated   (GimpContainerView *view,
54
 
                                            GimpImage         *image,
55
 
                                            gpointer           insert_data,
56
 
                                            Gimp              *gimp);
 
50
static GtkWidget * quit_close_all_dialog_new               (Gimp              *gimp,
 
51
                                                            gboolean           do_quit);
 
52
static void        quit_close_all_dialog_response          (GtkWidget         *dialog,
 
53
                                                            gint               response_id,
 
54
                                                            Gimp              *gimp);
 
55
static void        quit_close_all_dialog_container_changed (GimpContainer     *images,
 
56
                                                            GimpObject        *image,
 
57
                                                            GimpMessageBox    *box);
 
58
static void        quit_close_all_dialog_image_activated   (GimpContainerView *view,
 
59
                                                            GimpImage         *image,
 
60
                                                            gpointer           insert_data,
 
61
                                                            Gimp              *gimp);
57
62
 
58
63
 
59
64
/*  public functions  */
61
66
GtkWidget *
62
67
quit_dialog_new (Gimp *gimp)
63
68
{
 
69
  return quit_close_all_dialog_new (gimp, TRUE);
 
70
}
 
71
 
 
72
GtkWidget *
 
73
close_all_dialog_new (Gimp *gimp)
 
74
{
 
75
  return quit_close_all_dialog_new (gimp, FALSE);
 
76
}
 
77
 
 
78
static GtkWidget *
 
79
quit_close_all_dialog_new (Gimp     *gimp,
 
80
                           gboolean  do_quit)
 
81
{
64
82
  GimpContainer  *images;
 
83
  GimpContext    *context;
65
84
  GimpMessageBox *box;
66
85
  GtkWidget      *dialog;
67
86
  GtkWidget      *label;
68
87
  GtkWidget      *button;
69
88
  GtkWidget      *view;
 
89
  GtkWidget      *dnd_widget;
70
90
  gint            rows;
71
 
  gint            preview_size;
 
91
  gint            view_size;
72
92
 
73
93
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
74
94
 
76
96
#warning FIXME: need container of dirty images
77
97
#endif
78
98
 
79
 
  images = gimp_displays_get_dirty_images (gimp);
 
99
  images  = gimp_displays_get_dirty_images (gimp);
 
100
  context = gimp_context_new (gimp, "close-all-dialog",
 
101
                              gimp_get_user_context (gimp));
80
102
 
81
103
  g_return_val_if_fail (images != NULL, NULL);
82
104
 
83
105
  dialog =
84
 
    gimp_message_dialog_new (_("Quit The GIMP"), GIMP_STOCK_WILBER_EEK,
 
106
    gimp_message_dialog_new (do_quit ? _("Quit GIMP") : _("Close All Images"),
 
107
                             GIMP_STOCK_WARNING,
85
108
                             NULL, 0,
86
 
                             gimp_standard_help_func, NULL,
 
109
                             gimp_standard_help_func,
 
110
                             do_quit ?
 
111
                             GIMP_HELP_FILE_QUIT : GIMP_HELP_FILE_CLOSE_ALL,
87
112
 
88
113
                             GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
89
114
 
91
116
 
92
117
  g_object_set_data_full (G_OBJECT (dialog), "dirty-images",
93
118
                          images, (GDestroyNotify) g_object_unref);
 
119
  g_object_set_data_full (G_OBJECT (dialog), "dirty-images-context",
 
120
                          context, (GDestroyNotify) g_object_unref);
94
121
 
95
122
  g_signal_connect (dialog, "response",
96
 
                    G_CALLBACK (quit_dialog_response),
 
123
                    G_CALLBACK (quit_close_all_dialog_response),
97
124
                    gimp);
98
125
 
99
126
  box = GIMP_MESSAGE_DIALOG (dialog)->box;
101
128
  button = gtk_dialog_add_button (GTK_DIALOG (dialog), "", GTK_RESPONSE_OK);
102
129
 
103
130
  g_object_set_data (G_OBJECT (box), "ok-button", button);
 
131
  g_object_set_data (G_OBJECT (box), "do-quit", GINT_TO_POINTER (do_quit));
104
132
 
105
133
  g_signal_connect_object (images, "add",
106
 
                           G_CALLBACK (quit_dialog_container_changed),
 
134
                           G_CALLBACK (quit_close_all_dialog_container_changed),
107
135
                           box, 0);
108
136
  g_signal_connect_object (images, "remove",
109
 
                           G_CALLBACK (quit_dialog_container_changed),
 
137
                           G_CALLBACK (quit_close_all_dialog_container_changed),
110
138
                           box, 0);
111
139
 
112
 
  preview_size = gimp->config->layer_preview_size;
113
 
  rows         = CLAMP (gimp_container_num_children (images), 3, 6);
114
 
 
115
 
  view = gimp_container_tree_view_new (images, NULL, preview_size, 1);
 
140
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
 
141
                                           GTK_RESPONSE_OK,
 
142
                                           GTK_RESPONSE_CANCEL,
 
143
                                           -1);
 
144
 
 
145
  view_size = gimp->config->layer_preview_size;
 
146
  rows      = CLAMP (gimp_container_num_children (images), 3, 6);
 
147
 
 
148
  view = gimp_container_tree_view_new (images, context, view_size, 1);
116
149
  gimp_container_box_set_size_request (GIMP_CONTAINER_BOX (view),
117
150
                                       -1,
118
 
                                       rows * (preview_size + 2));
 
151
                                       rows * (view_size + 2));
119
152
  gtk_box_pack_start (GTK_BOX (box), view, TRUE, TRUE, 0);
120
153
  gtk_widget_show (view);
121
154
 
122
155
  g_signal_connect (view, "activate-item",
123
 
                    G_CALLBACK (quit_dialog_image_activated),
 
156
                    G_CALLBACK (quit_close_all_dialog_image_activated),
124
157
                    gimp);
125
158
 
126
 
  label = gtk_label_new (_("If you quit GIMP now, "
127
 
                           "these changes will be lost."));
 
159
  dnd_widget = gimp_container_view_get_dnd_widget (GIMP_CONTAINER_VIEW (view));
 
160
  gimp_dnd_xds_source_add (dnd_widget,
 
161
                           (GimpDndDragViewableFunc) gimp_dnd_get_drag_data,
 
162
                           NULL);
 
163
 
 
164
  if (do_quit)
 
165
    label = gtk_label_new (_("If you quit GIMP now, "
 
166
                             "these changes will be lost."));
 
167
  else
 
168
    label = gtk_label_new (_("If you close these images now, "
 
169
                             "changes will be lost."));
128
170
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
129
171
  gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
130
172
  gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
132
174
 
133
175
  g_object_set_data (G_OBJECT (box), "lost-label", label);
134
176
 
135
 
  quit_dialog_container_changed (images, NULL,
136
 
                                 GIMP_MESSAGE_DIALOG (dialog)->box);
 
177
  quit_close_all_dialog_container_changed (images, NULL,
 
178
                                           GIMP_MESSAGE_DIALOG (dialog)->box);
137
179
 
138
180
  return dialog;
139
181
}
140
182
 
141
183
static void
142
 
quit_dialog_response (GtkWidget *dialog,
143
 
                      gint       response_id,
144
 
                      Gimp      *gimp)
 
184
quit_close_all_dialog_response (GtkWidget *dialog,
 
185
                                gint       response_id,
 
186
                                Gimp      *gimp)
145
187
{
 
188
  GimpMessageBox *box     = GIMP_MESSAGE_DIALOG (dialog)->box;
 
189
  gboolean        do_quit = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (box),
 
190
                                                                "do-quit"));
 
191
 
146
192
  gtk_widget_destroy (dialog);
147
193
 
148
194
  if (response_id == GTK_RESPONSE_OK)
149
 
    gimp_exit (gimp, TRUE);
 
195
    {
 
196
      if (do_quit)
 
197
        gimp_exit (gimp, TRUE);
 
198
      else
 
199
        gimp_displays_delete (gimp);
 
200
    }
150
201
}
151
202
 
152
203
static void
153
 
quit_dialog_container_changed (GimpContainer  *images,
154
 
                               GimpObject     *image,
155
 
                               GimpMessageBox *box)
 
204
quit_close_all_dialog_container_changed (GimpContainer  *images,
 
205
                                         GimpObject     *image,
 
206
                                         GimpMessageBox *box)
156
207
{
157
208
  gint       num_images = gimp_container_num_children (images);
158
209
  GtkWidget *label      = g_object_get_data (G_OBJECT (box), "lost-label");
159
210
  GtkWidget *button     = g_object_get_data (G_OBJECT (box), "ok-button");
160
211
  GtkWidget *dialog     = gtk_widget_get_toplevel (button);
 
212
  gboolean   do_quit    = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (box),
 
213
                                                              "do-quit"));
 
214
  gchar     *text;
161
215
 
162
 
  if (num_images == 1)
163
 
    gimp_message_box_set_primary_text (box,
164
 
                                       _("There is one image with unsaved changes:"));
165
 
  else
166
 
    gimp_message_box_set_primary_text (box,
167
 
                                       _("There are %d images with unsaved changes:"),
168
 
                                       num_images);
 
216
  text = g_strdup_printf (ngettext ("There is one image with unsaved changes:",
 
217
                                    "There are %d images with unsaved changes:",
 
218
                                    num_images), num_images);
 
219
  gimp_message_box_set_primary_text (box, text);
 
220
  g_free (text);
169
221
 
170
222
  if (num_images == 0)
171
223
    {
172
224
      gtk_widget_hide (label);
173
225
      g_object_set (button,
174
 
                    "label",     GTK_STOCK_QUIT,
 
226
                    "label",     do_quit ? GTK_STOCK_QUIT : GTK_STOCK_CLOSE,
175
227
                    "use-stock", TRUE,
 
228
                    "image",     NULL,
176
229
                    NULL);
177
230
      gtk_widget_grab_default (button);
178
231
    }
179
232
  else
180
233
    {
 
234
      GtkWidget *icon = gtk_image_new_from_stock (GTK_STOCK_DELETE,
 
235
                                                  GTK_ICON_SIZE_BUTTON);
181
236
      gtk_widget_show (label);
182
237
      g_object_set (button,
183
238
                    "label",     _("_Discard Changes"),
184
239
                    "use-stock", FALSE,
 
240
                    "image",     icon,
185
241
                    NULL);
186
 
      gtk_window_set_default (GTK_WINDOW (dialog), NULL);
 
242
      gtk_dialog_set_default_response (GTK_DIALOG (dialog),
 
243
                                       GTK_RESPONSE_CANCEL);
187
244
    }
188
245
}
189
246
 
190
247
static void
191
 
quit_dialog_image_activated (GimpContainerView *view,
192
 
                             GimpImage         *image,
193
 
                             gpointer           insert_data,
194
 
                             Gimp              *gimp)
 
248
quit_close_all_dialog_image_activated (GimpContainerView *view,
 
249
                                       GimpImage         *image,
 
250
                                       gpointer           insert_data,
 
251
                                       Gimp              *gimp)
195
252
{
196
253
  GList *list;
197
254
 
201
258
    {
202
259
      GimpDisplay *display = list->data;
203
260
 
204
 
      if (display->gimage == image)
 
261
      if (display->image == image)
205
262
        gtk_window_present (GTK_WINDOW (display->shell));
206
263
    }
207
264
}