1 /* 2 * fm-file-ops-job.h 3 * 4 * Copyright 2009 PCMan <pcman.tw@gmail.com> 5 * Copyright 2013-2014 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua> 6 * 7 * This file is a part of the Libfm library. 8 * 9 * This library is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU Lesser General Public 11 * License as published by the Free Software Foundation; either 12 * version 2.1 of the License, or (at your option) any later version. 13 * 14 * This library is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * Lesser General Public License for more details. 18 * 19 * You should have received a copy of the GNU Lesser General Public 20 * License along with this library; if not, write to the Free Software 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 */ 23 24 25 #ifndef __FM_FILE_OPS_JOB_H__ 26 #define __FM_FILE_OPS_JOB_H__ 27 28 #include "fm-job.h" 29 #include "fm-deep-count-job.h" 30 #include "fm-file-info.h" 31 32 G_BEGIN_DECLS 33 34 #define FM_FILE_OPS_JOB_TYPE (fm_file_ops_job_get_type()) 35 #define FM_FILE_OPS_JOB(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),\ 36 FM_FILE_OPS_JOB_TYPE, FmFileOpsJob)) 37 #define FM_FILE_OPS_JOB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),\ 38 FM_FILE_OPS_JOB_TYPE, FmFileOpsJobClass)) 39 #define FM_IS_FILE_OPS_JOB(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),\ 40 FM_FILE_OPS_JOB_TYPE)) 41 #define FM_IS_FILE_OPS_JOB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),\ 42 FM_FILE_OPS_JOB_TYPE)) 43 44 typedef struct _FmFileOpsJob FmFileOpsJob; 45 typedef struct _FmFileOpsJobClass FmFileOpsJobClass; 46 47 /** 48 * FmFileOpType: 49 * @FM_FILE_OP_NONE: dummy 50 * @FM_FILE_OP_MOVE: move file 51 * @FM_FILE_OP_COPY: copy file 52 * @FM_FILE_OP_TRASH: move file to trash can 53 * @FM_FILE_OP_UNTRASH: restore file from trash can 54 * @FM_FILE_OP_DELETE: erase file 55 * @FM_FILE_OP_LINK: create symbolic link 56 * @FM_FILE_OP_CHANGE_ATTR: change file owner and attributes 57 * 58 * Operation for #FmFileOpsJob 59 */ 60 typedef enum { 61 FM_FILE_OP_NONE, 62 FM_FILE_OP_MOVE, 63 FM_FILE_OP_COPY, 64 FM_FILE_OP_TRASH, 65 FM_FILE_OP_UNTRASH, 66 FM_FILE_OP_DELETE, 67 FM_FILE_OP_LINK, 68 FM_FILE_OP_CHANGE_ATTR 69 } FmFileOpType; 70 71 /** 72 * FmFileOpOption: 73 * @FM_FILE_OP_CANCEL: cancel operation 74 * @FM_FILE_OP_OVERWRITE: overwrite existing file 75 * @FM_FILE_OP_RENAME: change name and continue 76 * @FM_FILE_OP_SKIP: skip this file 77 * @FM_FILE_OP_SKIP_ERROR: not supported 78 * 79 * Operation selection on error. 80 */ 81 typedef enum { 82 FM_FILE_OP_CANCEL = 0, 83 FM_FILE_OP_OVERWRITE = 1<<0, 84 FM_FILE_OP_RENAME = 1<<1, 85 FM_FILE_OP_SKIP = 1<<2, 86 FM_FILE_OP_SKIP_ERROR = 1<<3 87 } FmFileOpOption; 88 89 /* FIXME: maybe we should create derived classes for different kind 90 * of file operations rather than use one class to handle all kinds of 91 * file operations. */ 92 93 struct _FmFileOpsJob 94 { 95 FmJob parent; 96 FmFileOpType type; 97 FmPathList* srcs; 98 FmPath* dest; 99 const char* dest_fs_id; 100 101 goffset total; 102 goffset finished; 103 goffset current_file_finished; 104 /* goffset rate; */ 105 guint percent; 106 /* 107 time_t started_time; 108 time_t elapsed_time; 109 time_t remaining_time; 110 FmFileOpOption default_option; 111 */ 112 113 union 114 { 115 gboolean recursive; /* used by chmod/chown only */ 116 gboolean skip_dir_content; /* used by _fm_file_ops_job_copy_file */ 117 }; 118 119 /* for chmod and chown */ 120 gint32 uid; 121 gint32 gid; 122 mode_t new_mode; 123 mode_t new_mode_mask; 124 125 /* for change attributes */ 126 char *display_name; 127 GIcon *icon; 128 char *target; 129 gint8 set_hidden; 130 131 FmFileOpOption supported_options; 132 133 /*< private >*/ 134 gpointer _reserved1; 135 gpointer _reserved2; 136 }; 137 138 /** 139 * FmFileOpsJobClass 140 * @parent_class: the parent class 141 * @prepared: the class closure for the #FmFileOpsJob::prepared signal 142 * @cur_file: the class closure for the #FmFileOpsJob::cur-file signal 143 * @percent: the class closure for the #FmFileOpsJob::percent signal 144 * @ask_rename: the class closure for the #FmFileOpsJob::ask-rename signal 145 */ 146 struct _FmFileOpsJobClass 147 { 148 FmJobClass parent_class; 149 void (*prepared)(FmFileOpsJob* job); 150 void (*cur_file)(FmFileOpsJob* job, const char* file); 151 void (*percent)(FmFileOpsJob* job, guint percent); 152 FmFileOpOption (*ask_rename)(FmFileOpsJob* job, FmFileInfo* src, FmFileInfo* dest, char** new_name); 153 }; 154 155 GType fm_file_ops_job_get_type (void); 156 FmFileOpsJob* fm_file_ops_job_new(FmFileOpType type, FmPathList* files); 157 void fm_file_ops_job_set_dest(FmFileOpsJob* job, FmPath* dest); 158 FmPath* fm_file_ops_job_get_dest(FmFileOpsJob* job); 159 160 /* This only work for change attr jobs. */ 161 void fm_file_ops_job_set_recursive(FmFileOpsJob* job, gboolean recursive); 162 163 void fm_file_ops_job_set_chmod(FmFileOpsJob* job, mode_t new_mode, mode_t new_mode_mask); 164 void fm_file_ops_job_set_chown(FmFileOpsJob* job, gint uid, gint gid); 165 166 /* supported attributes are: display name, icon, hidden, target */ 167 void fm_file_ops_job_set_display_name(FmFileOpsJob *job, const char *name); 168 void fm_file_ops_job_set_icon(FmFileOpsJob *job, GIcon *icon); 169 void fm_file_ops_job_set_hidden(FmFileOpsJob *job, gboolean hidden); 170 void fm_file_ops_job_set_target(FmFileOpsJob *job, const char *url); 171 172 void fm_file_ops_job_emit_prepared(FmFileOpsJob* job); 173 void fm_file_ops_job_emit_cur_file(FmFileOpsJob* job, const char* cur_file); 174 void fm_file_ops_job_emit_percent(FmFileOpsJob* job); 175 FmFileOpOption fm_file_ops_job_ask_rename(FmFileOpsJob* job, GFile* src, GFileInfo* src_inf, GFile* dest, GFile** new_dest); 176 FmFileOpOption _fm_file_ops_job_ask_new_name(FmFileOpsJob* job, GFile* src, 177 GFile* dest, GFile** new_dest, 178 gboolean dest_exists); 179 FmFileOpOption fm_file_ops_job_get_options(FmFileOpsJob* job); 180 181 G_END_DECLS 182 183 #endif /* __FM_FILE_OPS_JOB_H__ */ 184