1 /* File management GUI for the text mode edition
3 * Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
4 * 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
6 * Written by: 1994, 1995 Janne Kukonlehto
7 * 1994, 1995 Fred Leeflang
8 * 1994, 1995, 1996 Miguel de Icaza
9 * 1995, 1996 Jakub Jelinek
10 * 1997 Norbert Warmuth
13 * The copy code was based in GNU's cp, and was written by:
14 * Torbjorn Granlund, David MacKenzie, and Jim Meyering.
16 * The move code was based in GNU's mv, and was written by:
17 * Mike Parker and David MacKenzie.
19 * Janne Kukonlehto added much error recovery to them for being used
20 * in an interactive program.
22 * This program is free software; you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation; either version 2 of the License, or
25 * (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
38 * Please note that all dialogs used here must be safe for background
43 /* {{{ Include files */
52 #include <sys/types.h>
57 #include "setup.h" /* verbose */
58 #include "dialog.h" /* do_refresh() */
59 #include "color.h" /* dialog_colors */
60 #include "widget.h" /* WLabel */
62 #include "main.h" /* the_hint */
63 #include "wtools.h" /* QuickDialog */
64 #include "panel.h" /* current_panel */
65 #include "fileopctx.h" /* FILE_CONT */
67 #include "key.h" /* get_event */
68 #include "util.h" /* strip_password() */
72 /* Hack: the vfs code should not rely on this */
73 #define WITH_FULL_PATHS 1
75 /* This structure describes the UI and internal data required by a file
85 /* Dialog and widgets for the operation progress window */
89 WLabel
*file_label
[2];
90 WLabel
*file_string
[2];
91 WLabel
*progress_label
[3];
92 WGauge
*progress_gauge
[3];
95 WLabel
*stalled_label
;
97 /* Query replace dialog */
99 Dlg_head
*replace_dlg
;
100 const char *replace_filename
;
102 struct stat
*s_stat
, *d_stat
;
106 /* Used to save the hint line */
107 static int last_hint_line
;
109 /* File operate window sizes */
113 #define WX_ETA_EXTRA 12
115 #define FCOPY_GAUGE_X 14
116 #define FCOPY_LABEL_X 5
118 /* Used for button result values */
120 REPLACE_YES
= B_USER
,
131 static FileProgressStatus
132 check_progress_buttons (FileOpContext
*ctx
)
143 event
.x
= -1; /* Don't show the GPM cursor */
144 c
= get_event (&event
, 0, 0);
148 /* Reinitialize to avoid old values after events other than
149 selecting a button */
150 ui
->op_dlg
->ret_value
= FILE_CONT
;
152 dlg_process_event (ui
->op_dlg
, c
, &event
);
153 switch (ui
->op_dlg
->ret_value
) {
166 /* {{{ File progress display routines */
169 file_op_context_create_ui (FileOpContext
*ctx
, int with_eta
)
178 g_return_if_fail (ctx
!= NULL
);
179 g_return_if_fail (ctx
->ui
== NULL
);
181 ui
= g_new0 (FileOpContextUI
, 1);
184 minus
= verbose
? 0 : 3;
185 eta_offset
= with_eta
? (WX_ETA_EXTRA
) / 2 : 0;
190 ctx
->recursive_result
= 0;
192 ui
->replace_result
= 0;
193 ui
->showing_eta
= with_eta
;
194 ui
->showing_bps
= with_eta
;
195 ui
->eta_extra
= with_eta
? WX_ETA_EXTRA
: 0;
196 x_size
= (WX
+ 4) + ui
->eta_extra
;
199 create_dlg (0, 0, WY
- minus
+ 4, x_size
, dialog_colors
, NULL
,
200 NULL
, op_names
[ctx
->operation
],
201 DLG_CENTER
| DLG_REVERSE
);
203 last_hint_line
= the_hint
->widget
.y
;
204 if ((ui
->op_dlg
->y
+ ui
->op_dlg
->lines
) > last_hint_line
)
205 the_hint
->widget
.y
= ui
->op_dlg
->y
+ ui
->op_dlg
->lines
+ 1;
207 add_widget (ui
->op_dlg
,
208 button_new (BY
- minus
, WX
- 19 + eta_offset
, FILE_ABORT
,
209 NORMAL_BUTTON
, _("&Abort"), 0));
210 add_widget (ui
->op_dlg
,
211 button_new (BY
- minus
, 14 + eta_offset
, FILE_SKIP
,
212 NORMAL_BUTTON
, _("&Skip"), 0));
214 add_widget (ui
->op_dlg
, ui
->progress_gauge
[2] =
215 gauge_new (7, FCOPY_GAUGE_X
, 0, 100, 0));
216 add_widget (ui
->op_dlg
, ui
->progress_label
[2] =
217 label_new (7, FCOPY_LABEL_X
, fifteen
));
218 add_widget (ui
->op_dlg
, ui
->bps_label
= label_new (7, WX
, ""));
220 add_widget (ui
->op_dlg
, ui
->progress_gauge
[1] =
221 gauge_new (8, FCOPY_GAUGE_X
, 0, 100, 0));
222 add_widget (ui
->op_dlg
, ui
->progress_label
[1] =
223 label_new (8, FCOPY_LABEL_X
, fifteen
));
224 add_widget (ui
->op_dlg
, ui
->stalled_label
= label_new (8, WX
, ""));
226 add_widget (ui
->op_dlg
, ui
->progress_gauge
[0] =
227 gauge_new (6, FCOPY_GAUGE_X
, 0, 100, 0));
228 add_widget (ui
->op_dlg
, ui
->progress_label
[0] =
229 label_new (6, FCOPY_LABEL_X
, fifteen
));
230 add_widget (ui
->op_dlg
, ui
->eta_label
= label_new (6, WX
, ""));
232 add_widget (ui
->op_dlg
, ui
->file_string
[1] =
233 label_new (4, FCOPY_GAUGE_X
, sixty
));
234 add_widget (ui
->op_dlg
, ui
->file_label
[1] =
235 label_new (4, FCOPY_LABEL_X
, fifteen
));
236 add_widget (ui
->op_dlg
, ui
->file_string
[0] =
237 label_new (3, FCOPY_GAUGE_X
, sixty
));
238 add_widget (ui
->op_dlg
, ui
->file_label
[0] =
239 label_new (3, FCOPY_LABEL_X
, fifteen
));
241 /* We will manage the dialog without any help, that's why
242 we have to call init_dlg */
243 init_dlg (ui
->op_dlg
);
244 ui
->op_dlg
->running
= 1;
248 file_op_context_destroy_ui (FileOpContext
*ctx
)
252 g_return_if_fail (ctx
!= NULL
);
257 dlg_run_done (ui
->op_dlg
);
258 destroy_dlg (ui
->op_dlg
);
262 the_hint
->widget
.y
= last_hint_line
;
267 static FileProgressStatus
268 show_no_bar (FileOpContext
*ctx
, int n
)
278 label_set_text (ui
->progress_label
[n
], "");
279 gauge_show (ui
->progress_gauge
[n
], 0);
281 return check_progress_buttons (ctx
);
284 static FileProgressStatus
285 show_bar (FileOpContext
*ctx
, int n
, double done
, double total
)
295 * Gauge needs integers, so give it with integers between 0 and 1023.
296 * This precision should be quite reasonable.
298 gauge_set_value (ui
->progress_gauge
[n
], 1024,
299 (int) (1024 * done
/ total
));
300 gauge_show (ui
->progress_gauge
[n
], 1);
301 return check_progress_buttons (ctx
);
305 file_eta_show (FileOpContext
*ctx
)
307 int eta_hours
, eta_mins
, eta_s
;
308 char eta_buffer
[BUF_TINY
];
316 if (!ui
->showing_eta
)
319 if (ctx
->eta_secs
> 0.5) {
320 eta_hours
= ctx
->eta_secs
/ (60 * 60);
321 eta_mins
= (ctx
->eta_secs
- (eta_hours
* 60 * 60)) / 60;
322 eta_s
= ctx
->eta_secs
- (eta_hours
* 60 * 60 + eta_mins
* 60);
323 g_snprintf (eta_buffer
, sizeof (eta_buffer
), _("ETA %d:%02d.%02d"),
324 eta_hours
, eta_mins
, eta_s
);
328 label_set_text (ui
->eta_label
, eta_buffer
);
332 file_bps_show (FileOpContext
*ctx
)
334 char bps_buffer
[BUF_TINY
];
342 if (!ui
->showing_bps
)
345 if (ctx
->bps
> 1024 * 1024) {
346 g_snprintf (bps_buffer
, sizeof (bps_buffer
), _("%.2f MB/s"),
347 ctx
->bps
/ (1024 * 1024.0));
348 } else if (ctx
->bps
> 1024) {
349 g_snprintf (bps_buffer
, sizeof (bps_buffer
), _("%.2f KB/s"),
351 } else if (ctx
->bps
> 1) {
352 g_snprintf (bps_buffer
, sizeof (bps_buffer
), _("%ld B/s"),
357 label_set_text (ui
->bps_label
, bps_buffer
);
361 file_progress_show (FileOpContext
*ctx
, off_t done
, off_t total
)
365 g_return_val_if_fail (ctx
!= NULL
, FILE_CONT
);
373 return check_progress_buttons (ctx
);
375 label_set_text (ui
->progress_label
[0], _("File"));
378 return show_bar (ctx
, 0, done
, total
);
380 return show_no_bar (ctx
, 0);
384 file_progress_show_count (FileOpContext
*ctx
, off_t done
, off_t total
)
388 g_return_val_if_fail (ctx
!= NULL
, FILE_CONT
);
396 return check_progress_buttons (ctx
);
398 label_set_text (ui
->progress_label
[1], _("Count"));
399 return show_bar (ctx
, 1, done
, total
);
401 return show_no_bar (ctx
, 1);
405 file_progress_show_bytes (FileOpContext
*ctx
, double done
, double total
)
409 g_return_val_if_fail (ctx
!= NULL
, FILE_CONT
);
417 return check_progress_buttons (ctx
);
419 label_set_text (ui
->progress_label
[2], _("Bytes"));
420 return show_bar (ctx
, 2, done
, total
);
422 return show_no_bar (ctx
, 2);
427 #define truncFileString(ui, s) name_trunc (s, ui->eta_extra + 47)
428 #define truncFileStringSecure(ui, s) path_trunc (s, ui->eta_extra + 47)
431 file_progress_show_source (FileOpContext
*ctx
, const char *s
)
435 g_return_val_if_fail (ctx
!= NULL
, FILE_CONT
);
443 #ifdef WITH_FULL_PATHS
444 int i
= strlen (current_panel
->cwd
);
446 /* We remove the full path we have added before */
447 if (!strncmp (s
, current_panel
->cwd
, i
)) {
448 if (s
[i
] == PATH_SEP
)
451 #endif /* WITH_FULL_PATHS */
453 label_set_text (ui
->file_label
[0], _("Source"));
454 label_set_text (ui
->file_string
[0], truncFileString (ui
, s
));
455 return check_progress_buttons (ctx
);
457 label_set_text (ui
->file_label
[0], "");
458 label_set_text (ui
->file_string
[0], "");
459 return check_progress_buttons (ctx
);
464 file_progress_show_target (FileOpContext
*ctx
, const char *s
)
468 g_return_val_if_fail (ctx
!= NULL
, FILE_CONT
);
476 label_set_text (ui
->file_label
[1], _("Target"));
477 label_set_text (ui
->file_string
[1], truncFileStringSecure (ui
, s
));
478 return check_progress_buttons (ctx
);
480 label_set_text (ui
->file_label
[1], "");
481 label_set_text (ui
->file_string
[1], "");
482 return check_progress_buttons (ctx
);
487 file_progress_show_deleting (FileOpContext
*ctx
, const char *s
)
491 g_return_val_if_fail (ctx
!= NULL
, FILE_CONT
);
498 label_set_text (ui
->file_label
[0], _("Deleting"));
499 label_set_text (ui
->file_label
[0], truncFileStringSecure (ui
, s
));
500 return check_progress_buttons (ctx
);
506 * FIXME: probably it is better to replace this with quick dialog machinery,
507 * but actually I'm not familiar with it and have not much time :(
513 int value
; /* 0 for labels */
516 N_("Target file \"%s\" already exists!"), 3, 4, 0}, {
517 N_("&Abort"), BY
+ 3, 25, REPLACE_ABORT
}, {
518 N_("If &size differs"), BY
+ 1, 28, REPLACE_SIZE
}, {
519 N_("Non&e"), BY
, 47, REPLACE_NEVER
}, {
520 N_("&Update"), BY
, 36, REPLACE_UPDATE
}, {
521 N_("A&ll"), BY
, 28, REPLACE_ALWAYS
}, {
522 N_("Overwrite all targets?"), BY
, 4, 0}, {
523 N_("&Reget"), BY
- 1, 28, REPLACE_REGET
}, {
524 N_("A&ppend"), BY
- 2, 45, REPLACE_APPEND
}, {
525 N_("&No"), BY
- 2, 37, REPLACE_NO
}, {
526 N_("&Yes"), BY
- 2, 28, REPLACE_YES
}, {
527 N_("Overwrite this target?"), BY
- 2, 4, 0}, {
528 #if (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) || (defined _LARGE_FILES && _LARGE_FILES)
529 N_("Target date: %s, size %llu"), 6, 4, 0}, {
530 N_("Source date: %s, size %llu"), 5, 4, 0}
532 N_("Target date: %s, size %u"), 6, 4, 0}, {
533 N_("Source date: %s, size %u"), 5, 4, 0}
537 #define ADD_RD_BUTTON(i)\
538 add_widget (ui->replace_dlg,\
539 button_new (rd_widgets [i].ypos, rd_widgets [i].xpos, rd_widgets [i].value,\
540 NORMAL_BUTTON, rd_widgets [i].text, 0))
542 #define ADD_RD_LABEL(ui,i,p1,p2)\
543 g_snprintf (buffer, sizeof (buffer), rd_widgets [i].text, p1, p2);\
544 add_widget (ui->replace_dlg,\
545 label_new (rd_widgets [i].ypos, rd_widgets [i].xpos, buffer))
548 init_replace (FileOpContext
*ctx
, enum OperationMode mode
)
551 char buffer
[BUF_SMALL
];
553 static int rd_xlen
= 60, rd_trunc
= X_TRUNC
;
556 static int i18n_flag
;
559 register int i
= sizeof (rd_widgets
) / sizeof (rd_widgets
[0]);
561 rd_widgets
[i
].text
= _(rd_widgets
[i
].text
);
564 * longest of "Overwrite..." labels
565 * (assume "Target date..." are short enough)
567 l1
= max (strlen (rd_widgets
[6].text
),
568 strlen (rd_widgets
[11].text
));
570 /* longest of button rows */
571 i
= sizeof (rd_widgets
) / sizeof (rd_widgets
[0]);
572 for (row
= l
= l2
= 0; i
--;) {
573 if (rd_widgets
[i
].value
!= 0) {
574 if (row
!= rd_widgets
[i
].ypos
) {
575 row
= rd_widgets
[i
].ypos
;
579 l
+= strlen (rd_widgets
[i
].text
) + 4;
582 l2
= max (l2
, l
); /* last row */
583 rd_xlen
= max (rd_xlen
, l1
+ l2
+ 8);
584 rd_trunc
= rd_xlen
- 6;
586 /* Now place buttons */
587 l1
+= 5; /* start of first button in the row */
588 i
= sizeof (rd_widgets
) / sizeof (rd_widgets
[0]);
590 for (l
= l1
, row
= 0; --i
> 1;) {
591 if (rd_widgets
[i
].value
!= 0) {
592 if (row
!= rd_widgets
[i
].ypos
) {
593 row
= rd_widgets
[i
].ypos
;
596 rd_widgets
[i
].xpos
= l
;
597 l
+= strlen (rd_widgets
[i
].text
) + 4;
600 /* Abort button is centered */
602 (rd_xlen
- strlen (rd_widgets
[1].text
) - 3) / 2;
604 #endif /* ENABLE_NLS */
608 if (mode
== Foreground
)
609 title
= _(" File exists ");
611 title
= _(" Background process: File exists ");
613 /* FIXME - missing help node */
615 create_dlg (0, 0, 16, rd_xlen
, alarm_colors
, NULL
, "[Replace]",
616 title
, DLG_CENTER
| DLG_REVERSE
);
620 name_trunc (ui
->replace_filename
,
621 rd_trunc
- strlen (rd_widgets
[0].text
)), 0);
628 ADD_RD_LABEL (ui
, 6, 0, 0);
630 /* "this target..." widgets */
631 if (!S_ISDIR (ui
->d_stat
->st_mode
)) {
632 if ((ctx
->operation
== OP_COPY
) && (ui
->d_stat
->st_size
!= 0)
633 && (ui
->s_stat
->st_size
> ui
->d_stat
->st_size
))
634 ADD_RD_BUTTON (7); /* reget */
636 ADD_RD_BUTTON (8); /* Overwrite all targets? */
640 ADD_RD_LABEL (ui
, 11, 0, 0);
642 ADD_RD_LABEL (ui
, 12, file_date (ui
->d_stat
->st_mtime
),
643 (off_t
) ui
->d_stat
->st_size
);
644 ADD_RD_LABEL (ui
, 13, file_date (ui
->s_stat
->st_mtime
),
645 (off_t
) ui
->s_stat
->st_size
);
649 file_progress_set_stalled_label (FileOpContext
*ctx
, const char *stalled_msg
)
653 g_return_if_fail (ctx
!= NULL
);
660 label_set_text (ui
->stalled_label
, stalled_msg
);
664 file_progress_real_query_replace (FileOpContext
*ctx
,
665 enum OperationMode mode
, const char *destname
,
666 struct stat
*_s_stat
,
667 struct stat
*_d_stat
)
671 g_return_val_if_fail (ctx
!= NULL
, FILE_CONT
);
672 g_return_val_if_fail (ctx
->ui
!= NULL
, FILE_CONT
);
676 if (ui
->replace_result
< REPLACE_ALWAYS
) {
677 ui
->replace_filename
= destname
;
678 ui
->s_stat
= _s_stat
;
679 ui
->d_stat
= _d_stat
;
680 init_replace (ctx
, mode
);
681 run_dlg (ui
->replace_dlg
);
682 ui
->replace_result
= ui
->replace_dlg
->ret_value
;
683 if (ui
->replace_result
== B_CANCEL
)
684 ui
->replace_result
= REPLACE_ABORT
;
685 destroy_dlg (ui
->replace_dlg
);
688 switch (ui
->replace_result
) {
691 if (_s_stat
->st_mtime
> _d_stat
->st_mtime
)
698 if (_s_stat
->st_size
== _d_stat
->st_size
)
704 /* Careful: we fall through and set do_append */
705 ctx
->do_reget
= _d_stat
->st_size
;
727 static QuickWidget fmd_widgets
[] = {
732 /* follow symlinks and preserve Attributes must be the first */
733 {quick_checkbox
, 3, 64, 8, FMDY
, N_("preserve &Attributes"), 9, 0,
734 0 /* &op_preserve */ , 0, NULL
},
735 {quick_checkbox
, 3, 64, 7, FMDY
, N_("follow &Links"), 7, 0,
736 0 /* &file_mask_op_follow_links */ , 0, NULL
},
737 {quick_label
, 3, 64, 5, FMDY
, N_("to:"), 0, 0, 0, 0, NULL
},
738 {quick_checkbox
, 37, 64, 4, FMDY
, N_("&Using shell patterns"), 0, 0,
739 0 /* &source_easy_patterns */ , 0, NULL
},
740 {quick_input
, 3, 64, 3, FMDY
, "", 58,
741 0, 0, 0, "input-def"},
745 {quick_input
, 3, 64, 6, FMDY
, "", 58, 0,
748 {quick_label
, 3, 64, 2, FMDY
, "", 0, 0, 0, 0, NULL
},
750 {quick_button
, 42, 64, 9, FMDY
, N_("&Cancel"), 0, B_CANCEL
, 0, 0,
753 #ifdef WITH_BACKGROUND
759 {quick_button
, 25, 64, 9, FMDY
, N_("&Background"), 0, B_USER
, 0, 0,
761 #else /* WITH_BACKGROUND */
768 {quick_button
, 14, 64, 9, FMDY
, N_("&OK"), 0, B_ENTER
, 0, 0, NULL
},
769 {quick_checkbox
, 42, 64, 8, FMDY
, N_("&Stable Symlinks"), 0, 0,
770 0 /* &file_mask_stable_symlinks */ , 0, NULL
},
771 {quick_checkbox
, 31, 64, 7, FMDY
, N_("&Dive into subdir if exists"), 0,
773 0 /* &dive_into_subdirs */ , 0, NULL
},
778 is_wildcarded (char *p
)
783 else if (*p
== '\\' && p
[1] >= '1' && p
[1] <= '9')
790 fmd_init_i18n (int force
)
793 static int initialized
= FALSE
;
797 if (initialized
&& !force
)
800 for (i
= sizeof (op_names
) / sizeof (op_names
[0]); i
--;)
801 op_names
[i
] = _(op_names
[i
]);
803 i
= sizeof (fmd_widgets
) / sizeof (fmd_widgets
[0]) - 1;
805 if (fmd_widgets
[i
].text
[0] != '\0')
806 fmd_widgets
[i
].text
= _(fmd_widgets
[i
].text
);
808 len
= strlen (fmd_widgets
[FMCB11
].text
)
809 + strlen (fmd_widgets
[FMCB21
].text
) + 15;
810 fmd_xlen
= max (fmd_xlen
, len
);
812 len
= strlen (fmd_widgets
[FMCB12
].text
)
813 + strlen (fmd_widgets
[FMCB22
].text
) + 15;
814 fmd_xlen
= max (fmd_xlen
, len
);
816 len
= strlen (fmd_widgets
[FMBRGT
].text
)
817 + strlen (fmd_widgets
[FMBLFT
].text
) + 11;
820 len
+= strlen (fmd_widgets
[FMBMID
].text
) + 6;
823 fmd_xlen
= max (fmd_xlen
, len
+ 4);
825 len
= (fmd_xlen
- (len
+ 6)) / 2;
826 i
= fmd_widgets
[FMBLFT
].relative_x
= len
+ 3;
827 i
+= strlen (fmd_widgets
[FMBLFT
].text
) + 8;
830 fmd_widgets
[FMBMID
].relative_x
= i
;
831 i
+= strlen (fmd_widgets
[FMBMID
].text
) + 6;
834 fmd_widgets
[FMBRGT
].relative_x
= i
;
836 #define chkbox_xpos(i) \
837 fmd_widgets [i].relative_x = fmd_xlen - strlen (fmd_widgets [i].text) - 6
840 chkbox_xpos (FMCB21
);
841 chkbox_xpos (FMCB22
);
843 if (fmd_xlen
!= FMD_XLEN
) {
844 i
= sizeof (fmd_widgets
) / sizeof (fmd_widgets
[0]) - 1;
846 fmd_widgets
[i
].x_divisions
= fmd_xlen
;
848 fmd_widgets
[FMDI1
].hotkey_pos
=
849 fmd_widgets
[FMDI2
].hotkey_pos
= fmd_xlen
- 6;
854 #endif /* !ENABLE_NLS */
858 file_mask_dialog (FileOpContext
*ctx
, FileOperation operation
, const char *text
,
859 const char *def_text
, int only_one
, int *do_background
)
861 int source_easy_patterns
= easy_patterns
;
862 char *source_mask
, *orig_mask
, *dest_dir
, *tmpdest
;
864 char *def_text_secure
;
867 QuickDialog Quick_input
;
869 g_return_val_if_fail (ctx
!= NULL
, NULL
);
871 message (1, __FUNCTION__
, "text = `%s' \n def_text = `%s'", text
,
874 fmd_init_i18n (FALSE
);
876 /* Set up the result pointers */
878 fmd_widgets
[FMCB12
].result
= &ctx
->op_preserve
;
879 fmd_widgets
[FMCB11
].result
= &ctx
->follow_links
;
880 fmd_widgets
[FMCB22
].result
= &ctx
->stable_symlinks
;
881 fmd_widgets
[FMCB21
].result
= &ctx
->dive_into_subdirs
;
883 /* filter out a possible password from def_text */
884 def_text_secure
= strip_password (g_strdup (def_text
), 1);
886 /* Create the dialog */
888 ctx
->stable_symlinks
= 0;
889 fmd_widgets
[FMDC
].result
= &source_easy_patterns
;
890 fmd_widgets
[FMDI1
].text
= easy_patterns
? "*" : "^\\(.*\\)$";
891 Quick_input
.xlen
= fmd_xlen
;
892 Quick_input
.xpos
= -1;
893 Quick_input
.title
= op_names
[operation
];
894 Quick_input
.help
= "[Mask Copy/Rename]";
895 Quick_input
.ylen
= FMDY
;
896 Quick_input
.i18n
= 1;
897 Quick_input
.widgets
= fmd_widgets
;
898 fmd_widgets
[FMDI0
].text
= text
;
899 fmd_widgets
[FMDI2
].text
= def_text_secure
;
900 fmd_widgets
[FMDI2
].str_result
= &dest_dir
;
901 fmd_widgets
[FMDI1
].str_result
= &source_mask
;
906 if ((val
= quick_dialog_skip (&Quick_input
, SKIP
)) == B_CANCEL
) {
907 g_free (def_text_secure
);
910 g_free (def_text_secure
);
912 if (ctx
->follow_links
)
913 ctx
->stat_func
= mc_stat
;
915 ctx
->stat_func
= mc_lstat
;
917 if (ctx
->op_preserve
) {
919 ctx
->umask_kill
= 0777777;
920 ctx
->preserve_uidgid
= (geteuid () == 0) ? 1 : 0;
923 ctx
->preserve
= ctx
->preserve_uidgid
= 0;
926 ctx
->umask_kill
= i
^ 0777777;
929 orig_mask
= source_mask
;
930 if (!dest_dir
|| !*dest_dir
) {
931 g_free (source_mask
);
934 if (source_easy_patterns
) {
935 source_easy_patterns
= easy_patterns
;
937 source_mask
= convert_pattern (source_mask
, match_file
, 1);
938 easy_patterns
= source_easy_patterns
;
940 re_compile_pattern (source_mask
, strlen (source_mask
),
942 g_free (source_mask
);
945 re_compile_pattern (source_mask
, strlen (source_mask
),
949 message (1, MSG_ERROR
, _("Invalid source pattern `%s' \n %s "),
957 dest_dir
= tilde_expand(tmpdest
);
960 ctx
->dest_mask
= strrchr (dest_dir
, PATH_SEP
);
961 if (ctx
->dest_mask
== NULL
)
962 ctx
->dest_mask
= dest_dir
;
965 orig_mask
= ctx
->dest_mask
;
967 || (!ctx
->dive_into_subdirs
&& !is_wildcarded (ctx
->dest_mask
)
969 || (!mc_stat (dest_dir
, &buf
) && S_ISDIR (buf
.st_mode
))))
970 || (ctx
->dive_into_subdirs
971 && ((!only_one
&& !is_wildcarded (ctx
->dest_mask
))
972 || (only_one
&& !mc_stat (dest_dir
, &buf
)
973 && S_ISDIR (buf
.st_mode
)))))
974 ctx
->dest_mask
= g_strdup ("*");
976 ctx
->dest_mask
= g_strdup (ctx
->dest_mask
);
981 dest_dir
= g_strdup ("./");