Major query replace dialog cleanup

This commit is contained in:
Jonathan Blandford 1998-12-22 23:38:39 +00:00
parent 7f3a7ac4d7
commit 2924e5bc78
5 changed files with 228 additions and 71 deletions

View File

@ -1,3 +1,11 @@
1998-12-22 Jonathan Blandford <jrb@redhat.com>
* gdialogs.c (file_progress_query_replace_policy): new function.
Currently called every time multiple files are called -- should
only be called if needed.
(file_progress_real_query_replace): Cleaned up some. Still has a
bit of work to do, but in general, much better.
Mon Dec 21 22:33:07 1998 Norbert Warmuth <nwarmuth@privat.circular.de> Mon Dec 21 22:33:07 1998 Norbert Warmuth <nwarmuth@privat.circular.de>
* layout: Deleted obsolete widgets from the Virtual FS configuration * layout: Deleted obsolete widgets from the Virtual FS configuration

View File

@ -9,6 +9,16 @@
#include "regex.h" #include "regex.h"
#include "../vfs/vfs.h" #include "../vfs/vfs.h"
enum {
REPLACE_PROMPT,
REPLACE_ALWAYS,
REPLACE_UPDATE,
REPLACE_NEVER,
REPLACE_ABORT,
REPLACE_SIZE,
REPLACE_OPTION_MENU
} FileReplaceCode;
static GtkWidget *op_win = NULL; static GtkWidget *op_win = NULL;
static GtkWidget *fmd_win = NULL; static GtkWidget *fmd_win = NULL;
static GtkObject *count_label = NULL; static GtkObject *count_label = NULL;
@ -16,10 +26,18 @@ static GtkObject *byte_prog = NULL;
static GtkWidget *file_label = NULL; static GtkWidget *file_label = NULL;
static GtkWidget *op_source_label = NULL; static GtkWidget *op_source_label = NULL;
static GtkWidget *op_target_label = NULL; static GtkWidget *op_target_label = NULL;
static GtkWidget *op_radio = NULL;
int op_preserve = 1; int op_preserve = 1;
static gint copy_status;
static gint minor_copy_status;
#define GDIALOG_TO_STRING "To: " #define GDIALOG_TO_STRING "To: "
#define GDIALOG_FROM_STRING "Copying from: " #define GDIALOG_FROM_STRING "Copying from: "
#define GDIALOG_PROGRESS_WIDTH 350 #define GDIALOG_PROGRESS_WIDTH 350
/* Callbacks go here... */ /* Callbacks go here... */
static void static void
fmd_check_box_callback (GtkWidget *widget, gpointer data) fmd_check_box_callback (GtkWidget *widget, gpointer data)
@ -156,23 +174,178 @@ file_progress_show_bytes (double done, double total)
gtk_main_iteration (); gtk_main_iteration ();
return FILE_CONT; return FILE_CONT;
} }
static void
option_menu_policy_callback (GtkWidget *menu, gpointer data)
{
g_print ("ork ork:%d\n", (gint) data);
minor_copy_status = (gint) data;
copy_status = (gint) data;
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (op_radio), TRUE);
}
static void
policy_callback (GtkWidget *button, gpointer data)
{
if (GTK_TOGGLE_BUTTON (button)->active) {
g_print ("toggle\n");
if ((gint) data == REPLACE_OPTION_MENU) {
copy_status = minor_copy_status;
} else
copy_status = (gint) data;
}
}
FileProgressStatus
file_progress_query_replace_policy ()
{
GtkWidget *qrp_dlg;
GtkWidget *radio;
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *icon;
GtkWidget *label;
GtkWidget *hrbox;
GSList *group = NULL;
GtkWidget *omenu;
GtkWidget *menu;
GtkWidget *menu_item;
/* copy_status = REPLACE_PROMPT;
* I have placed the old code because it is importatn. minor_copy_status = REPLACE_ALWAYS;
* It is in temp-hack for now. g_print ("in file_progress_query_replace_policy\n");
* qrp_dlg = gnome_dialog_new (_("Files Exist"),
* When the new code for replace_dlg is done, we can GNOME_STOCK_BUTTON_OK,
* kill it. GNOME_STOCK_BUTTON_CANCEL,
* -miguel. NULL);
*/ vbox = gtk_vbox_new (FALSE, GNOME_PAD_SMALL);
#include "temp-hack.c" hbox = gtk_hbox_new (FALSE, GNOME_PAD_SMALL);
icon = gnome_stock_pixmap_widget (hbox, GNOME_STOCK_PIXMAP_HELP);
gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, GNOME_PAD_SMALL);
label = gtk_label_new (_("Some of the files you are trying to copy already "
"exist in the destination folder."));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), gtk_hseparator_new (), FALSE, FALSE, 0);
radio = gtk_radio_button_new_with_label (group, _("Prompt me before overwriting any file."));
gtk_signal_connect (GTK_OBJECT (radio), "toggled", GTK_SIGNAL_FUNC (policy_callback), (gpointer) REPLACE_PROMPT);
gtk_box_pack_start (GTK_BOX (vbox), radio, FALSE, FALSE, 0);
group = gtk_radio_button_group (GTK_RADIO_BUTTON (radio));
radio = gtk_radio_button_new_with_label (group, _("Don't overwrite any files."));
gtk_signal_connect (GTK_OBJECT (radio), "toggled", GTK_SIGNAL_FUNC (policy_callback), (gpointer) REPLACE_NEVER);
gtk_box_pack_start (GTK_BOX (vbox), radio, FALSE, FALSE, 0);
group = gtk_radio_button_group (GTK_RADIO_BUTTON (radio));
op_radio = gtk_radio_button_new (group);
gtk_signal_connect (GTK_OBJECT (op_radio), "toggled", GTK_SIGNAL_FUNC (policy_callback), (gpointer) REPLACE_OPTION_MENU);
hrbox = gtk_hbox_new (FALSE, GNOME_PAD_SMALL);
gtk_box_pack_start (GTK_BOX (hrbox), gtk_label_new (_("Overwrite:")), FALSE, FALSE, 0);
/* we set up the option menu. */
omenu = gtk_option_menu_new ();
gtk_box_pack_start (GTK_BOX (hrbox), omenu, FALSE, FALSE, 0);
menu = gtk_menu_new ();
menu_item = gtk_menu_item_new_with_label ( _("Older files."));
gtk_menu_append (GTK_MENU (menu), menu_item);
gtk_signal_connect (GTK_OBJECT (menu_item), "activate",
GTK_SIGNAL_FUNC (option_menu_policy_callback), (gpointer) REPLACE_UPDATE);
menu_item = gtk_menu_item_new_with_label ( _("Files only if size differs."));
gtk_menu_append (GTK_MENU (menu), menu_item);
gtk_signal_connect (GTK_OBJECT (menu_item), "activate",
GTK_SIGNAL_FUNC (option_menu_policy_callback), (gpointer) REPLACE_SIZE);
menu_item = gtk_menu_item_new_with_label ( _("All files."));
gtk_menu_append (GTK_MENU (menu), menu_item);
gtk_signal_connect (GTK_OBJECT (menu_item), "activate",
GTK_SIGNAL_FUNC (option_menu_policy_callback), (gpointer) REPLACE_ALWAYS);
gtk_widget_show_all (menu);
gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu);
gtk_signal_connect (GTK_OBJECT (op_radio), "toggled", GTK_SIGNAL_FUNC (policy_callback), (gpointer) REPLACE_ALWAYS);
gtk_box_pack_start (GTK_BOX (vbox), op_radio, FALSE, FALSE, 0);
group = gtk_radio_button_group (GTK_RADIO_BUTTON (op_radio));
gtk_container_add (GTK_CONTAINER (op_radio), hrbox);
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (qrp_dlg)->vbox),
hbox, FALSE, FALSE, 0);
gtk_widget_show_all (GTK_WIDGET (GNOME_DIALOG (qrp_dlg)->vbox));
switch (gnome_dialog_run_and_close (GNOME_DIALOG (qrp_dlg))) {
case 0:
break;
case -1:
default:
copy_status = REPLACE_ABORT;
return FILE_ABORT;
}
return FILE_CONT;
}
FileProgressStatus
file_progress_real_query_replace (enum OperationMode mode, char *destname, struct stat *_s_stat, struct stat *_d_stat)
{
GtkWidget *qr_dlg;
gchar msg[128];
GtkWidget *label;
/* so what's the situation? Do we prompt or don't we prompt. */
if (copy_status == REPLACE_PROMPT){
qr_dlg = gnome_dialog_new ("File Exists", "Yes", "No", "Cancel", NULL);
snprintf (msg, 127, "The target file already exists:", destname);
label = gtk_label_new ("The target file already exists.");
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (qr_dlg)->vbox),
label, FALSE, FALSE, 0);
gtk_widget_show_all (GNOME_DIALOG (qr_dlg)->vbox);
g_print ("here?\n");
switch (gnome_dialog_run_and_close (GNOME_DIALOG (qr_dlg))) {
case 0:
return FILE_CONT;
case 1:
return FILE_SKIP;
default:
return FILE_ABORT;
}
}
switch (copy_status){
case REPLACE_UPDATE:
if (_s_stat->st_mtime > _d_stat->st_mtime)
return FILE_CONT;
else
return FILE_SKIP;
case REPLACE_SIZE:
if (_s_stat->st_size == _d_stat->st_size)
return FILE_SKIP;
else
return FILE_CONT;
case REPLACE_ALWAYS:
return FILE_CONT;
case REPLACE_NEVER:
return FILE_SKIP;
case REPLACE_ABORT:
default:
return FILE_ABORT;
}
}
void void
file_progress_set_stalled_label (char *stalled_msg) file_progress_set_stalled_label (char *stalled_msg)
{ {
if (!stalled_msg || !*stalled_msg) if (!stalled_msg || !*stalled_msg)
return; return;
g_warning ("memo: file_progress_set_stalled_label!\nmsg\t%s\n",stalled_msg); g_warning ("FIXME: file_progress_set_stalled_label!\nmsg\t%s\n",stalled_msg);
} }
char * char *
file_mask_dialog (FileOperation operation, char *text, char *def_text, int only_one, int *do_background) file_mask_dialog (FileOperation operation, char *text, char *def_text, int only_one, int *do_background)
@ -366,8 +539,7 @@ create_op_win (FileOperation op, int with_eta)
{ {
GtkWidget *alignment; GtkWidget *alignment;
GtkWidget *hbox; GtkWidget *hbox;
GtkWidget *prog;
g_print ("in create_op_win\n");
switch (op) { switch (op) {
case OP_MOVE: case OP_MOVE:

View File

@ -40,77 +40,32 @@ int query_dialog (char *header, char *text, int flags, int count, ...)
va_list ap; va_list ap;
Dlg_head *h; Dlg_head *h;
WLabel *label; WLabel *label;
GtkDialog *dialog; GtkWidget *dialog;
GList *list;
int i, result = -1; int i, result = -1;
gchar **buttons;
if (header == MSG_ERROR) if (header == MSG_ERROR)
header = _("Error"); header = _("Error");
h = create_dlg (0, 0, 0, 0, dialog_colors, default_dlg_callback, "[QueryBox]", "query", h = create_dlg (0, 0, 0, 0, dialog_colors, default_dlg_callback, "[QueryBox]", "query",
DLG_NO_TED | DLG_NO_TOPLEVEL); DLG_NO_TED | DLG_NO_TOPLEVEL);
dialog = GTK_DIALOG (gtk_dialog_new ());
x_dlg_set_window (h, GTK_WIDGET (dialog));
gtk_window_set_policy (GTK_WINDOW (dialog), 0, 0, 0);
x_set_dialog_title (h, header); /* extract the buttons from the args */
buttons = g_malloc (sizeof (gchar[flags + 1]));
label = label_new (0, 0, text, NULL);
add_widget (h, label);
if (flags & D_ERROR)
fprintf (stderr, "Messagebox: this should be displayed like an error\n");
va_start (ap, count); va_start (ap, count);
list = g_list_alloc (); for (i = 0; i < count; i++)
for (i = 0; i < count; i++){ buttons[i] = va_arg (ap, char *);
WButton *button;
char *cur_name = va_arg (ap, char *);
button = button_new (0, 0, B_USER+i, NORMAL_BUTTON, cur_name, 0, 0, NULL);
add_widget (h, button);
list = g_list_append (list, button);
if (i == sel_pos)
h->initfocus = h->current;
}
va_end (ap); va_end (ap);
/* Init the widgets */
init_dlg (h);
if (!(flags & D_INSERT))
gtk_grab_add (GTK_WIDGET (dialog));
/* Now do the GTK stuff */ buttons[i] = NULL;
gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (label->widget.wdata)); dialog = gnome_message_box_newv (text, header, buttons);
gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), 5);
g_list_foreach (list, (GFunc) pack_button, dialog->action_area); switch (gnome_dialog_run_and_close (GNOME_DIALOG (dialog))){
g_list_free (list);
gtk_box_set_homogeneous (GTK_BOX (dialog->action_area), TRUE);
gtk_widget_show (GTK_WIDGET (dialog));
if (flags & D_INSERT){
last_query_dlg = h;
return 0;
}
frontend_run_dlg (h);
dlg_run_done (h);
last_query_dlg = h;
gtk_grab_remove (GTK_WIDGET (dialog));
switch (h->ret_value){
case B_CANCEL: case B_CANCEL:
break; break;
default: default:
result = h->ret_value - B_USER; result = h->ret_value - B_USER;
} }
destroy_dlg (h);
sel_pos = 0;
return result; return result;
} }

