From 17fd844315b5224663c6f3f816836b3e51ef0e5c Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sat, 17 Aug 2024 16:34:45 +0300 Subject: [PATCH] Move content of src/filemanager/fileopctx.[ch] to src/filemanager/filegui.[ch]. No functional changes. Signed-off-by: Andrew Borodin --- src/background.c | 2 - src/background.h | 3 +- src/filemanager/Makefile.am | 1 - src/filemanager/cmd.c | 2 +- src/filemanager/file.c | 1 - src/filemanager/file.h | 2 +- src/filemanager/filegui.c | 49 +++++++++- src/filemanager/filegui.h | 168 +++++++++++++++++++++++++++++++- src/filemanager/fileopctx.c | 106 -------------------- src/filemanager/fileopctx.h | 189 ------------------------------------ 10 files changed, 218 insertions(+), 305 deletions(-) delete mode 100644 src/filemanager/fileopctx.c delete mode 100644 src/filemanager/fileopctx.h diff --git a/src/background.c b/src/background.c index 72a0eda73..85763daf7 100644 --- a/src/background.c +++ b/src/background.c @@ -51,8 +51,6 @@ #include "lib/event-types.h" #include "lib/util.h" /* my_fork() */ -#include "filemanager/fileopctx.h" /* file_op_context_t */ - #include "background.h" /*** global variables ****************************************************************************/ diff --git a/src/background.h b/src/background.h index a8b03233e..2b25facd2 100644 --- a/src/background.h +++ b/src/background.h @@ -6,7 +6,8 @@ #define MC__BACKGROUND_H #include /* pid_t */ -#include "filemanager/fileopctx.h" +#include "filemanager/filegui.h" + /*** typedefs(not structures) and defined constants **********************************************/ enum TaskState diff --git a/src/filemanager/Makefile.am b/src/filemanager/Makefile.am index 0b3c36556..4ee044757 100644 --- a/src/filemanager/Makefile.am +++ b/src/filemanager/Makefile.am @@ -15,7 +15,6 @@ libmcfilemanager_la_SOURCES = \ filegui.c filegui.h \ filemanager.h filemanager.c \ filenot.c filenot.h \ - fileopctx.c fileopctx.h \ find.c \ hotlist.c hotlist.h \ info.c info.h \ diff --git a/src/filemanager/cmd.c b/src/filemanager/cmd.c index acc53db60..299a79bd4 100644 --- a/src/filemanager/cmd.c +++ b/src/filemanager/cmd.c @@ -76,7 +76,7 @@ #include "src/diffviewer/ydiff.h" #endif -#include "fileopctx.h" +#include "filegui.h" #include "filenot.h" #include "hotlist.h" /* hotlist_show() */ #include "tree.h" /* tree_chdir() */ diff --git a/src/filemanager/file.c b/src/filemanager/file.c index 91ea587ea..0c0b5d3b5 100644 --- a/src/filemanager/file.c +++ b/src/filemanager/file.c @@ -77,7 +77,6 @@ /* Needed for other_panel and WTree */ #include "dir.h" -#include "filegui.h" #include "filenot.h" #include "tree.h" #include "filemanager.h" /* other_panel */ diff --git a/src/filemanager/file.h b/src/filemanager/file.h index 9e84279b4..26d4814a0 100644 --- a/src/filemanager/file.h +++ b/src/filemanager/file.h @@ -10,7 +10,7 @@ #include "lib/global.h" #include "lib/widget.h" -#include "fileopctx.h" +#include "filegui.h" /*** typedefs(not structures) and defined constants **********************************************/ diff --git a/src/filemanager/filegui.c b/src/filemanager/filegui.c index 758775bc3..2e334479f 100644 --- a/src/filemanager/filegui.c +++ b/src/filemanager/filegui.c @@ -155,7 +155,6 @@ statfs (char const *filename, struct fs_info *buf) #include "src/setup.h" /* verbose, safe_overwrite */ #include "filemanager.h" -#include "fileopctx.h" /* FILE_CONT */ #include "filegui.h" @@ -762,6 +761,54 @@ progress_button_callback (WButton *button, int action) /* --------------------------------------------------------------------------------------------- */ /*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ +/** + * \fn file_op_context_t * file_op_context_new (FileOperation op) + * \param op file operation struct + * \return The newly-created context, filled with the default file mask values. + * + * Creates a new file operation context with the default values. If you later want + * to have a user interface for this, call file_progress_ui_create(). + */ + +file_op_context_t * +file_op_context_new (FileOperation op) +{ + file_op_context_t *ctx; + + ctx = g_new0 (file_op_context_t, 1); + ctx->operation = op; + ctx->do_reget = -1; + ctx->stat_func = mc_lstat; + ctx->preserve = TRUE; + ctx->preserve_uidgid = (geteuid () == 0); + ctx->umask_kill = (mode_t) (~0); + ctx->erase_at_end = TRUE; + ctx->ask_overwrite = TRUE; + + return ctx; +} + +/* --------------------------------------------------------------------------------------------- */ +/** + * \fn void file_op_context_destroy (file_op_context_t *ctx) + * \param 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 (file_op_context_t *ctx) +{ + if (ctx != NULL) + { + file_progress_ui_destroy (ctx); + mc_search_free (ctx->search_handle); + g_free (ctx); + } +} + /* --------------------------------------------------------------------------------------------- */ FileProgressStatus diff --git a/src/filemanager/filegui.h b/src/filemanager/filegui.h index 478037495..a42dad329 100644 --- a/src/filemanager/filegui.h +++ b/src/filemanager/filegui.h @@ -1,23 +1,180 @@ /** \file filegui.h - * \brief Header: file management GUI for the text mode edition + * \brief Header: file management GUI */ #ifndef MC__FILEGUI_H #define MC__FILEGUI_H +#include +#include +#include /* uintmax_t */ + #include "lib/global.h" -#include "fileopctx.h" +#include "lib/vfs/vfs.h" /*** typedefs(not structures) and defined constants **********************************************/ +typedef int (*mc_stat_fn) (const vfs_path_t * vpath, struct stat * buf); + /*** enums ***************************************************************************************/ +typedef enum +{ + FILEGUI_DIALOG_ONE_ITEM, + FILEGUI_DIALOG_MULTI_ITEM, + FILEGUI_DIALOG_DELETE_ITEM +} filegui_dialog_type_t; + +typedef enum +{ + OP_COPY = 0, + OP_MOVE = 1, + OP_DELETE = 2 +} FileOperation; + +typedef enum +{ + RECURSIVE_YES = 0, + RECURSIVE_NO = 1, + RECURSIVE_ALWAYS = 2, + RECURSIVE_NEVER = 3, + RECURSIVE_ABORT = 4 +} FileCopyMode; + +/* ATTENTION: avoid overlapping with B_* values (lib/widget/dialog.h) */ +typedef enum +{ + FILE_CONT = 10, + FILE_RETRY, + FILE_SKIP, + FILE_ABORT, + FILE_IGNORE, + FILE_IGNORE_ALL, + FILE_SUSPEND +} FileProgressStatus; + +/* First argument passed to real functions */ +enum OperationMode +{ + Foreground, + Background +}; + /*** structures declarations (and typedefs of structures)*****************************************/ +struct mc_search_struct; + +/* This structure describes a context for file operations. It is used to update + * the progress windows and pass around options. + */ +typedef struct +{ + /* Operation type (copy, move, delete) */ + FileOperation operation; + + /* Start of file transferring */ + gint64 transfer_start; + + /* The estimated time of arrival in seconds */ + double eta_secs; + + /* Transferred bytes per second */ + long bps; + + /* Transferred seconds */ + long bps_time; + + filegui_dialog_type_t dialog_type; + + /* Counters for progress indicators */ + size_t progress_count; + size_t prev_progress_count; /* Used in OP_MOVE between copy and remove directories */ + uintmax_t progress_bytes; + uintmax_t copied_bytes; + + size_t total_count; + uintmax_t total_bytes; + /* Whether the panel total has been computed */ + gboolean totals_computed; + + size_t total_bps; + gint64 total_transfer_start; + double total_eta_secs; + + /* Result from the recursive query */ + FileCopyMode recursive_result; + + /* Whether to do a reget */ + off_t do_reget; + + /* Controls appending to files */ + gboolean do_append; + + /* Whether to stat or lstat */ + gboolean follow_links; + + /* Pointer to the stat function we will use */ + mc_stat_fn stat_func; + + /* Whether to recompute symlinks */ + gboolean stable_symlinks; + + /* Preserve the original files' owner, group, permissions, and + * timestamps (owner, group only as root). + */ + gboolean preserve; + + /* If running as root, preserve the original uid/gid (we don't want to + * try chown for non root) preserve_uidgid = preserve && uid == 0 + */ + gboolean preserve_uidgid; + + /* The bits to preserve in created files' modes on file copy */ + mode_t umask_kill; + + /* The mask of files to actually operate on */ + char *dest_mask; + + /* search handler */ + struct mc_search_struct *search_handle; + + /* Whether to dive into subdirectories for recursive operations */ + gboolean dive_into_subdirs; + + /* When moving directories cross filesystem boundaries delete the + * successfully copied files when all files below the directory and its + * subdirectories were processed. + * + * If erase_at_end is FALSE files will be deleted immediately after their + * successful copy (Note: this behavior is not tested and at the moment + * it can't be changed at runtime). + */ + gboolean erase_at_end; + + /* PID of the child for background operations */ + pid_t pid; + + /* toggle if all errors should be ignored */ + gboolean ignore_all; + + /* Whether the file operation is in pause */ + gboolean suspended; + + gboolean ask_overwrite; + + /* User interface data goes here */ + void *ui; +} file_op_context_t; + /*** global variables defined in .c file *********************************************************/ +extern const char *op_names[3]; + /*** declarations of public functions ************************************************************/ +file_op_context_t *file_op_context_new (FileOperation op); +void file_op_context_destroy (file_op_context_t * ctx); + void file_progress_ui_create (file_op_context_t * ctx, gboolean with_eta, filegui_dialog_type_t dialog_type); void file_progress_ui_destroy (file_op_context_t * ctx); @@ -37,5 +194,12 @@ void file_progress_show_target (file_op_context_t * ctx, const vfs_path_t * vpat gboolean file_progress_show_deleting (file_op_context_t * ctx, const vfs_path_t * vpath, size_t *count); +/* The following functions are implemented separately by each port */ +FileProgressStatus file_progress_real_query_replace (file_op_context_t * ctx, + enum OperationMode mode, const char *src, + struct stat *src_stat, const char *dst, + struct stat *dst_stat); + /*** inline functions ****************************************************************************/ + #endif /* MC__FILEGUI_H */ diff --git a/src/filemanager/fileopctx.c b/src/filemanager/fileopctx.c deleted file mode 100644 index 1d42210a4..000000000 --- a/src/filemanager/fileopctx.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - File operation contexts for the Midnight Commander - - Copyright (C) 1999-2024 - Free Software Foundation, Inc. - - Written by: - Federico Mena - Miguel de Icaza - - This file is part of the Midnight Commander. - - The Midnight Commander is free software: you can redistribute it - and/or modify it under the terms of the GNU General Public License as - published by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - The Midnight Commander is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - */ - -/** \file fileopctx.c - * \brief Source: file operation contexts - * \date 1998-2007 - * \author Federico Mena - * \author Miguel de Icaza - */ - -#include - -#include - -#include "lib/global.h" -#include "fileopctx.h" -#include "filegui.h" -#include "lib/search.h" -#include "lib/vfs/vfs.h" - -/*** global variables ****************************************************************************/ - -/*** file scope macro definitions ****************************************************************/ - -/*** file scope type declarations ****************************************************************/ - -/*** file scope variables ************************************************************************/ - -/*** file scope functions ************************************************************************/ -/* --------------------------------------------------------------------------------------------- */ - -/* --------------------------------------------------------------------------------------------- */ -/*** public functions ****************************************************************************/ -/* --------------------------------------------------------------------------------------------- */ - -/** - * \fn file_op_context_t * file_op_context_new (FileOperation op) - * \param op file operation struct - * \return The newly-created context, filled with the default file mask values. - * - * Creates a new file operation context with the default values. If you later want - * to have a user interface for this, call file_progress_ui_create(). - */ - -file_op_context_t * -file_op_context_new (FileOperation op) -{ - file_op_context_t *ctx; - - ctx = g_new0 (file_op_context_t, 1); - ctx->operation = op; - ctx->do_reget = -1; - ctx->stat_func = mc_lstat; - ctx->preserve = TRUE; - ctx->preserve_uidgid = (geteuid () == 0); - ctx->umask_kill = (mode_t) (~0); - ctx->erase_at_end = TRUE; - ctx->ask_overwrite = TRUE; - - return ctx; -} - -/* --------------------------------------------------------------------------------------------- */ -/** - * \fn void file_op_context_destroy (file_op_context_t *ctx) - * \param 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 (file_op_context_t *ctx) -{ - if (ctx != NULL) - { - file_progress_ui_destroy (ctx); - mc_search_free (ctx->search_handle); - g_free (ctx); - } -} - -/* --------------------------------------------------------------------------------------------- */ diff --git a/src/filemanager/fileopctx.h b/src/filemanager/fileopctx.h deleted file mode 100644 index 4c5dcbc7c..000000000 --- a/src/filemanager/fileopctx.h +++ /dev/null @@ -1,189 +0,0 @@ -/** \file fileopctx.h - * \brief Header: file operation contexts - * \date 1998 - * \author Federico Mena - * \author Miguel de Icaza - */ - -#ifndef MC__FILEOPCTX_H -#define MC__FILEOPCTX_H - -#include -#include -#include /* uintmax_t */ - -#include "lib/global.h" -#include "lib/vfs/vfs.h" - - -/*** typedefs(not structures) and defined constants **********************************************/ - -typedef int (*mc_stat_fn) (const vfs_path_t * vpath, struct stat * buf); - -/*** enums ***************************************************************************************/ - -typedef enum -{ - FILEGUI_DIALOG_ONE_ITEM, - FILEGUI_DIALOG_MULTI_ITEM, - FILEGUI_DIALOG_DELETE_ITEM -} filegui_dialog_type_t; - -typedef enum -{ - OP_COPY = 0, - OP_MOVE = 1, - OP_DELETE = 2 -} FileOperation; - -typedef enum -{ - RECURSIVE_YES = 0, - RECURSIVE_NO = 1, - RECURSIVE_ALWAYS = 2, - RECURSIVE_NEVER = 3, - RECURSIVE_ABORT = 4 -} FileCopyMode; - -/* ATTENTION: avoid overlapping with B_* values (lib/widget/dialog.h) */ -typedef enum -{ - FILE_CONT = 10, - FILE_RETRY, - FILE_SKIP, - FILE_ABORT, - FILE_IGNORE, - FILE_IGNORE_ALL, - FILE_SUSPEND -} FileProgressStatus; - -/* First argument passed to real functions */ -enum OperationMode -{ - Foreground, - Background -}; - -/*** structures declarations (and typedefs of structures)*****************************************/ - -struct mc_search_struct; - -/* This structure describes a context for file operations. It is used to update - * the progress windows and pass around options. - */ -typedef struct -{ - /* Operation type (copy, move, delete) */ - FileOperation operation; - - /* Start of file transferring */ - gint64 transfer_start; - - /* The estimated time of arrival in seconds */ - double eta_secs; - - /* Transferred bytes per second */ - long bps; - - /* Transferred seconds */ - long bps_time; - - filegui_dialog_type_t dialog_type; - - /* Counters for progress indicators */ - size_t progress_count; - size_t prev_progress_count; /* Used in OP_MOVE between copy and remove directories */ - uintmax_t progress_bytes; - uintmax_t copied_bytes; - - size_t total_count; - uintmax_t total_bytes; - /* Whether the panel total has been computed */ - gboolean totals_computed; - - size_t total_bps; - gint64 total_transfer_start; - double total_eta_secs; - - /* Result from the recursive query */ - FileCopyMode recursive_result; - - /* Whether to do a reget */ - off_t do_reget; - - /* Controls appending to files */ - gboolean do_append; - - /* Whether to stat or lstat */ - gboolean follow_links; - - /* Pointer to the stat function we will use */ - mc_stat_fn stat_func; - - /* Whether to recompute symlinks */ - gboolean stable_symlinks; - - /* Preserve the original files' owner, group, permissions, and - * timestamps (owner, group only as root). - */ - gboolean preserve; - - /* If running as root, preserve the original uid/gid (we don't want to - * try chown for non root) preserve_uidgid = preserve && uid == 0 - */ - gboolean preserve_uidgid; - - /* The bits to preserve in created files' modes on file copy */ - mode_t umask_kill; - - /* The mask of files to actually operate on */ - char *dest_mask; - - /* search handler */ - struct mc_search_struct *search_handle; - - /* Whether to dive into subdirectories for recursive operations */ - gboolean dive_into_subdirs; - - /* When moving directories cross filesystem boundaries delete the - * successfully copied files when all files below the directory and its - * subdirectories were processed. - * - * If erase_at_end is FALSE files will be deleted immediately after their - * successful copy (Note: this behavior is not tested and at the moment - * it can't be changed at runtime). - */ - gboolean erase_at_end; - - /* PID of the child for background operations */ - pid_t pid; - - /* toggle if all errors should be ignored */ - gboolean ignore_all; - - /* Whether the file operation is in pause */ - gboolean suspended; - - gboolean ask_overwrite; - - /* User interface data goes here */ - void *ui; -} file_op_context_t; - -/*** global variables defined in .c file *********************************************************/ - -extern const char *op_names[3]; - -/*** declarations of public functions ************************************************************/ - -file_op_context_t *file_op_context_new (FileOperation op); -void file_op_context_destroy (file_op_context_t * ctx); - -/* The following functions are implemented separately by each port */ -FileProgressStatus file_progress_real_query_replace (file_op_context_t * ctx, - enum OperationMode mode, const char *src, - struct stat *src_stat, const char *dst, - struct stat *dst_stat); - -/*** inline functions ****************************************************************************/ -#endif /* MC__FILEOPCTX_H */