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

« back to all changes in this revision

Viewing changes to app/display/gimpdisplayshell-close.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
 * This program is free software; you can redistribute it and/or modify
48
48
/*  local function prototypes  */
49
49
 
50
50
static void      gimp_display_shell_close_dialog       (GimpDisplayShell *shell,
51
 
                                                        GimpImage        *gimage);
 
51
                                                        GimpImage        *image);
52
52
static void      gimp_display_shell_close_name_changed (GimpImage        *image,
53
53
                                                        GimpMessageBox   *box);
54
54
static gboolean  gimp_display_shell_close_time_changed (GimpMessageBox   *box);
56
56
                                                        gboolean          close,
57
57
                                                        GimpDisplayShell *shell);
58
58
 
59
 
static gchar   * gimp_time_since                       (guint             then);
 
59
static void      gimp_time_since                       (guint  then,
 
60
                                                        gint  *hours,
 
61
                                                        gint  *minutes);
60
62
 
61
63
 
62
64
/*  public functions  */
65
67
gimp_display_shell_close (GimpDisplayShell *shell,
66
68
                          gboolean          kill_it)
67
69
{
68
 
  GimpImage *gimage;
 
70
  GimpImage *image;
69
71
 
70
72
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
71
73
 
72
 
  gimage = shell->gdisp->gimage;
 
74
  image = shell->display->image;
73
75
 
74
76
  /*  FIXME: gimp_busy HACK not really appropriate here because we only
75
77
   *  want to prevent the busy image and display to be closed.  --Mitch
76
78
   */
77
 
  if (gimage->gimp->busy)
 
79
  if (image->gimp->busy)
78
80
    return;
79
81
 
80
82
  /*  If the image has been modified, give the user a chance to save
81
83
   *  it before nuking it--this only applies if its the last view
82
 
   *  to an image canvas.  (a gimage with disp_count = 1)
 
84
   *  to an image canvas.  (a image with disp_count = 1)
83
85
   */
84
 
  if (! kill_it               &&
85
 
      gimage->disp_count == 1 &&
86
 
      gimage->dirty           &&
87
 
      GIMP_DISPLAY_CONFIG (gimage->gimp->config)->confirm_on_close)
 
86
  if (! kill_it              &&
 
87
      image->disp_count == 1 &&
 
88
      image->dirty           &&
 
89
      GIMP_DISPLAY_CONFIG (image->gimp->config)->confirm_on_close)
88
90
    {
89
 
      gimp_display_shell_close_dialog (shell, gimage);
 
91
      gimp_display_shell_close_dialog (shell, image);
90
92
    }
91
93
  else
92
94
    {
93
 
      gimp_display_delete (shell->gdisp);
 
95
      gimp_display_delete (shell->display);
94
96
    }
95
97
}
96
98
 
102
104
 
103
105
static void
104
106
gimp_display_shell_close_dialog (GimpDisplayShell *shell,
105
 
                                 GimpImage        *gimage)
 
107
                                 GimpImage        *image)
106
108
{
107
109
  GtkWidget      *dialog;
 
110
  GtkWidget      *button;
108
111
  GimpMessageBox *box;
109
112
  GClosure       *closure;
110
113
  GSource        *source;
117
120
      return;
118
121
    }
119
122
 
120
 
  name = file_utils_uri_to_utf8_basename (gimp_image_get_uri (gimage));
 
123
  name = file_utils_uri_display_basename (gimp_image_get_uri (image));
121
124
 
122
125
  title = g_strdup_printf (_("Close %s"), name);
123
126
  g_free (name);
124
127
 
125
128
  shell->close_dialog =
