1
/* The GIMP -- an image manipulation program
1
/* GIMP - The GNU Image Manipulation Program
2
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
4
* This program is free software; you can redistribute it and/or modify
48
48
/* local function prototypes */
50
50
static void gimp_display_shell_close_dialog (GimpDisplayShell *shell,
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);
65
67
gimp_display_shell_close (GimpDisplayShell *shell,
70
72
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
72
gimage = shell->gdisp->gimage;
74
image = shell->display->image;
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
77
if (gimage->gimp->busy)
79
if (image->gimp->busy)
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)
85
gimage->disp_count == 1 &&
87
GIMP_DISPLAY_CONFIG (gimage->gimp->config)->confirm_on_close)
87
image->disp_count == 1 &&
89
GIMP_DISPLAY_CONFIG (image->gimp->config)->confirm_on_close)
89
gimp_display_shell_close_dialog (shell, gimage);
91
gimp_display_shell_close_dialog (shell, image);
93
gimp_display_delete (shell->gdisp);
95
gimp_display_delete (shell->display);
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));
122
125
title = g_strdup_printf (_("Close %s"), name);
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,
131
_("Do_n't save"), GTK_RESPONSE_CLOSE,
132
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
133
GTK_STOCK_SAVE, RESPONSE_SAVE,
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));
142
gtk_dialog_add_buttons (GTK_DIALOG (dialog),
143
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
144
GTK_STOCK_SAVE, RESPONSE_SAVE,
138
147
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
149
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
140
155
g_signal_connect (dialog, "destroy",
141
156
G_CALLBACK (gtk_widget_destroyed),
142
157
&shell->close_dialog);
148
163
box = GIMP_MESSAGE_DIALOG (dialog)->box;
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),
154
gimp_display_shell_close_name_changed (gimage, box);
169
gimp_display_shell_close_name_changed (image, box);
157
172
g_cclosure_new_object (G_CALLBACK (gimp_display_shell_close_time_changed),
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);
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.
167
g_object_set_data (G_OBJECT (box), "gimp-image", gimage);
184
g_object_set_data (G_OBJECT (box), "gimp-image", image);
169
186
gimp_display_shell_close_time_changed (box);
204
221
if (image->dirty_time)
206
gchar *period = gimp_time_since (image->dirty_time);
208
gimp_message_box_set_text (box,
209
_("If you don't save the image, "
210
"changes from the last %s will be lost."),
226
gimp_time_since (image->dirty_time, &hours, &minutes);
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 "
235
"If you don't save the image, "
236
"changes from the last %d "
237
"hours will be lost.",
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.",
252
gimp_message_box_set_text (box,
253
ngettext ("If you don't save the image, "
254
"changes from the last minute "
256
"If you don't save the image, "
257
"changes from the last %d "
258
"minutes will be lost.",
229
277
switch (response_id)
231
279
case GTK_RESPONSE_CLOSE:
232
gimp_display_delete (shell->gdisp);
280
gimp_display_delete (shell->display);
235
283
case RESPONSE_SAVE:
239
action = gimp_ui_manager_find_action (shell->menubar_manager,
240
"file", "file-save");
242
g_return_if_fail (action != NULL);
244
gtk_action_activate (action);
246
if (! shell->gdisp->gimage->dirty)
247
gimp_display_delete (shell->gdisp);
284
gimp_ui_manager_activate_action (shell->menubar_manager,
285
"file", "file-save-and-close");
257
gimp_time_since (guint then)
294
gimp_time_since (guint then,
259
guint now = time (NULL);
260
guint diff = 1 + now - then;
262
g_return_val_if_fail (now >= then, NULL);
265
/* one second, the time period */
266
return g_strdup (_("second"));
269
return g_strdup_printf (_("%d seconds"), diff);
271
/* round to the nearest minute */
272
diff = (diff + 30) / 60;
275
return g_strdup (_("minute"));
277
return g_strdup_printf (_("%d minutes"), diff);
298
guint now = time (NULL);
299
guint diff = 1 + now - then;
301
g_return_if_fail (now >= then);
303
/* first round up to the nearest minute */
304
diff = (diff + 59) / 60;
306
/* then optionally round minutes to multiples of 5 or 10 */
308
diff = ((diff + 8) / 10) * 10;
310
diff = ((diff + 3) / 5) * 5;
312
/* determine full hours */
319
/* round up to full hours for 2 and more */
320
if (*hours > 1 && diff > 0)