1999-01-06 Federico Mena Quintero <federico@nuclecu.unam.mx>

* fileopctx.h: New file with declarations for the file operation
	context structure.

	* fileopctx.c (file_op_context_new): New function to create a file
	operation context with the default file mask values.
	(file_op_context_destroy): New function to destroy a file
	operation context and its associated UI, if appropriate.

	* filegui.h: Use complete prototype for fmd_init_i18n().

	* filegui.c (FileOpContextUI): New structure that describes the UI
	and internal data for file operation contexts in the text mode
	version.
	(file_op_context_create_ui): Renamed from create_op_win() and
	made it use a context instead of global variables.
	(file_op_context_destroy_ui): Likewise, renamed from
	destroy_op_win().
	(fmd_widgets): Removed an #ifdef HAVE_XVIEW bit and moved the
	initialization of the result pointers to file_mask_dialog(), as we
	need to use the pointers to the fields inside the file op context now.
	Made all the functions use a file operation context.
	(file_mask_dialog): Always call fmd_init_i18n(); it will take care
	of idempotence by itself.
	(fmd_init_i18n): Now the code that makes sure this function is
	only called once is here.

	* cmd.c (check_for_default): Make it use a file operation context.
	* tree.c (tree_copy): Likewise.
	(tree_move): Likewise.
	(tree_rmdir_cmd): Likewise.

	* file.c: Removed file_progress_replace_progress and
	file_progress_replace_filename -- they are only used in filegui.c
	as part of the UI for the file operation context.
	(panel_operate_generate_prompt): Made static.
	(panel_operate_generate_prompt): Always call fmd_init_i18n(); it
	will take care of idempotence by itself.
	(panel_operate): Removed the panel_operate_def() function, and
	made panel_operate() take an extra "ask_user" argument.
	(query_recursive): Made static.

	* background.c (background_attention): Made static.
	(register_task_running): Made static.
	(do_background): Now takes a file operation context as an
	argument.  It stores the pid of the child there.

	* Makefile.in: Added fileopctx.[ch].
This commit is contained in:
Miguel de Icaza 1999-01-07 01:14:50 +00:00
parent 53d59fab98
commit 5920588805
4 changed files with 199 additions and 282 deletions

View File

@ -1,18 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/* New dialogs... */
#include "../vfs/vfs.h"
#include "file.h"
#include "panel.h"
FileProgressStatus file_progress_show_source (char *path);
FileProgressStatus file_progress_show_target (char *path);
FileProgressStatus file_progress_show_deleting (char *path);
FileProgressStatus file_progress_show (long done, long total);
FileProgressStatus file_progress_show_count (long done, long total);
FileProgressStatus file_progress_show_bytes (long done, long total);
FileProgressStatus file_progress_real_query_replace (enum OperationMode mode, char *destname, struct stat *_s_stat, struct stat *_d_stat);
void file_progress_set_stalled_label (char *stalled_msg);
char *file_mask_dialog (FileOperation operation, char *text, char *def_text, int only_one, int *do_background);
void create_op_win (FileOperation op, int with_eta);
void destroy_op_win (void);
void fmd_init_i18n();

View File

