Moved charsets.[ch] from src to lib directory
[midnight-commander.git] / src / fileopctx.h
bloba2b7b24f18d8214899151a2edf96bb5d017a1842
1 /** \file fileopctx.h
2 * \brief Header: file operation contexts
3 * \date 1998
4 * \author Federico Mena <federico@nuclecu.unam.mx>
5 * \author Miguel de Icaza <miguel@nuclecu.unam.mx>
6 */
8 /* File operation contexts for the Midnight Commander
10 * Copyright (C) 1998 Free Software Foundation, Inc.
14 #ifndef MC__FILEOPCTX_H
15 #define MC__FILEOPCTX_H
17 #include <sys/stat.h>
18 #include <sys/types.h>
19 #include <sys/time.h>
21 #include "lib/global.h"
24 /*** typedefs(not structures) and defined constants **********************************************/
26 typedef int (*mc_stat_fn) (const char *filename, struct stat * buf);
28 /*** enums ***************************************************************************************/
30 typedef enum
32 OP_COPY = 0,
33 OP_MOVE = 1,
34 OP_DELETE = 2
35 } FileOperation;
37 typedef enum
39 RECURSIVE_YES = 0,
40 RECURSIVE_NO = 1,
41 RECURSIVE_ALWAYS = 2,
42 RECURSIVE_NEVER = 3,
43 RECURSIVE_ABORT = 4
44 } FileCopyMode;
46 typedef enum
48 FILE_CONT = 0,
49 FILE_RETRY = 1,
50 FILE_SKIP = 2,
51 FILE_ABORT = 3
52 } FileProgressStatus;
54 /* First argument passed to real functions */
55 enum OperationMode
57 Foreground,
58 Background
61 /*** structures declarations (and typedefs of structures)*****************************************/
63 struct mc_search_struct;
65 /* This structure describes a context for file operations. It is used to update
66 * the progress windows and pass around options.
68 typedef struct FileOpContext
70 /* Operation type (copy, move, delete) */
71 FileOperation operation;
73 /* The estimated time of arrival in seconds */
74 double eta_secs;
76 /* Transferred bytes per second */
77 long bps;
79 /* Transferred seconds */
80 long bps_time;
82 /* Whether the panel total has been computed */
83 gboolean progress_totals_computed;
84 int dialog_type;
86 /* Counters for progress indicators */
87 off_t progress_count;
88 double progress_bytes;
90 /* The value of the "preserve Attributes" checkbox in the copy file dialog.
91 * We can't use the value of "ctx->preserve" because it can change in order
92 * to preserve file attributs when moving files across filesystem boundaries
93 * (we want to keep the value of the checkbox between copy operations).
95 gboolean op_preserve;
97 /* Result from the recursive query */
98 FileCopyMode recursive_result;
100 /* Whether to do a reget */
101 off_t do_reget;
103 /* Controls appending to files */
104 gboolean do_append;
106 /* Whether to stat or lstat */
107 gboolean follow_links;
109 /* Pointer to the stat function we will use */
110 mc_stat_fn stat_func;
112 /* Whether to recompute symlinks */
113 gboolean stable_symlinks;
115 /* Preserve the original files' owner, group, permissions, and
116 * timestamps (owner, group only as root).
118 int preserve;
120 /* If running as root, preserve the original uid/gid (we don't want to
121 * try chown for non root) preserve_uidgid = preserve && uid == 0
123 gboolean preserve_uidgid;
125 /* The bits to preserve in created files' modes on file copy */
126 int umask_kill;
128 /* The mask of files to actually operate on */
129 char *dest_mask;
131 /* search handler */
132 struct mc_search_struct *search_handle;
134 /* Whether to dive into subdirectories for recursive operations */
135 int dive_into_subdirs;
137 /* When moving directories cross filesystem boundaries delete the
138 * successfully copied files when all files below the directory and its
139 * subdirectories were processed.
141 * If erase_at_end is FALSE files will be deleted immediately after their
142 * successful copy (Note: this behavior is not tested and at the moment
143 * it can't be changed at runtime).
145 gboolean erase_at_end;
147 /* PID of the child for background operations */
148 pid_t pid;
150 /* User interface data goes here */
151 void *ui;
152 } FileOpContext;
154 typedef struct
156 off_t progress_count;
157 double progress_bytes;
158 double copyed_bytes;
159 size_t bps;
160 size_t bps_count;
161 struct timeval transfer_start;
162 double eta_secs;
164 gboolean ask_overwrite;
165 gboolean is_toplevel_file;
167 } FileOpTotalContext;
169 /*** global variables defined in .c file *********************************************************/
171 extern const char *op_names[3];
173 /*** declarations of public functions ************************************************************/
175 FileOpContext *file_op_context_new (FileOperation op);
176 void file_op_context_destroy (FileOpContext * ctx);
178 FileOpTotalContext *file_op_total_context_new (void);
179 void file_op_total_context_destroy (FileOpTotalContext * tctx);
181 /* The following functions are implemented separately by each port */
182 FileProgressStatus file_progress_real_query_replace (FileOpContext * ctx,
183 enum OperationMode mode,
184 const char *destname,
185 struct stat *_s_stat, struct stat *_d_stat);
187 /*** inline functions ****************************************************************************/
188 #endif /* MC__FILEOPCTX_H */