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, 2009 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
14 * The copy code was based in GNU's cp, and was written by:
15 * Torbjorn Granlund, David MacKenzie, and Jim Meyering.
17 * The move code was based in GNU's mv, and was written by:
18 * Mike Parker and David MacKenzie.
20 * Janne Kukonlehto added much error recovery to them for being used
21 * in an interactive program.
23 * This program is free software; you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published by
25 * the Free Software Foundation; either version 2 of the License, or
26 * (at your option) any later version.
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
39 * Please note that all dialogs used here must be safe for background
44 * \brief Source: file management GUI for the text mode edition
47 /* {{{ Include files */
55 #include <sys/types.h>
58 #if defined(STAT_STATVFS) \
59 && (defined(HAVE_STRUCT_STATVFS_F_BASETYPE) \
60 || defined(HAVE_STRUCT_STATVFS_F_FSTYPENAME))
61 # include <sys/statvfs.h>
62 # define STRUCT_STATFS struct statvfs
63 # define STATFS statvfs
64 #elif defined(HAVE_STATFS) && !defined(STAT_STATFS4)
65 # ifdef HAVE_SYS_VFS_H
67 # elif defined(HAVE_SYS_MOUNT_H) && defined(HAVE_SYS_PARAM_H)
68 # include <sys/param.h>
69 # include <sys/mount.h>
70 # elif defined(HAVE_SYS_STATFS_H)
71 # include <sys/statfs.h>
73 # define STRUCT_STATFS struct statfs
74 # define STATFS statfs
81 #include "../src/tty/key.h" /* tty_get_event */
83 #include "../src/search/search.h"
85 #include "setup.h" /* verbose */
86 #include "dialog.h" /* do_refresh() */
87 #include "widget.h" /* WLabel */
88 #include "main-widgets.h"
89 #include "main.h" /* the_hint */
90 #include "wtools.h" /* QuickDialog */
91 #include "panel.h" /* current_panel */
92 #include "fileopctx.h" /* FILE_CONT */
94 #include "util.h" /* strip_password() */
96 #include "../src/strescape.h"
100 MSDOS_SUPER_MAGIC
= 0x4d44,
101 NTFS_SB_MAGIC
= 0x5346544e,
102 NTFS_3G_MAGIC
= 0x65735546,
103 PROC_SUPER_MAGIC
= 0x9fa0,
104 SMB_SUPER_MAGIC
= 0x517B,
105 NCP_SUPER_MAGIC
= 0x564c,
106 USBDEVICE_SUPER_MAGIC
= 0x9fa2
107 } filegui_nonattrs_fs_t
;
109 /* Hack: the vfs code should not rely on this */
110 #define WITH_FULL_PATHS 1
112 /* This structure describes the UI and internal data required by a file
122 /* Dialog and widgets for the operation progress window */
126 WLabel
*file_label
[2];
127 WLabel
*file_string
[2];
128 WLabel
*progress_label
[3];
129 WGauge
*progress_gauge
[3];
132 WLabel
*stalled_label
;
134 /* Query replace dialog */
136 Dlg_head
*replace_dlg
;
137 const char *replace_filename
;
139 struct stat
*s_stat
, *d_stat
;
143 /* Used to save the hint line */
144 static int last_hint_line
;
146 /* File operate window sizes */
150 #define WX_ETA_EXTRA 12
152 #define FCOPY_GAUGE_X 14
153 #define FCOPY_LABEL_X 5
155 /* Used for button result values */
157 REPLACE_YES
= B_USER
,
169 filegui__check_attrs_on_fs(const char *fs_path
)
174 if (!setup_copymove_persistent_attr
)
177 if (STATFS(fs_path
, &stfs
)!=0)
181 switch ((filegui_nonattrs_fs_t
) stfs
.f_type
)
183 case MSDOS_SUPER_MAGIC
:
186 case PROC_SUPER_MAGIC
:
187 case SMB_SUPER_MAGIC
:
188 case NCP_SUPER_MAGIC
:
189 case USBDEVICE_SUPER_MAGIC
:
193 # elif defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) \
194 || defined(HAVE_STRUCT_STATVFS_F_FSTYPENAME)
195 if (!strcmp(stfs
.f_fstypename
, "msdos")
196 || !strcmp(stfs
.f_fstypename
, "msdosfs")
197 || !strcmp(stfs
.f_fstypename
, "ntfs")
198 || !strcmp(stfs
.f_fstypename
, "procfs")
199 || !strcmp(stfs
.f_fstypename
, "smbfs")
200 || strstr(stfs
.f_fstypename
, "fusefs"))
202 # elif defined(HAVE_STRUCT_STATVFS_F_BASETYPE)
203 if (!strcmp(stfs
.f_basetype
, "pcfs")
204 || !strcmp(stfs
.f_basetype
, "ntfs")
205 || !strcmp(stfs
.f_basetype
, "proc")
206 || !strcmp(stfs
.f_basetype
, "smbfs")
207 || !strcmp(stfs
.f_basetype
, "fuse"))
215 static FileProgressStatus
216 check_progress_buttons (FileOpContext
*ctx
)
227 event
.x
= -1; /* Don't show the GPM cursor */
228 c
= tty_get_event (&event
, FALSE
, FALSE
);
232 /* Reinitialize to avoid old values after events other than
233 selecting a button */
234 ui
->op_dlg
->ret_value
= FILE_CONT
;
236 dlg_process_event (ui
->op_dlg
, c
, &event
);
237 switch (ui
->op_dlg
->ret_value
) {
250 /* {{{ File progress display routines */
253 file_op_context_create_ui_without_init (FileOpContext
*ctx
, int with_eta
)
262 g_return_if_fail (ctx
!= NULL
);
263 g_return_if_fail (ctx
->ui
== NULL
);
265 ui
= g_new0 (FileOpContextUI
, 1);
268 minus
= verbose
? 0 : 3;
269 eta_offset
= with_eta
? (WX_ETA_EXTRA
) / 2 : 0;
274 ctx
->recursive_result
= 0;
276 ui
->replace_result
= 0;
277 ui
->showing_eta
= with_eta
;
278 ui
->showing_bps
= with_eta
;
279 ui
->eta_extra
= with_eta
? WX_ETA_EXTRA
: 0;
280 x_size
= (WX
+ 4) + ui
->eta_extra
;
283 create_dlg (0, 0, WY
- minus
+ 4, x_size
, dialog_colors
, NULL
,
284 NULL
, op_names
[ctx
->operation
],
285 DLG_CENTER
| DLG_REVERSE
);
287 last_hint_line
= the_hint
->widget
.y
;
288 if ((ui
->op_dlg
->y
+ ui
->op_dlg
->lines
) > last_hint_line
)
289 the_hint
->widget
.y
= ui
->op_dlg
->y
+ ui
->op_dlg
->lines
+ 1;
291 add_widget (ui
->op_dlg
,
292 button_new (BY
- minus
, WX
- 19 + eta_offset
, FILE_ABORT
,
293 NORMAL_BUTTON
, _("&Abort"), 0));
294 add_widget (ui
->op_dlg
,
295 button_new (BY
- minus
, 14 + eta_offset
, FILE_SKIP
,
296 NORMAL_BUTTON
, _("&Skip"), 0));
298 add_widget (ui
->op_dlg
, ui
->progress_gauge
[2] =
299 gauge_new (7, FCOPY_GAUGE_X
, 0, 100, 0));
300 add_widget (ui
->op_dlg
, ui
->progress_label
[2] =
301 label_new (7, FCOPY_LABEL_X
, fifteen
));
302 add_widget (ui
->op_dlg
, ui
->bps_label
= label_new (7, WX
, ""));
304 add_widget (ui
->op_dlg
, ui
->progress_gauge
[1] =
305 gauge_new (8, FCOPY_GAUGE_X
, 0, 100, 0));
306 add_widget (ui
->op_dlg
, ui
->progress_label
[1] =
307 label_new (8, FCOPY_LABEL_X
, fifteen
));
308 add_widget (ui
->op_dlg
, ui
->stalled_label
= label_new (8, WX
, ""));
310 add_widget (ui
->op_dlg
, ui
->progress_gauge
[0] =
311 gauge_new (6, FCOPY_GAUGE_X
, 0, 100, 0));
312 add_widget (ui
->op_dlg
, ui
->progress_label
[0] =
313 label_new (6, FCOPY_LABEL_X
, fifteen
));
314 add_widget (ui
->op_dlg
, ui
->eta_label
= label_new (6, WX
, ""));
316 add_widget (ui
->op_dlg
, ui
->file_string
[1] =
317 label_new (4, FCOPY_GAUGE_X
, sixty
));
318 add_widget (ui
->op_dlg
, ui
->file_label
[1] =
319 label_new (4, FCOPY_LABEL_X
, fifteen
));
320 add_widget (ui
->op_dlg
, ui
->file_string
[0] =
321 label_new (3, FCOPY_GAUGE_X
, sixty
));
322 add_widget (ui
->op_dlg
, ui
->file_label
[0] =
323 label_new (3, FCOPY_LABEL_X
, fifteen
));
327 file_op_context_create_ui (FileOpContext
*ctx
, int with_eta
)
331 g_return_if_fail (ctx
!= NULL
);
332 g_return_if_fail (ctx
->ui
== NULL
);
334 file_op_context_create_ui_without_init(ctx
, with_eta
);
337 /* We will manage the dialog without any help, that's why
338 we have to call init_dlg */
339 init_dlg (ui
->op_dlg
);
340 ui
->op_dlg
->running
= 1;
344 file_op_context_destroy_ui (FileOpContext
*ctx
)
348 g_return_if_fail (ctx
!= NULL
);
353 dlg_run_done (ui
->op_dlg
);
354 destroy_dlg (ui
->op_dlg
);
358 the_hint
->widget
.y
= last_hint_line
;
363 static FileProgressStatus
364 show_no_bar (FileOpContext
*ctx
, int n
)
374 label_set_text (ui
->progress_label
[n
], "");
375 gauge_show (ui
->progress_gauge
[n
], 0);
377 return check_progress_buttons (ctx
);
380 static FileProgressStatus
381 show_bar (FileOpContext
*ctx
, int n
, double done
, double total
)
391 * Gauge needs integers, so give it with integers between 0 and 1023.
392 * This precision should be quite reasonable.
394 gauge_set_value (ui
->progress_gauge
[n
], 1024,
395 (int) (1024 * done
/ total
));
396 gauge_show (ui
->progress_gauge
[n
], 1);
397 return check_progress_buttons (ctx
);
401 file_eta_show (FileOpContext
*ctx
)
403 int eta_hours
, eta_mins
, eta_s
;
404 char eta_buffer
[BUF_TINY
];
412 if (!ui
->showing_eta
)
415 if (ctx
->eta_secs
> 0.5) {
416 eta_hours
= ctx
->eta_secs
/ (60 * 60);
417 eta_mins
= (ctx
->eta_secs
- (eta_hours
* 60 * 60)) / 60;
418 eta_s
= ctx
->eta_secs
- (eta_hours
* 60 * 60 + eta_mins
* 60);
419 g_snprintf (eta_buffer
, sizeof (eta_buffer
), _("ETA %d:%02d.%02d"),
420 eta_hours
, eta_mins
, eta_s
);
424 label_set_text (ui
->eta_label
, eta_buffer
);
428 file_bps_show (FileOpContext
*ctx
)
430 char bps_buffer
[BUF_TINY
];
438 if (!ui
->showing_bps
)
441 if (ctx
->bps
> 1024 * 1024) {
442 g_snprintf (bps_buffer
, sizeof (bps_buffer
), _("%.2f MB/s"),
443 ctx
->bps
/ (1024 * 1024.0));
444 } else if (ctx
->bps
> 1024) {
445 g_snprintf (bps_buffer
, sizeof (bps_buffer
), _("%.2f KB/s"),
447 } else if (ctx
->bps
> 1) {
448 g_snprintf (bps_buffer
, sizeof (bps_buffer
), _("%ld B/s"),
453 label_set_text (ui
->bps_label
, bps_buffer
);
457 file_progress_show (FileOpContext
*ctx
, off_t done
, off_t total
)
461 g_return_val_if_fail (ctx
!= NULL
, FILE_CONT
);
469 return check_progress_buttons (ctx
);
471 label_set_text (ui
->progress_label
[0], _("File"));
474 return show_bar (ctx
, 0, done
, total
);
476 return show_no_bar (ctx
, 0);
480 file_progress_show_count (FileOpContext
*ctx
, off_t done
, off_t total
)
484 g_return_val_if_fail (ctx
!= NULL
, FILE_CONT
);
492 return check_progress_buttons (ctx
);
494 label_set_text (ui
->progress_label
[1], _("Count"));
495 return show_bar (ctx
, 1, done
, total
);
497 return show_no_bar (ctx
, 1);
501 file_progress_show_bytes (FileOpContext
*ctx
, double done
, double total
)
505 g_return_val_if_fail (ctx
!= NULL
, FILE_CONT
);
513 return check_progress_buttons (ctx
);
515 label_set_text (ui
->progress_label
[2], _("Bytes"));
516 return show_bar (ctx
, 2, done
, total
);
518 return show_no_bar (ctx
, 2);
523 #define truncFileString(ui, s) str_trunc (s, ui->eta_extra + 47)
524 #define truncFileStringSecure(ui, s) path_trunc (s, ui->eta_extra + 47)
527 file_progress_show_source (FileOpContext
*ctx
, const char *s
)
531 g_return_val_if_fail (ctx
!= NULL
, FILE_CONT
);
539 #ifdef WITH_FULL_PATHS
540 int i
= strlen (current_panel
->cwd
);
542 /* We remove the full path we have added before */
543 if (!strncmp (s
, current_panel
->cwd
, i
)) {
544 if (s
[i
] == PATH_SEP
)
547 #endif /* WITH_FULL_PATHS */
549 label_set_text (ui
->file_label
[0], _("Source"));
550 label_set_text (ui
->file_string
[0], truncFileString (ui
, s
));
551 return check_progress_buttons (ctx
);
553 label_set_text (ui
->file_label
[0], "");
554 label_set_text (ui
->file_string
[0], "");
555 return check_progress_buttons (ctx
);
560 file_progress_show_target (FileOpContext
*ctx
, const char *s
)
564 g_return_val_if_fail (ctx
!= NULL
, FILE_CONT
);
572 label_set_text (ui
->file_label
[1], _("Target"));
573 label_set_text (ui
->file_string
[1], truncFileStringSecure (ui
, s
));
574 return check_progress_buttons (ctx
);
576 label_set_text (ui
->file_label
[1], "");
577 label_set_text (ui
->file_string
[1], "");
578 return check_progress_buttons (ctx
);
583 file_progress_show_deleting (FileOpContext
*ctx
, const char *s
)
587 g_return_val_if_fail (ctx
!= NULL
, FILE_CONT
);
594 label_set_text (ui
->file_label
[0], _("Deleting"));
595 label_set_text (ui
->file_label
[0], truncFileStringSecure (ui
, s
));
596 return check_progress_buttons (ctx
);
600 * FIXME: probably it is better to replace this with quick dialog machinery,
601 * but actually I'm not familiar with it and have not much time :(
607 overwrite_query_dialog (FileOpContext
*ctx
, enum OperationMode mode
)
609 #define ADD_RD_BUTTON(i)\
610 add_widget (ui->replace_dlg,\
611 button_new (rd_widgets [i].ypos, rd_widgets [i].xpos, rd_widgets [i].value,\
612 NORMAL_BUTTON, rd_widgets [i].text, 0))
614 #define ADD_RD_LABEL(i, p1, p2)\
615 g_snprintf (buffer, sizeof (buffer), rd_widgets [i].text, p1, p2);\
616 add_widget (ui->replace_dlg,\
617 label_new (rd_widgets [i].ypos, rd_widgets [i].xpos, buffer))
620 const int rd_ylen
= 17;
626 int value
; /* 0 for labels */
628 /* 0 */ { N_("Target file already exists!"), 3, 4, 0 },
629 /* 1 */ { "%s", 4, 4, 0 },
630 #if (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) || (defined _LARGE_FILES && _LARGE_FILES)
631 /* 2 */ { N_("Source date: %s, size %llu"), 6, 4, 0 },
632 /* 3 */ { N_("Target date: %s, size %llu"), 7, 4, 0 },
634 /* 2 */ { N_("Source date: %s, size %u"), 6, 4, 0 },
635 /* 3 */ { N_("Target date: %s, size %u"), 7, 4, 0 },
637 /* 4 */ { N_("&Abort"), 14, 25, REPLACE_ABORT
},
638 /* 5 */ { N_("If &size differs"), 12, 28, REPLACE_SIZE
},
639 /* 6 */ { N_("Non&e"), 11, 47, REPLACE_NEVER
},
640 /* 7 */ { N_("&Update"), 11, 36, REPLACE_UPDATE
},
641 /* 8 */ { N_("A&ll"), 11, 28, REPLACE_ALWAYS
},
642 /* 9 */ { N_("Overwrite all targets?"), 11, 4, 0 },
643 /* 10 */ { N_("&Reget"), 10, 28, REPLACE_REGET
},
644 /* 11 */ { N_("A&ppend"), 9, 45, REPLACE_APPEND
},
645 /* 12 */ { N_("&No"), 9, 37, REPLACE_NO
},
646 /* 13 */ { N_("&Yes"), 9, 28, REPLACE_YES
},
647 /* 14 */ { N_("Overwrite this target?"), 9, 4, 0 }
650 const int num
= sizeof (rd_widgets
) / sizeof (rd_widgets
[0]);
653 FileOpContextUI
*ui
= ctx
->ui
;
655 char buffer
[BUF_SMALL
];
657 const char *stripped_name
= strip_home_and_password (ui
->replace_filename
);
658 int stripped_name_len
;
662 widgets_len
= g_new0 (int, num
);
664 if (mode
== Foreground
)
665 title
= _(" File exists ");
667 title
= _(" Background process: File exists ");
669 stripped_name_len
= str_term_width1 (stripped_name
);
672 int i
, l1
, l2
, l
, row
;
674 for (i
= 0; i
< num
; i
++) {
676 if (i
!= 1) /* skip filename */
677 rd_widgets
[i
].text
= _(rd_widgets
[i
].text
);
678 #endif /* ENABLE_NLS */
679 widgets_len
[i
] = str_term_width1 (rd_widgets
[i
].text
);
683 * longest of "Overwrite..." labels
684 * (assume "Target date..." are short enough)
686 l1
= max (widgets_len
[9], widgets_len
[14]);
688 /* longest of button rows */
690 for (row
= l
= l2
= 0; i
--;)
691 if (rd_widgets
[i
].value
!= 0) {
692 if (row
!= rd_widgets
[i
].ypos
) {
693 row
= rd_widgets
[i
].ypos
;
697 l
+= widgets_len
[i
] + 4;
700 l2
= max (l2
, l
); /* last row */
701 rd_xlen
= max (rd_xlen
, l1
+ l2
+ 8);
702 rd_xlen
= max (rd_xlen
, str_term_width1 (title
) + 2);
703 rd_xlen
= max (rd_xlen
, min (COLS
, stripped_name_len
+ 8));
705 /* Now place widgets */
706 l1
+= 5; /* start of first button in the row */
708 for (l
= l1
, row
= 0; --i
> 1;)
709 if (rd_widgets
[i
].value
!= 0) {
710 if (row
!= rd_widgets
[i
].ypos
) {
711 row
= rd_widgets
[i
].ypos
;
714 rd_widgets
[i
].xpos
= l
;
715 l
+= widgets_len
[i
] + 4;
718 /* Abort button is centered */
719 rd_widgets
[4].xpos
= (rd_xlen
- widgets_len
[4] - 3) / 2;
722 /* FIXME - missing help node */
724 create_dlg (0, 0, rd_ylen
, rd_xlen
, alarm_colors
, NULL
, "[Replace]",
725 title
, DLG_CENTER
| DLG_REVERSE
);
727 /* prompt -- centered */
728 add_widget (ui
->replace_dlg
,
729 label_new (rd_widgets
[0].ypos
,
730 (rd_xlen
- widgets_len
[0]) / 2,
731 rd_widgets
[0].text
));
732 /* file name -- centered */
733 stripped_name
= str_trunc (stripped_name
, rd_xlen
- 8);
734 stripped_name_len
= str_term_width1 (stripped_name
);
735 add_widget (ui
->replace_dlg
,
736 label_new (rd_widgets
[1].ypos
,
737 (rd_xlen
- stripped_name_len
) / 2,
741 ADD_RD_LABEL (2, file_date (ui
->s_stat
->st_mtime
),
742 (off_t
) ui
->s_stat
->st_size
);
743 /* destination date */
744 ADD_RD_LABEL (3, file_date (ui
->d_stat
->st_mtime
),
745 (off_t
) ui
->d_stat
->st_size
);
747 ADD_RD_BUTTON (4); /* Abort */
748 ADD_RD_BUTTON (5); /* If size differs */
749 ADD_RD_BUTTON (6); /* None */
750 ADD_RD_BUTTON (7); /* Update */
751 ADD_RD_BUTTON (8); /* All" */
752 ADD_RD_LABEL (9, 0, 0); /* Overwrite all targets? */
754 /* "this target..." widgets */
755 if (!S_ISDIR (ui
->d_stat
->st_mode
)) {
756 if ((ctx
->operation
== OP_COPY
) && (ui
->d_stat
->st_size
!= 0)
757 && (ui
->s_stat
->st_size
> ui
->d_stat
->st_size
))
758 ADD_RD_BUTTON (10); /* Reget */
760 ADD_RD_BUTTON (11); /* Append */
762 ADD_RD_BUTTON (12); /* No */
763 ADD_RD_BUTTON (13); /* Yes */
764 ADD_RD_LABEL (14, 0, 0); /* Overwrite this target? */
766 result
= run_dlg (ui
->replace_dlg
);
767 destroy_dlg (ui
->replace_dlg
);
769 g_free (widgets_len
);
777 file_progress_set_stalled_label (FileOpContext
*ctx
, const char *stalled_msg
)
781 g_return_if_fail (ctx
!= NULL
);
782 g_return_if_fail (ctx
->ui
!= NULL
);
785 label_set_text (ui
->stalled_label
, stalled_msg
);
789 file_progress_real_query_replace (FileOpContext
*ctx
,
790 enum OperationMode mode
, const char *destname
,
791 struct stat
*_s_stat
,
792 struct stat
*_d_stat
)
796 g_return_val_if_fail (ctx
!= NULL
, FILE_CONT
);
797 g_return_val_if_fail (ctx
->ui
!= NULL
, FILE_CONT
);
801 if (ui
->replace_result
< REPLACE_ALWAYS
) {
802 ui
->replace_filename
= destname
;
803 ui
->s_stat
= _s_stat
;
804 ui
->d_stat
= _d_stat
;
805 ui
->replace_result
= overwrite_query_dialog (ctx
, mode
);
806 if (ui
->replace_result
== B_CANCEL
)
807 ui
->replace_result
= REPLACE_ABORT
;
810 switch (ui
->replace_result
) {
813 if (_s_stat
->st_mtime
> _d_stat
->st_mtime
)
820 if (_s_stat
->st_size
== _d_stat
->st_size
)
826 /* Careful: we fall through and set do_append */
827 ctx
->do_reget
= _d_stat
->st_size
;
847 is_wildcarded (char *p
)
852 if (*p
== '\\' && p
[1] >= '1' && p
[1] <= '9')
859 file_mask_dialog (FileOpContext
*ctx
, FileOperation operation
,
861 const char *format
, const void *text
,
862 const char *def_text
, gboolean
*do_background
)
864 const size_t FMDY
= 13;
865 const size_t FMDX
= 68;
869 const size_t gap
= 1;
870 size_t b0_len
, b2_len
;
873 int source_easy_patterns
= easy_patterns
;
875 char fmd_buf
[BUF_MEDIUM
];
876 char *source_mask
, *orig_mask
, *dest_dir
, *tmp
;
877 char *def_text_secure
;
880 QuickWidget fmd_widgets
[] =
882 /* 0 */ QUICK_BUTTON (42, 64, 10, FMDY
, N_("&Cancel"), B_CANCEL
, NULL
),
883 #ifdef WITH_BACKGROUND
884 /* 1 */ QUICK_BUTTON (25, 64, 10, FMDY
, N_("&Background"), B_USER
, NULL
),
888 #endif /* WITH_BACKGROUND */
890 QUICK_BUTTON (14, FMDX
, 10, FMDY
, N_("&OK"), B_ENTER
, NULL
),
892 QUICK_CHECKBOX (42, FMDX
, 8, FMDY
, N_("&Stable Symlinks"), &ctx
->stable_symlinks
),
894 QUICK_CHECKBOX (31, FMDX
, 7, FMDY
, N_("di&Ve into subdir if exists"), &ctx
->dive_into_subdirs
),
896 QUICK_CHECKBOX (3, FMDX
, 8, FMDY
, N_("preserve &Attributes"), &ctx
->op_preserve
),
898 QUICK_CHECKBOX (3, FMDX
, 7, FMDY
, N_("follow &Links"), &ctx
->follow_links
),
900 QUICK_INPUT (3, FMDX
, 6, FMDY
, "", 58, 0, "input2", &dest_dir
),
902 QUICK_LABEL (3, FMDX
, 5, FMDY
, N_("to:")),
904 QUICK_CHECKBOX (37, FMDX
, 4, FMDY
, N_("&Using shell patterns"), &source_easy_patterns
),
906 QUICK_INPUT (3, FMDX
, 3, FMDY
, easy_patterns
? "*" : "^\\(.*\\)$", 58, 0, "input-def", &source_mask
),
908 QUICK_LABEL (3, FMDX
, 2, FMDY
, fmd_buf
),
912 g_return_val_if_fail (ctx
!= NULL
, NULL
);
916 for (i
= 0; i
<= 2 - OFFSET
; i
++)
917 fmd_widgets
[i
].u
.button
.text
= _(fmd_widgets
[i
].u
.button
.text
);
920 for (i
= 3 - OFFSET
; i
<= 9 - OFFSET
; i
++)
922 fmd_widgets
[i
].u
.checkbox
.text
= _(fmd_widgets
[i
].u
.checkbox
.text
);
923 #endif /* !ENABLE_NLS */
925 fmd_xlen
= max (FMDX
, (size_t) COLS
* 2/3);
927 len
= str_term_width1 (fmd_widgets
[6 - OFFSET
].u
.checkbox
.text
)
928 + str_term_width1 (fmd_widgets
[4 - OFFSET
].u
.checkbox
.text
) + 15;
929 fmd_xlen
= max (fmd_xlen
, len
);
931 len
= str_term_width1 (fmd_widgets
[5 - OFFSET
].u
.checkbox
.text
)
932 + str_term_width1 (fmd_widgets
[3 - OFFSET
].u
.checkbox
.text
) + 15;
933 fmd_xlen
= max (fmd_xlen
, len
);
936 b2_len
= str_term_width1 (fmd_widgets
[2 - OFFSET
].u
.button
.text
) + 6 + gap
; /* OK */
937 #ifdef WITH_BACKGROUND
938 b1_len
= str_term_width1 (fmd_widgets
[1].u
.button
.text
) + 4 + gap
; /* Background */
940 b0_len
= str_term_width1 (fmd_widgets
[0].u
.button
.text
) + 4; /* Cancel */
941 len
= b0_len
+ b1_len
+ b2_len
;
942 fmd_xlen
= min (max (fmd_xlen
, len
+ 6), (size_t) COLS
);
947 flen
= str_term_width1 (format
);
948 i
= fmd_xlen
- flen
- 4; /* FIXME */
949 g_snprintf (fmd_buf
, sizeof (fmd_buf
),
950 format
, str_trunc ((const char *) text
, i
));
952 g_snprintf (fmd_buf
, sizeof (fmd_buf
), format
, *(const int *) text
);
953 fmd_xlen
= max (fmd_xlen
, (size_t) str_term_width1 (fmd_buf
) + 6);
956 for (i
= sizeof (fmd_widgets
) / sizeof (fmd_widgets
[0]); i
> 0; )
957 fmd_widgets
[--i
].x_divisions
= fmd_xlen
;
959 i
= (fmd_xlen
- len
)/2;
961 fmd_widgets
[2 - OFFSET
].relative_x
= i
;
963 #ifdef WITH_BACKGROUND
964 /* Background button */
965 fmd_widgets
[1].relative_x
= i
;
969 fmd_widgets
[0].relative_x
= i
;
971 #define chkbox_xpos(i) \
972 fmd_widgets [i].relative_x = fmd_xlen - str_term_width1 (fmd_widgets [i].u.checkbox.text) - 6
973 chkbox_xpos (3 - OFFSET
);
974 chkbox_xpos (4 - OFFSET
);
975 chkbox_xpos (9 - OFFSET
);
979 fmd_widgets
[ 7 - OFFSET
].u
.input
.len
=
980 fmd_widgets
[10 - OFFSET
].u
.input
.len
= fmd_xlen
- 6;
982 /* unselect checkbox if target filesystem don't support attributes */
983 ctx
->op_preserve
= filegui__check_attrs_on_fs (def_text
);
985 /* filter out a possible password from def_text */
986 tmp
= strip_password (g_strdup (def_text
), 1);
987 if (source_easy_patterns
)
988 def_text_secure
= strutils_glob_escape (tmp
);
990 def_text_secure
= strutils_regex_escape (tmp
);
994 fmd_widgets
[7 - OFFSET
].u
.input
.text
= def_text_secure
;
996 ctx
->stable_symlinks
= 0;
997 *do_background
= FALSE
;
1002 QuickDialog Quick_input
=
1004 fmd_xlen
, FMDY
, -1, -1, op_names
[operation
],
1005 "[Mask Copy/Rename]", fmd_widgets
, TRUE
1009 val
= quick_dialog_skip (&Quick_input
, 4);
1011 if (val
== B_CANCEL
) {
1012 g_free (def_text_secure
);
1016 if (ctx
->follow_links
)
1017 ctx
->stat_func
= mc_stat
;
1019 ctx
->stat_func
= mc_lstat
;
1021 if (ctx
->op_preserve
) {
1023 ctx
->umask_kill
= 0777777;
1024 ctx
->preserve_uidgid
= (geteuid () == 0) ? 1 : 0;
1027 ctx
->preserve
= ctx
->preserve_uidgid
= 0;
1030 ctx
->umask_kill
= i2
^ 0777777;
1033 if (!dest_dir
|| !*dest_dir
) {
1034 g_free (def_text_secure
);
1035 g_free (source_mask
);
1039 ctx
->search_handle
= mc_search_new(source_mask
,-1);
1041 if (ctx
->search_handle
== NULL
) {
1042 message (D_ERROR
, MSG_ERROR
, _("Invalid source pattern `%s'"),
1045 g_free (source_mask
);
1049 g_free (def_text_secure
);
1050 g_free (source_mask
);
1052 ctx
->search_handle
->is_case_sentitive
= TRUE
;
1053 if (source_easy_patterns
)
1054 ctx
->search_handle
->search_type
= MC_SEARCH_T_GLOB
;
1056 ctx
->search_handle
->search_type
= MC_SEARCH_T_REGEX
;
1059 dest_dir
= tilde_expand (tmp
);
1062 ctx
->dest_mask
= strrchr (dest_dir
, PATH_SEP
);
1063 if (ctx
->dest_mask
== NULL
)
1064 ctx
->dest_mask
= dest_dir
;
1067 orig_mask
= ctx
->dest_mask
;
1068 if (!*ctx
->dest_mask
1069 || (!ctx
->dive_into_subdirs
&& !is_wildcarded (ctx
->dest_mask
)
1071 || (!mc_stat (dest_dir
, &buf
) && S_ISDIR (buf
.st_mode
))))
1072 || (ctx
->dive_into_subdirs
1073 && ((!only_one
&& !is_wildcarded (ctx
->dest_mask
))
1074 || (only_one
&& !mc_stat (dest_dir
, &buf
)
1075 && S_ISDIR (buf
.st_mode
)))))
1076 ctx
->dest_mask
= g_strdup ("\\0");
1078 ctx
->dest_mask
= g_strdup (ctx
->dest_mask
);
1083 dest_dir
= g_strdup ("./");
1086 *do_background
= TRUE
;