@ -1,264 +0,0 @@
#include "global.h"
#include "color.h"
static struct stat *s_stat, *d_stat;
/* Used for button result values */
enum {
REPLACE_YES = B_USER,
REPLACE_NO,
REPLACE_APPEND,
REPLACE_ALWAYS,
REPLACE_UPDATE,
REPLACE_NEVER,
REPLACE_ABORT,
REPLACE_SIZE,
REPLACE_REGET
} FileReplaceCode;
static int
replace_callback (struct Dlg_head *h, int Id, int Msg)
{
#ifndef HAVE_X
switch (Msg){
case DLG_DRAW:
dialog_repaint (h, ERROR_COLOR, ERROR_COLOR);
break;
}
#endif
return 0;
}
#ifdef HAVE_X
#define X_TRUNC 128
#else
#define X_TRUNC 52
#endif
/* File operate window sizes */
#define WX 62
#define WY 10
#define BY 10
#define WX_ETA_EXTRA 12
static int replace_colors [4];
static Dlg_head *replace_dlg;
/*
* FIXME: probably it is better to replace this with quick dialog machinery,
* but actually I'm not familiar with it and have not much time :(
* alex
*/
static struct
{
char* text;
int ypos, xpos;
int value; /* 0 for labels */
char* tkname;
WLay layout;
}
rd_widgets [] =
{
{N_("Target file \"%s\" already exists!"),
3, 4, 0, "target-e", XV_WLAY_CENTERROW},
{N_("&Abort"), BY + 3, 25, REPLACE_ABORT, "abort", XV_WLAY_CENTERROW},
{N_("if &Size differs"),
BY + 1, 28, REPLACE_SIZE, "if-size", XV_WLAY_RIGHTOF},
{N_("non&E"), BY, 47, REPLACE_NEVER, "none", XV_WLAY_RIGHTOF},
{N_("&Update"), BY, 36, REPLACE_UPDATE, "update", XV_WLAY_RIGHTOF},
{N_("al&L"), BY, 28, REPLACE_ALWAYS, "all", XV_WLAY_RIGHTOF},
{N_("Overwrite all targets?"),
BY, 4, 0, "over-label", XV_WLAY_CENTERROW},
{N_("&Reget"), BY - 1, 28, REPLACE_REGET, "reget", XV_WLAY_RIGHTOF},
{N_("ap&Pend"), BY - 2, 45, REPLACE_APPEND, "append", XV_WLAY_RIGHTOF},
{N_("&No"), BY - 2, 37, REPLACE_NO, "no", XV_WLAY_RIGHTOF},
{N_("&Yes"), BY - 2, 28, REPLACE_YES, "yes", XV_WLAY_RIGHTOF},
{N_("Overwrite this target?"),
BY - 2, 4, 0, "overlab", XV_WLAY_CENTERROW},
{N_("Target date: %s, size %d"),
6, 4, 0, "target-date",XV_WLAY_CENTERROW},
{N_("Source date: %s, size %d"),
5, 4, 0, "source-date",XV_WLAY_CENTERROW}
};
#define ADD_RD_BUTTON(i)\
add_widgetl (replace_dlg,\
button_new (rd_widgets [i].ypos, rd_widgets [i].xpos, rd_widgets [i].value,\
NORMAL_BUTTON, rd_widgets [i].text, 0, 0, rd_widgets [i].tkname), \
rd_widgets [i].layout)
#define ADD_RD_LABEL(i,p1,p2)\
sprintf (buffer, rd_widgets [i].text, p1, p2);\
add_widgetl (replace_dlg,\
label_new (rd_widgets [i].ypos, rd_widgets [i].xpos, buffer, rd_widgets [i].tkname),\
rd_widgets [i].layout)
static void
init_replace (enum OperationMode mode)
{
char buffer [128];
static int rd_xlen = 60, rd_trunc = X_TRUNC;
#ifdef ENABLE_NLS
static int i18n_flag;
if (!i18n_flag)
{
int l1, l2, l, row;
register int i = sizeof (rd_widgets) / sizeof (rd_widgets [0]);
while (i--)
rd_widgets [i].text = _(rd_widgets [i].text);
/*
*longest of "Overwrite..." labels
* (assume "Target date..." are short enough)
*/
l1 = max (strlen (rd_widgets [6].text), strlen (rd_widgets [11].text));
/* longest of button rows */
i = sizeof (rd_widgets) / sizeof (rd_widgets [0]);
for (row = l = l2 = 0; i--;)
{
if (rd_widgets [i].value != 0)
{
if (row != rd_widgets [i].ypos)
{
row = rd_widgets [i].ypos;
l2 = max (l2, l);
l = 0;
}
l += strlen (rd_widgets [i].text) + 4;
}
}
l2 = max (l2, l); /* last row */
rd_xlen = max (rd_xlen, l1 + l2 + 8);
rd_trunc = rd_xlen - 6;
/* Now place buttons */
l1 += 5; /* start of first button in the row */
i = sizeof (rd_widgets) / sizeof (rd_widgets [0]);
for (l = l1, row = 0; --i > 1;)
{
if (rd_widgets [i].value != 0)
{
if (row != rd_widgets [i].ypos)
{
row = rd_widgets [i].ypos;
l = l1;
}
rd_widgets [i].xpos = l;
l += strlen (rd_widgets [i].text) + 4;
}
}
/* Abort button is centered */
rd_widgets [1].xpos = (rd_xlen - strlen (rd_widgets [1].text) - 3) / 2;
}
#endif /* ENABLE_NLS */
replace_colors [0] = ERROR_COLOR;
replace_colors [1] = COLOR_NORMAL;
replace_colors [2] = ERROR_COLOR;
replace_colors [3] = COLOR_NORMAL;
replace_dlg = create_dlg (0, 0, 16, rd_xlen, replace_colors, replace_callback,
"[ Replace ]", "replace", DLG_CENTER);
x_set_dialog_title (replace_dlg,
mode == Foreground ? _(" File exists ") : _(" Background process: File exists "));
ADD_RD_LABEL(0, name_trunc (file_progress_replace_filename, rd_trunc - strlen (rd_widgets [0].text)), 0 );
ADD_RD_BUTTON(1);
ADD_RD_BUTTON(2);
ADD_RD_BUTTON(3);
ADD_RD_BUTTON(4);
ADD_RD_BUTTON(5);
ADD_RD_LABEL(6,0,0);
/* "this target..." widgets */
if (!S_ISDIR (d_stat->st_mode)){
if ((d_stat->st_size && s_stat->st_size > d_stat->st_size))
ADD_RD_BUTTON(7);
ADD_RD_BUTTON(8);
}
ADD_RD_BUTTON(9);
ADD_RD_BUTTON(10);
ADD_RD_LABEL(11,0,0);
ADD_RD_LABEL(12, file_date (d_stat->st_mtime), (int) d_stat->st_size);
ADD_RD_LABEL(13, file_date (s_stat->st_mtime), (int) s_stat->st_size);
}
FileProgressStatus
file_progress_real_query_replace (enum OperationMode mode, char *destname, struct stat *_s_stat,
struct stat *_d_stat)
{
g_warning ("memo: file_progress_real_query_replace!\n");
g_warning ("memo: file_progress_real_query_replace!\n");
g_warning ("memo: file_progress_real_query_replace!\n");
g_warning ("memo: file_progress_real_query_replace!\n");
g_warning ("memo: file_progress_real_query_replace!\n");
g_warning ("memo: file_progress_real_query_replace!\n");
g_warning ("memo: file_progress_real_query_replace!\n");
g_warning ("memo: file_progress_real_query_replace!\n");
g_warning ("memo: file_progress_real_query_replace!\n");
g_warning ("memo: file_progress_real_query_replace!\n");
g_warning ("memo: file_progress_real_query_replace!\n");
g_warning ("memo: file_progress_real_query_replace!\n");
g_warning ("memo: file_progress_real_query_replace!\n");
g_warning ("memo: file_progress_real_query_replace!\n");
g_warning ("memo: file_progress_real_query_replace!\n");
g_warning ("memo: file_progress_real_query_replace!\n");
/* Better to have something than nothing at all */
if (file_progress_replace_result < REPLACE_ALWAYS){
file_progress_replace_filename = destname;
s_stat = _s_stat;
d_stat = _d_stat;
init_replace (mode);
run_dlg (replace_dlg);
file_progress_replace_result = replace_dlg->ret_value;
if (file_progress_replace_result == B_CANCEL)
file_progress_replace_result = REPLACE_ABORT;
destroy_dlg (replace_dlg);
}
switch (file_progress_replace_result){
case REPLACE_UPDATE:
do_refresh ();
if (_s_stat->st_mtime > _d_stat->st_mtime)
return FILE_CONT;
else
return FILE_SKIP;
case REPLACE_SIZE:
do_refresh ();
if (_s_stat->st_size == _d_stat->st_size)
return FILE_SKIP;
else
return FILE_CONT;
case REPLACE_REGET:
/* Carefull: we fall through and set do_append */
file_progress_do_reget = _d_stat->st_size;
case REPLACE_APPEND:
file_progress_do_append = 1;
case REPLACE_YES:
case REPLACE_ALWAYS:
do_refresh ();
return FILE_CONT;
case REPLACE_NO:
case REPLACE_NEVER:
do_refresh ();
return FILE_SKIP;
case REPLACE_ABORT:
default:
return FILE_ABORT;
}
}