126
 
    dialog = gimp_message_dialog_new (title, GIMP_STOCK_WARNING,
 
129
    dialog = gimp_message_dialog_new (title, GTK_STOCK_SAVE,
127
130
                                      GTK_WIDGET (shell),
128
131
                                      GTK_DIALOG_DESTROY_WITH_PARENT,
129
132
                                      gimp_standard_help_func, NULL,
130
 
 
131
 
                                      _("Do_n't save"), GTK_RESPONSE_CLOSE,
132
 
                                      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
133
 
                                      GTK_STOCK_SAVE,   RESPONSE_SAVE,
134
 
 
135
133
                                      NULL);
136
134
  g_free (title);
137
135
 
 
136
  button = gtk_dialog_add_button (GTK_DIALOG (dialog),
 
137
                                  _("Do_n't Save"), GTK_RESPONSE_CLOSE);
 
138
  gtk_button_set_image (GTK_BUTTON (button),
 
139
                        gtk_image_new_from_stock (GTK_STOCK_DELETE,
 
140
                                                  GTK_ICON_SIZE_BUTTON));
 
141
 
 
142
  gtk_dialog_add_buttons (GTK_DIALOG (dialog),
 
143
                          GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 
144
                          GTK_STOCK_SAVE,   RESPONSE_SAVE,
 
145
                          NULL);
 
146
 
138
147
  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
139
148
 
 
149
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
 
150
                                           RESPONSE_SAVE,
 
151
                                           GTK_RESPONSE_CLOSE,
 
152
                                           GTK_RESPONSE_CANCEL,
 
153
                                           -1);
 
154
 
140
155
  g_signal_connect (dialog, "destroy",
141
156
                    G_CALLBACK (gtk_widget_destroyed),
142
157
                    &shell->close_dialog);
147
162
 
148
163
  box = GIMP_MESSAGE_DIALOG (dialog)->box;
149
164
 
