33
33
#include "core/gimpimage.h"
34
34
#include "core/gimpprogress.h"
36
#include "config/gimpcoreconfig.h"
37
36
#include "config/gimpguiconfig.h"
39
38
#include "file/file-utils.h"
41
#include "plug-in/plug-in-proc-def.h"
42
#include "plug-in/plug-ins.h"
40
#include "pdb/gimppdb.h"
42
#include "plug-in/gimppluginmanager.h"
43
#include "plug-in/gimppluginprocedure.h"
44
45
#include "gimpfiledialog.h"
45
46
#include "gimpfileprocview.h"
46
47
#include "gimphelp-ids.h"
48
#include "gimpprogressbox.h"
47
49
#include "gimpview.h"
48
50
#include "gimpviewrendererimagefile.h"
49
51
#include "gimpthumbbox.h"
98
101
static gchar * gimp_file_dialog_pattern_from_extension (const gchar *extension);
102
gimp_file_dialog_get_type (void)
104
static GType dialog_type = 0;
108
static const GTypeInfo dialog_info =
110
sizeof (GimpFileDialogClass),
111
(GBaseInitFunc) NULL,
112
(GBaseFinalizeFunc) NULL,
113
(GClassInitFunc) gimp_file_dialog_class_init,
114
NULL, /* class_finalize */
115
NULL, /* class_data */
116
sizeof (GimpFileDialog),
118
NULL, /* instance_init */
121
static const GInterfaceInfo progress_iface_info =
123
(GInterfaceInitFunc) gimp_file_dialog_progress_iface_init,
124
NULL, /* iface_finalize */
125
NULL /* iface_data */
128
dialog_type = g_type_register_static (GTK_TYPE_FILE_CHOOSER_DIALOG,
132
g_type_add_interface_static (dialog_type, GIMP_TYPE_PROGRESS,
133
&progress_iface_info);
104
G_DEFINE_TYPE_WITH_CODE (GimpFileDialog, gimp_file_dialog,
105
GTK_TYPE_FILE_CHOOSER_DIALOG,
106
G_IMPLEMENT_INTERFACE (GIMP_TYPE_PROGRESS,
107
gimp_file_dialog_progress_iface_init))
109
#define parent_class gimp_file_dialog_parent_class
140
113
gimp_file_dialog_class_init (GimpFileDialogClass *klass)
151
gimp_file_dialog_progress_iface_init (GimpProgressInterface *progress_iface)
153
progress_iface->start = gimp_file_dialog_progress_start;
154
progress_iface->end = gimp_file_dialog_progress_end;
155
progress_iface->is_active = gimp_file_dialog_progress_is_active;
156
progress_iface->set_text = gimp_file_dialog_progress_set_text;
157
progress_iface->set_value = gimp_file_dialog_progress_set_value;
158
progress_iface->get_value = gimp_file_dialog_progress_get_value;
124
gimp_file_dialog_init (GimpFileDialog *dialog)
129
gimp_file_dialog_progress_iface_init (GimpProgressInterface *iface)
131
iface->start = gimp_file_dialog_progress_start;
132
iface->end = gimp_file_dialog_progress_end;
133
iface->is_active = gimp_file_dialog_progress_is_active;
134
iface->set_text = gimp_file_dialog_progress_set_text;
135
iface->set_value = gimp_file_dialog_progress_set_value;
136
iface->get_value = gimp_file_dialog_progress_get_value;
137
iface->pulse = gimp_file_dialog_progress_pulse;
138
iface->get_window = gimp_file_dialog_progress_get_window;
186
169
gboolean cancelable)
188
171
GimpFileDialog *dialog = GIMP_FILE_DIALOG (progress);
190
if (! dialog->progress_active)
192
GtkProgressBar *bar = GTK_PROGRESS_BAR (dialog->progress);
194
gtk_progress_bar_set_text (bar, message);
195
gtk_progress_bar_set_fraction (bar, 0.0);
197
gtk_widget_show (dialog->progress);
199
dialog->progress_active = TRUE;
200
dialog->progress_cancelable = cancelable;
172
GimpProgress *retval;
174
retval = gimp_progress_start (GIMP_PROGRESS (dialog->progress),
175
message, cancelable);
176
gtk_widget_show (dialog->progress);
211
184
GimpFileDialog *dialog = GIMP_FILE_DIALOG (progress);
213
if (dialog->progress_active)
215
GtkProgressBar *bar = GTK_PROGRESS_BAR (dialog->progress);
217
gtk_progress_bar_set_text (bar, "");
218
gtk_progress_bar_set_fraction (bar, 0.0);
220
gtk_widget_hide (dialog->progress);
222
dialog->progress_active = FALSE;
223
dialog->progress_cancelable = FALSE;
186
gimp_progress_end (GIMP_PROGRESS (dialog->progress));
187
gtk_widget_hide (dialog->progress);
266
219
GimpFileDialog *dialog = GIMP_FILE_DIALOG (progress);
268
if (dialog->progress_active)
270
GtkProgressBar *bar = GTK_PROGRESS_BAR (dialog->progress);
272
return gtk_progress_bar_get_fraction (bar);
221
return gimp_progress_get_value (GIMP_PROGRESS (dialog->progress));
225
gimp_file_dialog_progress_pulse (GimpProgress *progress)
227
GimpFileDialog *dialog = GIMP_FILE_DIALOG (progress);
229
gimp_progress_pulse (GIMP_PROGRESS (dialog->progress));
233
gimp_file_dialog_progress_get_window (GimpProgress *progress)
235
GimpFileDialog *dialog = GIMP_FILE_DIALOG (progress);
237
return (guint32) gimp_window_get_native (GTK_WINDOW (dialog));
302
265
case GTK_FILE_CHOOSER_ACTION_OPEN:
303
file_procs = gimp->load_procs;
266
file_procs = gimp->plug_in_manager->load_procs;
304
267
automatic = _("Automatically Detected");
305
268
automatic_help_id = GIMP_HELP_FILE_OPEN_BY_EXTENSION;
271
local_only = (gimp_pdb_lookup_procedure (gimp->pdb,
272
"file-uri-load") == NULL);
308
275
case GTK_FILE_CHOOSER_ACTION_SAVE:
309
file_procs = gimp->save_procs;
276
file_procs = gimp->plug_in_manager->save_procs;
310
277
automatic = _("By Extension");
311
278
automatic_help_id = GIMP_HELP_FILE_SAVE_BY_EXTENSION;
281
local_only = (gimp_pdb_lookup_procedure (gimp->pdb,
282
"file-uri-save") == NULL);
369
348
gimp_file_dialog_set_sensitive (GimpFileDialog *dialog,
370
349
gboolean sensitive)
372
354
g_return_if_fail (GIMP_IS_FILE_DIALOG (dialog));
374
gimp_dialog_set_sensitive (GTK_DIALOG (dialog), sensitive);
357
gtk_container_get_children (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox));
359
for (list = children; list; list = g_list_next (list))
361
/* skip the last item (the action area) */
362
if (! g_list_next (list))
365
gtk_widget_set_sensitive (list->data, sensitive);
368
g_list_free (children);
371
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
372
GTK_RESPONSE_CANCEL, sensitive);
374
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
375
GTK_RESPONSE_OK, sensitive);
376
377
dialog->busy = ! sensitive;
377
378
dialog->canceled = FALSE;
381
gimp_file_dialog_set_file_proc (GimpFileDialog *dialog,
382
PlugInProcDef *file_proc)
382
gimp_file_dialog_set_file_proc (GimpFileDialog *dialog,
383
GimpPlugInProcedure *file_proc)
384
385
g_return_if_fail (GIMP_IS_FILE_DIALOG (dialog));
392
393
gimp_file_dialog_set_image (GimpFileDialog *dialog,
394
gboolean save_a_copy)
395
gboolean save_a_copy,
396
gboolean close_after_saving)
396
398
const gchar *uri = NULL;
400
402
g_return_if_fail (GIMP_IS_FILE_DIALOG (dialog));
401
g_return_if_fail (GIMP_IS_IMAGE (gimage));
403
g_return_if_fail (GIMP_IS_IMAGE (image));
403
dialog->gimage = gimage;
404
dialog->save_a_copy = save_a_copy;
405
dialog->image = image;
406
dialog->save_a_copy = save_a_copy;
407
dialog->close_after_saving = close_after_saving;
407
uri = g_object_get_data (G_OBJECT (gimage), "gimp-image-save-a-copy");
410
uri = g_object_get_data (G_OBJECT (image), "gimp-image-save-a-copy");
410
uri = gimp_image_get_uri (gimage);
413
uri = gimp_image_get_uri (image);
412
415
gimp_file_dialog_set_file_proc (dialog, NULL);
414
418
dirname = g_path_get_dirname (uri);
415
basename = file_utils_uri_to_utf8_basename (uri);
420
/* g_path_get_dirname() is supposed to work on pathnames, not URIs.
422
* If uri points to a file on the root of a drive
423
* "file:///d:/foo.png", g_path_get_dirname() would return
424
* "file:///d:". (What we really would want is "file:///d:/".) When
425
* this then is passed inside gtk+ to g_filename_from_uri() we get
426
* "d:" which is not an absolute pathname. This currently causes an
427
* assertion failure in gtk+. This scenario occurs if we have opened
428
* an image from the root of a drive and then do Save As.
430
* Of course, gtk+ shouldn't assert even if we feed it slighly bogus
431
* data, and that problem should be fixed, too. But to get the
432
* correct default current folder in the filechooser combo box, we
433
* need to pass it the proper URI for an absolute path anyway. So
434
* don't use g_path_get_dirname() on file: URIs.
436
if (g_str_has_prefix (uri, "file:///"))
438
gchar *filepath = g_filename_from_uri (uri, NULL, NULL);
439
gchar *dirpath = NULL;
441
if (filepath != NULL)
443
dirpath = g_path_get_dirname (filepath);
449
dirname = g_filename_to_uri (dirpath, NULL, NULL);
459
dirname = g_path_get_dirname (uri);
463
basename = file_utils_uri_display_basename (uri);
417
465
if (dirname && strlen (dirname) && strcmp (dirname, "."))
418
gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dialog),
467
gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dialog),
470
else if (g_object_get_data (G_OBJECT (image), "gimp-image-dirname"))
472
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog),
473
g_object_get_data (G_OBJECT (image),
474
"gimp-image-dirname"));
421
478
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), basename);
460
517
GSList *file_procs)
462
GtkFileFilter *filter;
465
filter = gtk_file_filter_new ();
466
gtk_file_filter_set_name (filter, _("All Files"));
467
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
468
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
469
gtk_file_filter_add_pattern (filter, "*");
522
all = gtk_file_filter_new ();
523
gtk_file_filter_set_name (all, _("All files"));
524
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), all);
525
gtk_file_filter_add_pattern (all, "*");
527
all = gtk_file_filter_new ();
528
gtk_file_filter_set_name (all, _("All images"));
529
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), all);
471
531
for (list = file_procs; list; list = g_slist_next (list))
473
PlugInProcDef *file_proc = list->data;
533
GimpPlugInProcedure *file_proc = list->data;
475
535
if (file_proc->extensions_list)
483
domain = plug_ins_locale_domain (gimp, file_proc->prog, NULL);
485
label = plug_in_proc_def_get_label (file_proc, domain);
487
str = g_string_new (label);
490
filter = gtk_file_filter_new ();
537
GtkFileFilter *filter = gtk_file_filter_new ();
542
str = g_string_new (gimp_plug_in_procedure_get_label (file_proc));
492
544
/* an arbitrary limit to keep the file dialog from becoming too wide */
493
545
#define MAX_EXTENSIONS 4