61
src/fileopctx.c Normal file
View File

@ -0,0 +1,61 @@
/* File operation contexts for the Midnight Commander
*
* Copyright (C) 1998 The Free Software Foundation
*
* Authors: Federico Mena <federico@nuclecu.unam.mx>
* Miguel de Icaza <miguel@nuclecu.unam.mx>
*/
#include <config.h>
#include <unistd.h>
#include <glib.h>
#include "fileopctx.h"
#include "../vfs/vfs.h"
/**
* file_op_context_new:
*
* Creates a new file operation context with the default values. If you later want
* to have a user interface for this, call #file_op_context_create_ui().
*
* Return value: The newly-created context, filled with the default file mask values.
**/
FileOpContext *
file_op_context_new (void)
{
FileOpContext *ctx;
ctx = g_new0 (FileOpContext, 1);
ctx->eta_secs = 0.0;
ctx->progress_bytes = 0.0;
ctx->do_reget = TRUE;
ctx->stat_func = mc_lstat;
ctx->preserve = TRUE;
ctx->preserve_uidgid = (geteuid () == 0) ? TRUE : FALSE;
ctx->umask_kill = 0777777;
ctx->erase_at_end = TRUE;
return ctx;
}
/**
* file_op_context_destroy:
* @ctx: The file operation context to destroy.
*
* Destroys the specified file operation context and its associated UI data, if
* it exists.
**/
void
file_op_context_destroy (FileOpContext *ctx)
{
g_return_if_fail (ctx != NULL);
if (ctx->ui)
file_op_context_destroy_ui (ctx);
/* FIXME: do we need to free ctx->dest_mask? */
g_free (ctx);
}