150
 
  g_signal_connect_object (gimage, "name_changed",
 
165
  g_signal_connect_object (image, "name-changed",
151
166
                           G_CALLBACK (gimp_display_shell_close_name_changed),
152
167
                           box, 0);
153
168
 
154
 
  gimp_display_shell_close_name_changed (gimage, box);
 
169
  gimp_display_shell_close_name_changed (image, box);
155
170
 
156
171
  closure =
157
172
    g_cclosure_new_object (G_CALLBACK (gimp_display_shell_close_time_changed),
158
173
                           G_OBJECT (box));
159
174
 
160
 
  source = g_timeout_source_new (1000);
 
175
  /*  update every 10 seconds  */
 
176
  source = g_timeout_source_new (10 * 1000);
161
177
  g_source_set_closure (source, closure);
162
178
  g_source_attach (source, NULL);
 
179
  g_source_unref (source);
163
180
 
164
181
  /*  The dialog is destroyed with the shell, so it should be safe
165
182
   *  to hold an image pointer for the lifetime of the dialog.
166
183
   */
167
 
  g_object_set_data (G_OBJECT (box), "gimp-image", gimage);
 
184
  g_object_set_data (G_OBJECT (box), "gimp-image", image);
168
185
 
169
186
  gimp_display_shell_close_time_changed (box);
170
187
 
178
195
  GtkWidget *window = gtk_widget_get_toplevel (GTK_WIDGET (box));
179
196
  gchar     *name;
180
197
 
181
 
  name = file_utils_uri_to_utf8_basename (gimp_image_get_uri (image));
 
198
  name = file_utils_uri_display_basename (gimp_image_get_uri (image));
182
199
 
183
200
  if (window)
184
201
    {
203
220
 
204
221
  if (image->dirty_time)
205
222
    {
206
 
      gchar *period = gimp_time_since (image->dirty_time);
207
 
 
208
 
      gimp_message_box_set_text (box,
209
 
                                 _("If you don't save the image, "
210
 
                                   "changes from the last %s will be lost."),
211
 
                                 period);
212
 
      g_free (period);
 
223
      gint hours   = 0;
 
224
      gint minutes = 0;
 
225
 
 
226
      gimp_time_since (image->dirty_time, &hours, &minutes);
 
227
 
 
228
      if (hours > 0)
 
229
        {
 
230
          if (hours > 1 || minutes == 0)
 
231
            gimp_message_box_set_text (box,
 
232
                                       ngettext ("If you don't save the image, "
 
233
                                                 "changes from the last hour "
 
234
                                                 "will be lost.",
 
235
                                                 "If you don't save the image, "
 
236
                                                 "changes from the last %d "
 
237
                                                 "hours will be lost.",
 
238
                                                 hours), hours);
 
239
 
 
240
          else
 
241
            gimp_message_box_set_text (box,
 
242
                                       ngettext ("If you don't save the image, "
 
243
                                                 "changes from the last hour "
 
244
                                                 "and %d minute will be lost.",
 
245
                                                 "If you don't save the image, "
 
246
                                                 "changes from the last hour "
 
247
                                                 "and %d minutes will be lost.",
 
248
                                                 minutes), minutes);
 
249
        }
 
250
      else
 
251
        {
 
252
          gimp_message_box_set_text (box,
 
253
                                     ngettext ("If you don't save the image, "
 
254
                                               "changes from the last minute "
 
255
                                               "will be lost.",
 
256
                                               "If you don't save the image, "
 
257
                                               "changes from the last %d "
 
258
                                               "minutes will be lost.",
 
259
                                               minutes), minutes);
 
260
        }
213
261
    }
214
262
  else
215
263
    {
229
277
  switch (response_id)
230
278
    {
231
279
    case GTK_RESPONSE_CLOSE:
232
 
      gimp_display_delete (shell->gdisp);
 
280
      gimp_display_delete (shell->display);
233
281
      break;
234
282
 
235
283
    case RESPONSE_SAVE:
236
 
      {
237
 
        GtkAction *action;
238
 
 
239
 
        action = gimp_ui_manager_find_action (shell->menubar_manager,
240
 
                                              "file", "file-save");
241
 
 
242
 
        g_return_if_fail (action != NULL);
243
 
 
244
 
        gtk_action_activate (action);
245
 
 
246
 
        if (! shell->gdisp->gimage->dirty)
247
 
          gimp_display_delete (shell->gdisp);
248
 
      }
 
284
      gimp_ui_manager_activate_action (shell->menubar_manager,
 
285
                                       "file", "file-save-and-close");
249
286
      break;
250
287
 
251
288
    default:
253
290
    }
254
291
}
255
292
 
256
 
static gchar *
257
 
gimp_time_since (guint  then)
 
293
static void
 
294
gimp_time_since (guint  then,
 
295
                 gint  *hours,
 
296
                 gint  *minutes)
258
297
{
259
 
  guint  now  = time (NULL);
260
 
  guint  diff = 1 + now - then;
261
 
 
262
 
  g_return_val_if_fail (now >= then, NULL);
263
 
 
264
 
  if (diff == 1)
265
 
    /* one second, the time period  */
266
 
    return g_strdup (_("second"));
267
 
 
268
 
  if (diff < 60)
269
 
    return g_strdup_printf (_("%d seconds"), diff);
270
 
 
271
 
  /*  round to the nearest minute  */
272
 
  diff = (diff + 30) / 60;
273
 
 
274
 
  if (diff == 1)
275
 
    return g_strdup (_("minute"));
276
 
 
277
 
  return g_strdup_printf (_("%d minutes"), diff);
 
298
  guint now  = time (NULL);
 
299
  guint diff = 1 + now - then;
 
300
 
 
301
  g_return_if_fail (now >= then);
 
302
 
 
303
  /*  first round up to the nearest minute  */
 
304
  diff = (diff + 59) / 60;
 
305
 
 
306
  /*  then optionally round minutes to multiples of 5 or 10  */
 
307
  if (diff > 50)
 
308
    diff = ((diff + 8) / 10) * 10;
 
309
  else if (diff > 20)
 
310
    diff = ((diff + 3) / 5) * 5;
 
311
 
 
312
  /*  determine full hours  */
 
313
  if (diff >= 60)
 
314
    {
 
315
      *hours = diff / 60;
 
316
      diff = (diff % 60);
 
317
    }
 
318
 
 
319
  /*  round up to full hours for 2 and more  */
 
320
  if (*hours > 1 && diff > 0)
 
321
    {
 
322
      *hours += 1;
 
323
      diff = 0;
 
324
    }
 
325
 
 
326
  *minutes = diff;
278
327
}