View File

@ -1,3 +1,7 @@
1998-12-22 Jonathan Blandford <jrb@redhat.com>
* file.c: add a HAVE_GNOME only function
Mon Dec 21 22:39:35 1998 Norbert Warmuth <nwarmuth@privat.circular.de> Mon Dec 21 22:39:35 1998 Norbert Warmuth <nwarmuth@privat.circular.de>
* mountlist.c: Define xBSD on FreeBSD. * mountlist.c: Define xBSD on FreeBSD.

View File

@ -216,9 +216,12 @@ char *file_mask_dest_mask = NULL;
int (*file_mask_xstat)(char *, struct stat *) = mc_lstat; int (*file_mask_xstat)(char *, struct stat *) = mc_lstat;
int file_mask_op_follow_links = 0; int file_mask_op_follow_links = 0;
#ifndef HAVE_GNOME
/* we don't need these in the GNOME version */
char *file_progress_replace_filename; char *file_progress_replace_filename;
int file_progress_replace_result; int file_progress_replace_result;
#endif
unsigned long file_progress_bps = 0, file_progress_bps_time = 0; unsigned long file_progress_bps = 0, file_progress_bps_time = 0;
char *op_names [3] = { char *op_names [3] = {
@ -1711,8 +1714,13 @@ panel_operate_flags (void *source_panel, FileOperation operation, char *thedefau
if (operation == OP_DELETE && confirm_delete){ if (operation == OP_DELETE && confirm_delete){
if (know_not_what_am_i_doing) if (know_not_what_am_i_doing)
query_set_sel (1); query_set_sel (1);
#ifdef HAVE_GNOME
i = query_dialog (_(op_names [operation]), cmd_buf,
D_ERROR, 2, _("Yes"), _("No"));
#else
i = query_dialog (_(op_names [operation]), cmd_buf, i = query_dialog (_(op_names [operation]), cmd_buf,
D_ERROR, 2, _("&Yes"), _("&No")); D_ERROR, 2, _("&Yes"), _("&No"));
#endif
if (i != 0) if (i != 0)
return 0; return 0;
} else if (operation != OP_DELETE){ } else if (operation != OP_DELETE){
@ -1771,8 +1779,6 @@ panel_operate_flags (void *source_panel, FileOperation operation, char *thedefau
#endif #endif
/* Initialize things */ /* Initialize things */
/* We now have ETA in all cases */
create_op_win (operation, 1);
/* We do not want to trash cache every time file is /* We do not want to trash cache every time file is
created/touched. However, this will make our cache contain created/touched. However, this will make our cache contain
invalid data. */ invalid data. */
@ -1791,6 +1797,9 @@ panel_operate_flags (void *source_panel, FileOperation operation, char *thedefau
/* This code is only called by the tree and panel code */ /* This code is only called by the tree and panel code */
if (only_one){ if (only_one){
/* We now have ETA in all cases */
create_op_win (operation, 1);
/* One file: FIXME mc_chdir will take user out of any vfs */ /* One file: FIXME mc_chdir will take user out of any vfs */
if (operation != OP_COPY && get_current_type () == view_tree) if (operation != OP_COPY && get_current_type () == view_tree)
mc_chdir (PATH_SEP_STR); mc_chdir (PATH_SEP_STR);
@ -1878,6 +1887,15 @@ panel_operate_flags (void *source_panel, FileOperation operation, char *thedefau
file_progress_bytes = panel->total; file_progress_bytes = panel->total;
} }
#ifdef HAVE_GNOME
/* FIXME: we need to determine if this dialog is actually needed. */
if (file_progress_query_replace_policy () == FILE_ABORT)
goto clean_up;
#endif
/* We now have ETA in all cases */
create_op_win (operation, 1);
/* Loop for every file, perform the actual copy operation */ /* Loop for every file, perform the actual copy operation */
for (i = 0; i < panel->count; i++){ for (i = 0; i < panel->count; i++){