138
src/fileopctx.h Normal file
View File

@ -0,0 +1,138 @@
/* File operation contexts for the Midnight Commander
*
* Copyright (C) 1998 The Free Software Foundation
*
* Authors: Federico Mena <federico@nuclecu.unam.mx>
* Miguel de Icaza <miguel@nuclecu.unam.mx>
*/
#ifndef FILEOPCTX_H
#define FILEOPCTX_H
#include <sys/stat.h>
#include <sys/types.h>
#include "background.h"
#include "regex.h"
/* This structure describes a context for file operations. It is used to update
* the progress windows and pass around options.
*/
typedef struct {
/* The estimated time of arrival in seconds */
double eta_secs;
/* Transferred bytes per second */
long bps;
/* Transferred seconds */
long bps_time;
/* Whether the panel total has been computed */
int progress_totals_computed;
/* Counters for progress indicators */
long progress_count;
double progress_bytes;
/* Result from the recursive query */
int recursive_result;
/* Whether to do a reget */
int do_reget;
/* Controls appending to files */
int do_append;
/* Whether to stat or lstat */
int follow_links;
/* Pointer to the stat function we will use */
int (*stat_func) (char *filename, struct stat *buf);
/* Whether to recompute symlinks */
int stable_symlinks;
/* Preserve the original files' owner, group, permissions, and
* timestamps (owner, group only as root).
*/
int preserve;
/* If running as root, preserve the original uid/gid (we don't want to
* try chwon for non root) preserve_uidgid = preserve && uid == 0
*/
int preserve_uidgid;
/* The bits to preserve in created files' modes on file copy */
int umask_kill;
/* The mask of files to actually operate on */
char *dest_mask;
/* Regex for the file mask */
struct re_pattern_buffer rx;
struct re_registers regs;
/* Whether to dive into subdirectories for recursive operations */
int dive_into_subdirs;
/* When moving directories cross filesystem boundaries delete the
* successfull copied files when all files below the directory and its
* subdirectories were processed.
*
* If erase_at_end is zero files will be deleted immediately after their
* successful copy (Note: this behaviour is not tested and at the moment
* it can't be changed at runtime).
*/
int erase_at_end;
/* PID of the child for background operations */
pid_t pid;
/* User interface data goes here */
void *ui;
} FileOpContext;
FileOpContext *file_op_context_new (void);
void file_op_context_destroy (FileOpContext *ctx);
typedef enum {
OP_COPY,
OP_MOVE,
OP_DELETE
} FileOperation;
extern char *op_names [3];
typedef enum {
FILE_CONT,
FILE_RETRY,
FILE_SKIP,
FILE_ABORT
} FileProgressStatus;
/* The following functions are implemented separately by each port */
void file_op_context_create_ui (FileOpContext *ctx, FileOperation op, int with_eta);
void file_op_context_destroy_ui (FileOpContext *ctx);
FileProgressStatus file_progress_show (FileOpContext *ctx, long done, long total);
FileProgressStatus file_progress_show_count (FileOpContext *ctx, long done, long total);
FileProgressStatus file_progress_show_bytes (FileOpContext *ctx, double done, double total);
FileProgressStatus file_progress_show_source (FileOpContext *ctx, char *path);
FileProgressStatus file_progress_show_target (FileOpContext *ctx, char *path);
FileProgressStatus file_progress_show_deleting (FileOpContext *ctx, char *path);
void file_progress_set_stalled_label (FileOpContext *ctx, char *stalled_msg);
FileProgressStatus file_progress_real_query_replace (FileOpContext *ctx,
enum OperationMode mode,
char *destname,
struct stat *_s_stat,
struct stat *_d_stat);
#endif