Merge branch '2944_cleanup'
[midnight-commander.git] / src / filemanager / fileopctx.h
blobb1af1887f9cbc0d85f155d48d6bffbfd8f5e7840
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>
20 #include <inttypes.h> /* uintmax_t */
22 #include "lib/global.h"
23 #include "lib/vfs/vfs.h"
26 /*** typedefs(not structures) and defined constants **********************************************/
28 typedef int (*mc_stat_fn) (const vfs_path_t * vpath, struct stat * buf);
30 /*** enums ***************************************************************************************/
32 typedef enum
34 FILEGUI_DIALOG_ONE_ITEM,
35 FILEGUI_DIALOG_MULTI_ITEM,
36 FILEGUI_DIALOG_DELETE_ITEM
37 } filegui_dialog_type_t;
39 typedef enum
41 OP_COPY = 0,
42 OP_MOVE = 1,
43 OP_DELETE = 2
44 } FileOperation;
46 typedef enum
48 RECURSIVE_YES = 0,
49 RECURSIVE_NO = 1,
50 RECURSIVE_ALWAYS = 2,
51 RECURSIVE_NEVER = 3,
52 RECURSIVE_ABORT = 4
53 } FileCopyMode;
55 typedef enum
57 FILE_CONT = 0,
58 FILE_RETRY = 1,
59 FILE_SKIP = 2,
60 FILE_ABORT = 3,
61 FILE_SKIPALL = 4,
62 FILE_SUSPEND = 5
63 } FileProgressStatus;
65 /* First argument passed to real functions */
66 enum OperationMode
68 Foreground,
69 Background
72 /*** structures declarations (and typedefs of structures)*****************************************/
74 struct mc_search_struct;
76 /* This structure describes a context for file operations. It is used to update
77 * the progress windows and pass around options.
79 typedef struct FileOpContext
81 /* Operation type (copy, move, delete) */
82 FileOperation operation;
84 /* The estimated time of arrival in seconds */
85 double eta_secs;
87 /* Transferred bytes per second */
88 long bps;
90 /* Transferred seconds */
91 long bps_time;
93 /* Whether the panel total has been computed */
94 gboolean progress_totals_computed;
95 filegui_dialog_type_t dialog_type;
97 /* Counters for progress indicators */
98 size_t progress_count;
99 uintmax_t progress_bytes;
101 /* The value of the "preserve Attributes" checkbox in the copy file dialog.
102 * We can't use the value of "ctx->preserve" because it can change in order
103 * to preserve file attributs when moving files across filesystem boundaries
104 * (we want to keep the value of the checkbox between copy operations).
106 gboolean op_preserve;
108 /* Result from the recursive query */
109 FileCopyMode recursive_result;
111 /* Whether to do a reget */
112 off_t do_reget;
114 /* Controls appending to files */
115 gboolean do_append;
117 /* Whether to stat or lstat */
118 gboolean follow_links;
120 /* Pointer to the stat function we will use */
121 mc_stat_fn stat_func;
123 /* Whether to recompute symlinks */
124 gboolean stable_symlinks;
126 /* Preserve the original files' owner, group, permissions, and
127 * timestamps (owner, group only as root).
129 gboolean preserve;
131 /* If running as root, preserve the original uid/gid (we don't want to
132 * try chown for non root) preserve_uidgid = preserve && uid == 0
134 gboolean preserve_uidgid;
136 /* The bits to preserve in created files' modes on file copy */
137 int umask_kill;
139 /* The mask of files to actually operate on */
140 char *dest_mask;
142 /* search handler */
143 struct mc_search_struct *search_handle;
145 /* Whether to dive into subdirectories for recursive operations */
146 gboolean dive_into_subdirs;
148 /* When moving directories cross filesystem boundaries delete the
149 * successfully copied files when all files below the directory and its
150 * subdirectories were processed.
152 * If erase_at_end is FALSE files will be deleted immediately after their
153 * successful copy (Note: this behavior is not tested and at the moment
154 * it can't be changed at runtime).
156 gboolean erase_at_end;
158 /* PID of the child for background operations */
159 pid_t pid;
161 /* toggle if all errors should be ignored */
162 gboolean skip_all;
164 /* Whether the file operation is in pause */
165 gboolean suspended;
167 /* User interface data goes here */
168 void *ui;
169 } FileOpContext;
171 typedef struct
173 size_t progress_count;
174 uintmax_t progress_bytes;
175 uintmax_t copied_bytes;
176 size_t bps;
177 size_t bps_count;
178 struct timeval transfer_start;
179 double eta_secs;
181 gboolean ask_overwrite;
182 } FileOpTotalContext;
184 /*** global variables defined in .c file *********************************************************/
186 extern const char *op_names[3];
188 /*** declarations of public functions ************************************************************/
190 FileOpContext *file_op_context_new (FileOperation op);
191 void file_op_context_destroy (FileOpContext * ctx);
193 FileOpTotalContext *file_op_total_context_new (void);
194 void file_op_total_context_destroy (FileOpTotalContext * tctx);
196 /* The following functions are implemented separately by each port */
197 FileProgressStatus file_progress_real_query_replace (FileOpContext * ctx,
198 enum OperationMode mode,
199 const char *destname,
200 struct stat *_s_stat, struct stat *_d_stat);
202 /*** inline functions ****************************************************************************/
203 #endif /* MC__FILEOPCTX_H */