2 * ROX-Filer, filer for the ROX desktop project
3 * Copyright (C) 2006, Thomas Leonard and others (see changelog for details).
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17 * Place, Suite 330, Boston, MA 02111-1307 USA
20 /* action.c - code for handling the filer action windows.
21 * These routines generally fork() and talk to us via pipes.
29 #include <sys/param.h>
42 #include "gui_support.h"
47 #include "modechange.h"
56 #if defined(HAVE_GETXATTR)
57 # define ATTR_MAN_PAGE N_("See the attr(5) man page for full details.")
58 #elif defined(HAVE_ATTROPEN)
59 # define ATTR_MAN_PAGE N_("See the fsattr(5) man page for full details.")
61 # define ATTR_MAN_PAGE N_("You do not appear to have OS support.")
64 /* Parent->Child messages are one character each:
66 * Y/N Yes/No button clicked
67 * F Force deletion of non-writeable items
69 * E Entry text changed
73 typedef struct _GUIside GUIside
;
74 typedef void ActionChild(gpointer data
);
75 typedef void ForDirCB(const char *path
, const char *dest_path
);
79 ABox
*abox
; /* The action window widget */
81 int from_child
; /* File descriptor */
83 int input_tag
; /* gdk_input_add() */
84 pid_t child
; /* Process ID */
85 int errors
; /* Number of errors so far */
86 gboolean show_info
; /* For Disk Usage */
88 guchar
**default_string
; /* Changed when the entry changes */
89 void (*entry_string_func
)(GtkWidget
*widget
,
90 const guchar
*string
);
95 /* These don't need to be in a structure because we fork() before
98 static gboolean mount_open_dir
= FALSE
;
99 static gboolean mount_mount
= FALSE
; /* (FALSE => unmount) */
100 static int from_parent
= 0;
101 static FILE *to_parent
= NULL
;
102 static gboolean quiet
= FALSE
;
103 static GString
*message
= NULL
;
104 static const char *action_dest
= NULL
;
105 static const char *action_leaf
= NULL
;
106 static void (*action_do_func
)(const char *source
, const char *dest
);
107 static double size_tally
; /* For Disk Usage */
108 static unsigned long dir_counter
; /* For Disk Usage */
109 static unsigned long file_counter
; /* For Disk Usage */
111 static struct mode_change
*mode_change
= NULL
; /* For Permissions */
112 static FindCondition
*find_condition
= NULL
; /* For Find */
113 static MIME_type
*type_change
= NULL
;
115 /* Only used by child */
116 static gboolean o_force
= FALSE
;
117 static gboolean o_brief
= FALSE
;
118 static gboolean o_recurse
= FALSE
;
119 static gboolean o_newer
= FALSE
;
121 static Option o_action_copy
, o_action_move
, o_action_link
;
122 static Option o_action_delete
, o_action_mount
;
123 static Option o_action_force
, o_action_brief
, o_action_recurse
;
124 static Option o_action_newer
;
126 static Option o_action_mount_command
;
127 static Option o_action_umount_command
;
128 static Option o_action_eject_command
;
130 /* Whenever the text in these boxes is changed we store a copy of the new
131 * string to be used as the default next time.
133 static guchar
*last_chmod_string
= NULL
;
134 static guchar
*last_find_string
= NULL
;
135 static guchar
*last_settype_string
= NULL
;
137 /* Set to one of the above before forking. This may change over a call to
138 * reply(). It is reset to NULL once the text is parsed.
140 static guchar
*new_entry_string
= NULL
;
142 /* Static prototypes */
143 static void send_done(void);
144 static void send_check_path(const gchar
*path
);
145 static void send_mount_path(const gchar
*path
);
146 static gboolean
printf_send(const char *msg
, ...);
147 static gboolean
send_msg(void);
148 static gboolean
send_error(void);
149 static gboolean
send_dir(const char *dir
);
150 static gboolean
read_exact(int source
, char *buffer
, ssize_t len
);
151 static void do_mount(const guchar
*path
, gboolean mount
);
152 static gboolean
printf_reply(int fd
, gboolean ignore_quiet
,
153 const char *msg
, ...);
154 static gboolean
remove_pinned_ok(GList
*paths
);
159 /* This is called whenever the user edits the entry box (if any) - send the
162 static void entry_changed(GtkEditable
*entry
, GUIside
*gui_side
)
166 g_return_if_fail(gui_side
->default_string
!= NULL
);
168 text
= gtk_editable_get_chars(entry
, 0, -1);
170 if (gui_side
->entry_string_func
)
171 gui_side
->entry_string_func(GTK_WIDGET(entry
), text
);
173 g_free(*(gui_side
->default_string
));
174 *(gui_side
->default_string
) = text
; /* Gets text's ref */
176 if (!gui_side
->to_child
)
179 fputc('E', gui_side
->to_child
);
180 fputs(text
, gui_side
->to_child
);
181 fputc('\n', gui_side
->to_child
);
182 fflush(gui_side
->to_child
);
185 void show_condition_help(gpointer data
)
190 help
= gtk_dialog_new_with_buttons(
191 _("Find expression reference"),
193 GTK_STOCK_CLOSE
, GTK_RESPONSE_CANCEL
,
195 gtk_dialog_set_default_response(GTK_DIALOG(help
), GTK_RESPONSE_CANCEL
);
197 text
= gtk_label_new(NULL
);
198 gtk_misc_set_padding(GTK_MISC(text
), 2, 2);
199 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(help
)->vbox
), text
);
200 gtk_label_set_selectable(GTK_LABEL(text
), TRUE
);
201 gtk_label_set_markup(GTK_LABEL(text
), _(
202 "<u>Quick Start</u>\n"
203 "Just put the name of the file you're looking for in single quotes:\n"
204 "<b>'index.html'</b> (to find a file called 'index.html')\n"
207 "<b>'*.htm', '*.html'</b> (finds HTML files)\n"
208 "<b>IsDir 'lib'</b> (finds directories called 'lib')\n"
209 "<b>IsReg 'core'</b> (finds a regular file called 'core')\n"
210 "<b>! (IsDir, IsReg)</b> (is neither a directory nor a regular file)\n"
211 "<b>mtime after 1 day ago and size > 1Mb</b> (big, and recently modified)\n"
212 "<b>'CVS' prune, isreg</b> (a regular file not in CVS)\n"
213 "<b>IsReg system(grep -q fred \"%\")</b> (contains the word 'fred')\n"
215 "<u>Simple Tests</u>\n"
216 "<b>IsReg, IsLink, IsDir, IsChar, IsBlock, IsDev, IsPipe, IsSocket, IsDoor</b> "
218 "<b>IsSUID, IsSGID, IsSticky, IsReadable, IsWriteable, IsExecutable</b> "
220 "<b>IsEmpty, IsMine</b>\n"
221 "A pattern in single quotes is a shell-style wildcard pattern to match. If it\n"
222 "contains a slash then the match is against the full path; otherwise it is\n"
223 "against the leafname only.\n"
225 "<u>Comparisons</u>\n"
226 "<b><, <=, =, !=, >, >=, After, Before</b> (compare two values)\n"
227 "<b>5 bytes, 1Kb, 2Mb, 3Gb</b> (file sizes)\n"
228 "<b>2 secs|mins|hours|days|weeks|years ago|hence</b> (times)\n"
229 "<b>atime, ctime, mtime, now, size, inode, nlinks, uid, gid, blocks</b> "
233 "<b>system(command)</b> (true if 'command' returns with a zero exit status;\n"
234 "a % in 'command' is replaced with the path of the current file)\n"
235 "<b>prune</b> (false, and prevents searching the contents of a directory)."));
237 g_signal_connect(help
, "response",
238 G_CALLBACK(gtk_widget_destroy
), NULL
);
240 gtk_widget_show_all(help
);
243 static void show_chmod_help(gpointer data
)
248 help
= gtk_dialog_new_with_buttons(
249 _("Change permissions reference"),
251 GTK_STOCK_CLOSE
, GTK_RESPONSE_CANCEL
,
253 gtk_dialog_set_default_response(GTK_DIALOG(help
), GTK_RESPONSE_CANCEL
);
255 text
= gtk_label_new(NULL
);
256 gtk_misc_set_padding(GTK_MISC(text
), 2, 2);
257 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(help
)->vbox
), text
);
258 gtk_label_set_selectable(GTK_LABEL(text
), TRUE
);
259 gtk_label_set_markup(GTK_LABEL(text
), _(
260 "Normally, you can just select a command from the menu (click \n"
261 "on the arrow beside the command box). Sometimes, you need more...\n"
263 "The format of a command is: <b>CHANGE, CHANGE, ...</b>\n"
264 "Each <b>CHANGE</b> is: <b>WHO HOW PERMISSIONS</b>\n"
265 "<b>WHO</b> is some combination of <b>u</b>, <b>g</b> and <b>o</b> which "
266 "determines whether to\n"
267 "change the permissions for the User (owner), Group or Others.\n"
268 "<b>HOW</b> is <b>+</b>, <b>-</b> or <b>=</b> to add, remove or set "
269 "exactly the permissions.\n"
270 "<b>PERMISSIONS</b> is some combination of the letters <b>rwxXstugo</b>\n"
272 "Bracketed text and spaces are ignored.\n"
275 "<b>u+rw</b>: the file owner gains read and write permission\n"
276 "<b>g=u</b>: the group permissions are set to be the same as the user's\n"
277 "<b>o=u-w</b>: others get the same permissions as the owner, but without "
279 "<b>a+x</b>: <b>a</b>ll get execute/access permission - same as <b>ugo+x</b>\n"
280 "<b>a+X</b>: directories become accessable by everyone; files which were\n"
281 "executable by anyone become executable by everyone\n"
282 "<b>u+rw, go+r</b>: two commands at once!\n"
283 "<b>u+s</b>: set the SetUID bit - often has no effect on script files\n"
284 "<b>755</b>: set the permissions directly\n"
286 "See the chmod(1) man page for full details."));
288 g_signal_connect(help
, "response",
289 G_CALLBACK(gtk_widget_destroy
), NULL
);
291 gtk_widget_show_all(help
);
295 static void show_settype_help(gpointer data
)
300 help
= gtk_dialog_new_with_buttons(
301 _("Set type reference"),
303 GTK_STOCK_CLOSE
, GTK_RESPONSE_CANCEL
,
305 gtk_dialog_set_default_response(GTK_DIALOG(help
), GTK_RESPONSE_CANCEL
);
307 text
= gtk_label_new(NULL
);
308 gtk_misc_set_padding(GTK_MISC(text
), 2, 2);
309 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(help
)->vbox
), text
);
310 gtk_label_set_selectable(GTK_LABEL(text
), TRUE
);
311 gtk_label_set_markup(GTK_LABEL(text
), _(
312 "Normally ROX-Filer determines the type of a regular file\n"
313 "by matching it's name against a pattern. To change the\n"
314 "type of the file you must rename it.\n"
316 "Newer file systems can support something called 'Extended\n"
317 "Attributes' which can be used to store additional data with\n"
318 "each file as named parameters. ROX-Filer uses the\n"
319 "'user.mime_type' attribute to store file types.\n"
321 "File types are only supported for regular files, not\n"
322 "directories, devices, pipes or sockets, and then only\n"
323 "on certain file systems and where the OS implements them.\n"));
325 text
= gtk_label_new(_(ATTR_MAN_PAGE
));
326 gtk_misc_set_padding(GTK_MISC(text
), 2, 2);
327 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(help
)->vbox
), text
);
329 g_signal_connect(help
, "response",
330 G_CALLBACK(gtk_widget_destroy
), NULL
);
332 gtk_widget_show_all(help
);
335 static void process_message(GUIside
*gui_side
, const gchar
*buffer
)
337 ABox
*abox
= gui_side
->abox
;
340 abox_ask(abox
, buffer
+ 1);
341 else if (*buffer
== 's')
342 dir_check_this(buffer
+ 1); /* Update this item */
343 else if (*buffer
== '=')
344 abox_add_filename(abox
, buffer
+ 1);
345 else if (*buffer
== '#')
346 abox_clear_results(abox
);
347 else if (*buffer
== 'X')
349 filer_close_recursive(buffer
+ 1);
350 /* Let child know it's safe to continue... */
351 fputc('X', gui_side
->to_child
);
352 fflush(gui_side
->to_child
);
354 else if (*buffer
== 'm' || *buffer
== 'M')
356 /* Mount / major changes to this path */
360 mount_user_mount(buffer
+ 1);
362 filer_check_mounted(buffer
+ 1);
364 else if (*buffer
== '/')
365 abox_set_current_object(abox
, buffer
+ 1);
366 else if (*buffer
== 'o')
367 filer_opendir(buffer
+ 1, NULL
, NULL
);
368 else if (*buffer
== '!')
371 abox_log(abox
, buffer
+ 1, "error");
373 else if (*buffer
== '<')
374 abox_set_file(abox
, 0, buffer
+1);
375 else if (*buffer
== '>')
377 abox_set_file(abox
, 1, buffer
+1);
378 abox_show_compare(abox
, TRUE
);
380 else if (*buffer
== '%')
382 abox_set_percentage(abox
, atoi(buffer
+1));
385 abox_log(abox
, buffer
+ 1, NULL
);
388 /* Called when the child sends us a message */
389 static void message_from_child(gpointer data
,
391 GdkInputCondition condition
)
394 GUIside
*gui_side
= (GUIside
*) data
;
395 ABox
*abox
= gui_side
->abox
;
396 GtkTextBuffer
*text_buffer
;
398 text_buffer
= gtk_text_view_get_buffer(GTK_TEXT_VIEW(abox
->log
));
400 if (read_exact(source
, buf
, 4))
406 message_len
= strtol(buf
, NULL
, 16);
407 buffer
= g_malloc(message_len
+ 1);
408 if (message_len
> 0 && read_exact(source
, buffer
, message_len
))
410 buffer
[message_len
] = '\0';
411 process_message(gui_side
, buffer
);
415 g_printerr("Child died in the middle of a message.\n");
418 if (gui_side
->abort_attempts
)
419 abox_log(abox
, _("\nProcess terminated.\n"), "error");
421 /* The child is dead */
424 fclose(gui_side
->to_child
);
425 gui_side
->to_child
= NULL
;
426 close(gui_side
->from_child
);
427 g_source_remove(gui_side
->input_tag
);
428 abox_cancel_ask(gui_side
->abox
);
430 if (gui_side
->errors
)
434 if (gui_side
->errors
== 1)
435 report
= g_strdup(_("There was one error.\n"));
437 report
= g_strdup_printf(_("There were %d errors.\n"),
440 gtk_text_buffer_insert_at_cursor(text_buffer
, report
, -1);
444 else if (gui_side
->show_info
== FALSE
)
445 gtk_widget_destroy(GTK_WIDGET(gui_side
->abox
));
448 /* Scans src_dir, calling cb(item, dest_path) for each item */
449 static void for_dir_contents(ForDirCB
*cb
,
451 const char *dest_path
)
455 GList
*list
= NULL
, *next
;
457 d
= mc_opendir(src_dir
);
460 /* Message displayed is "ERROR reading 'path': message" */
461 printf_send("!%s '%s': %s\n", _("ERROR reading"),
462 src_dir
, g_strerror(errno
));
468 while ((ent
= mc_readdir(d
)))
470 if (ent
->d_name
[0] == '.' && (ent
->d_name
[1] == '\0'
471 || (ent
->d_name
[1] == '.' && ent
->d_name
[2] == '\0')))
473 list
= g_list_prepend(list
, g_strdup(make_path(src_dir
,
478 for (next
= list
; next
; next
= next
->next
)
480 cb((char *) next
->data
, dest_path
);
487 /* Read this many bytes into the buffer. TRUE on success. */
488 static gboolean
read_exact(int source
, char *buffer
, ssize_t len
)
493 got
= read(source
, buffer
, len
);
502 static void send_done(void)
504 printf_send(_("'\nDone\n"));
507 /* Notify the filer that this item has been updated */
508 static void send_check_path(const gchar
*path
)
510 printf_send("s%s", path
);
513 /* Notify the filer that this whole subtree has changed (eg, been unmounted) */
514 static void send_mount_path(const gchar
*path
)
516 printf_send("m%s", path
);
519 /* Send a message to the filer process. The first character indicates the
520 * type of the message.
522 static gboolean
printf_send(const char *msg
, ...)
528 tmp
= g_strdup_vprintf(msg
, args
);
531 g_string_assign(message
, tmp
);
537 /* Send 'message' to our parent process. TRUE on success. */
538 static gboolean
send_msg(void)
543 g_return_val_if_fail(message
->len
< 0xffff, FALSE
);
545 sprintf(len_buffer
, "%04" G_GSIZE_MODIFIER
"x", message
->len
);
546 fwrite(len_buffer
, 1, 4, to_parent
);
547 len
= fwrite(message
->str
, 1, message
->len
, to_parent
);
549 return len
== (ssize_t
) message
->len
;
552 /* Set the directory indicator at the top of the window */
553 static gboolean
send_dir(const char *dir
)
555 return printf_send("/%s", dir
);
558 static gboolean
send_error(void)
560 return printf_send("!%s: %s\n", _("ERROR"), g_strerror(errno
));
563 static void response(GtkDialog
*dialog
, gint response
, GUIside
*gui_side
)
567 if (!gui_side
->to_child
)
570 if (response
== GTK_RESPONSE_YES
)
572 else if (response
== GTK_RESPONSE_NO
)
577 fputc(code
, gui_side
->to_child
);
578 fflush(gui_side
->to_child
);
579 abox_show_compare(gui_side
->abox
, FALSE
);
582 static void flag_toggled(ABox
*abox
, gint flag
, GUIside
*gui_side
)
584 if (!gui_side
->to_child
)
587 fputc(flag
, gui_side
->to_child
);
588 fflush(gui_side
->to_child
);
591 static void read_new_entry_text(void)
597 new = g_string_new(NULL
);
601 len
= read(from_parent
, &c
, 1);
604 fprintf(stderr
, "read() error: %s\n",
606 _exit(1); /* Parent died? */
611 g_string_append_c(new, c
);
614 g_free(new_entry_string
);
615 new_entry_string
= new->str
;
616 g_string_free(new, FALSE
);
619 static void process_flag(char flag
)
630 o_recurse
= !o_recurse
;
639 read_new_entry_text();
642 printf_send("!ERROR: Bad message '%c'\n", flag
);
647 /* If the parent has sent any flag toggles, read them */
648 static void check_flags(void)
659 FD_SET(from_parent
, &set
);
662 got
= select(from_parent
+ 1, &set
, NULL
, NULL
, &tv
);
665 g_error("select() failed: %s\n", g_strerror(errno
));
669 got
= read(from_parent
, &retval
, 1);
671 g_error("read() error: %s\n", g_strerror(errno
));
673 process_flag(retval
);
677 /* Read until the user sends a reply. If ignore_quiet is TRUE then
678 * the user MUST click Yes or No, else treat quiet on as Yes.
679 * If the user needs prompting then does send_msg().
681 static gboolean
printf_reply(int fd
, gboolean ignore_quiet
,
682 const char *msg
, ...)
689 if (quiet
&& !ignore_quiet
)
693 tmp
= g_strdup_vprintf(msg
, args
);
696 g_string_assign(message
, tmp
);
703 len
= read(fd
, &retval
, 1);
706 fprintf(stderr
, "read() error: %s\n",
708 _exit(1); /* Parent died? */
714 printf_send("' %s\n", _("Yes"));
717 printf_send("' %s\n", _("No"));
720 process_flag(retval
);
726 static void abort_operation(GtkWidget
*widget
, gpointer data
)
728 GUIside
*gui_side
= (GUIside
*) data
;
732 if (gui_side
->abort_attempts
== 0)
734 abox_log(ABOX(widget
),
735 _("\nAsking child process to terminate...\n"),
737 kill(-gui_side
->child
, SIGTERM
);
741 abox_log(ABOX(widget
),
742 _("\nTrying to KILL run-away process...\n"),
744 kill(-gui_side
->child
, SIGKILL
);
745 kill(-gui_side
->child
, SIGCONT
);
747 gui_side
->abort_attempts
++;
750 gtk_widget_destroy(widget
);
753 static void destroy_action_window(GtkWidget
*widget
, gpointer data
)
755 GUIside
*gui_side
= (GUIside
*) data
;
759 kill(-gui_side
->child
, SIGTERM
);
760 fclose(gui_side
->to_child
);
761 close(gui_side
->from_child
);
762 g_source_remove(gui_side
->input_tag
);
770 /* Create two pipes, fork() a child and return a pointer to a GUIside struct
771 * (NULL on failure). The child calls func().
773 static GUIside
*start_action(GtkWidget
*abox
, ActionChild
*func
, gpointer data
,
774 int force
, int brief
, int recurse
, int newer
)
777 int filedes
[4]; /* 0 and 2 are for reading */
780 struct sigaction act
;
784 report_error("pipe: %s", g_strerror(errno
));
785 gtk_widget_destroy(abox
);
789 if (pipe(filedes
+ 2))
793 report_error("pipe: %s", g_strerror(errno
));
794 gtk_widget_destroy(abox
);
798 autoq
= gtk_toggle_button_get_active(
799 GTK_TOGGLE_BUTTON(ABOX(abox
)->quiet
));
810 report_error("fork: %s", g_strerror(errno
));
811 gtk_widget_destroy(abox
);
814 /* We are the child */
816 /* Create a new process group */
821 dir_drop_all_dnotifies();
823 /* Reset the SIGCHLD handler */
824 act
.sa_handler
= SIG_DFL
;
825 sigemptyset(&act
.sa_mask
);
827 sigaction(SIGCHLD
, &act
, NULL
);
829 message
= g_string_new(NULL
);
832 to_parent
= fdopen(filedes
[1], "wb");
833 from_parent
= filedes
[2];
839 /* We are the parent */
842 gui_side
= g_new(GUIside
, 1);
843 gui_side
->from_child
= filedes
[0];
844 gui_side
->to_child
= fdopen(filedes
[3], "wb");
845 gui_side
->child
= child
;
846 gui_side
->errors
= 0;
847 gui_side
->show_info
= FALSE
;
848 gui_side
->default_string
= NULL
;
849 gui_side
->entry_string_func
= NULL
;
850 gui_side
->abort_attempts
= 0;
852 gui_side
->abox
= ABOX(abox
);
853 g_signal_connect(abox
, "destroy",
854 G_CALLBACK(destroy_action_window
), gui_side
);
856 g_signal_connect(abox
, "response", G_CALLBACK(response
), gui_side
);
857 g_signal_connect(abox
, "flag_toggled",
858 G_CALLBACK(flag_toggled
), gui_side
);
859 g_signal_connect(abox
, "abort_operation",
860 G_CALLBACK(abort_operation
), gui_side
);
862 gui_side
->input_tag
= gdk_input_add_full(gui_side
->from_child
,
870 /* ACTIONS ON ONE ITEM */
872 /* These may call themselves recursively, or ask questions, etc */
874 /* Updates the global size_tally, file_counter and dir_counter */
875 static void do_usage(const char *src_path
, const char *unused
)
881 if (mc_lstat(src_path
, &info
))
883 printf_send("'%s:\n", src_path
);
886 else if (S_ISREG(info
.st_mode
) || S_ISLNK(info
.st_mode
))
889 size_tally
+= info
.st_size
;
891 else if (S_ISDIR(info
.st_mode
))
894 if (printf_reply(from_parent
, FALSE
,
895 _("?Count contents of %s?"), src_path
))
898 safe_path
= g_strdup(src_path
);
899 for_dir_contents(do_usage
, safe_path
, safe_path
);
907 /* dest_path is the dir containing src_path */
908 static void do_delete(const char *src_path
, const char *unused
)
916 if (mc_lstat(src_path
, &info
))
922 write_prot
= S_ISLNK(info
.st_mode
) ? FALSE
923 : access(src_path
, W_OK
) != 0;
924 if (write_prot
|| !quiet
)
928 printf_send("<%s", src_path
);
930 res
=printf_reply(from_parent
, write_prot
&& !o_force
,
931 _("?Delete %s'%s'?"),
932 write_prot
? _("WRITE-PROTECTED ") : "",
939 printf_send(_("'Deleting '%s'\n"), src_path
);
941 safe_path
= g_strdup(src_path
);
943 if (S_ISDIR(info
.st_mode
))
945 for_dir_contents(do_delete
, safe_path
, safe_path
);
946 if (rmdir(safe_path
))
952 printf_send(_("'Directory '%s' deleted\n"), safe_path
);
953 send_mount_path(safe_path
);
955 else if (unlink(src_path
))
959 send_check_path(safe_path
);
960 if (strcmp(g_basename(safe_path
), ".DirIcon") == 0)
963 dir
= g_path_get_dirname(safe_path
);
964 send_check_path(dir
);
972 static void do_eject(const char *path
)
974 const char *argv
[]={"sh", "-c", NULL
, NULL
};
982 printf_send("<%s", path
);
984 res
=printf_reply(from_parent
, !o_force
,
992 printf_send(_("'Eject '%s'\n"), path
);
994 /* Need to close all sub-directories now, or we
995 * can't unmount if dnotify is used.
999 printf_send("X%s", path
);
1000 /* Wait until it's safe... */
1001 read(from_parent
, &c
, 1);
1002 g_return_if_fail(c
== 'X');
1005 argv
[2] = build_command_with_path(o_action_eject_command
.value
,
1007 err
= fork_exec_wait((const char**)argv
);
1008 g_free((gchar
*) argv
[2]);
1011 printf_send(_("!%s\neject failed\n"), err
);
1015 printf_send("M%s", path
);
1019 /* path is the item to check. If is is a directory then we may recurse
1020 * (unless prune is used).
1022 static void do_find(const char *path
, const char *unused
)
1030 if (!printf_reply(from_parent
, FALSE
, _("?Check '%s'?"), path
))
1036 if (new_entry_string
)
1038 find_condition_free(find_condition
);
1039 find_condition
= find_compile(new_entry_string
);
1040 null_g_free(&new_entry_string
);
1046 printf_send(_("!Invalid find condition - "
1047 "change it and try again\n"));
1048 if (!printf_reply(from_parent
, TRUE
,
1049 _("?Check '%s'?"), path
))
1053 if (mc_lstat(path
, &info
.stats
))
1056 printf_send(_("'(while checking '%s')\n"), path
);
1060 info
.fullpath
= path
;
1061 time(&info
.now
); /* XXX: Not for each check! */
1063 info
.leaf
= g_basename(path
);
1065 if (find_test_condition(find_condition
, &info
))
1066 printf_send("=%s", path
);
1068 if (S_ISDIR(info
.stats
.st_mode
) && !info
.prune
)
1071 safe_path
= g_strdup(path
);
1072 for_dir_contents(do_find
, safe_path
, safe_path
);
1077 /* Like mode_compile(), but ignores spaces and bracketed bits */
1078 static struct mode_change
*nice_mode_compile(const char *mode_string
,
1079 unsigned int masked_ops
)
1083 struct mode_change
*retval
= NULL
;
1085 new = g_string_new(NULL
);
1087 for (; *mode_string
; mode_string
++)
1089 if (*mode_string
== '(')
1091 if (*mode_string
== ')')
1099 if (brackets
== 0 && *mode_string
!= ' ')
1100 g_string_append_c(new, *mode_string
);
1104 retval
= mode_compile(new->str
, masked_ops
);
1105 g_string_free(new, TRUE
);
1109 static void do_chmod(const char *path
, const char *unused
)
1116 if (mc_lstat(path
, &info
))
1121 if (S_ISLNK(info
.st_mode
))
1127 printf_send("<%s", path
);
1129 res
=printf_reply(from_parent
, FALSE
,
1130 _("?Change permissions of '%s'?"), path
);
1136 printf_send(_("'Changing permissions of '%s'\n"), path
);
1140 if (new_entry_string
)
1143 mode_free(mode_change
);
1144 mode_change
= nice_mode_compile(new_entry_string
,
1146 null_g_free(&new_entry_string
);
1153 _("!Invalid mode command - change it and try again\n"));
1154 if (!printf_reply(from_parent
, TRUE
,
1155 _("?Change permissions of '%s'?"), path
))
1159 if (mc_lstat(path
, &info
))
1164 if (S_ISLNK(info
.st_mode
))
1167 new_mode
= mode_adjust(info
.st_mode
, mode_change
);
1168 if (chmod(path
, new_mode
))
1174 send_check_path(path
);
1176 if (S_ISDIR(info
.st_mode
))
1178 send_mount_path(path
);
1183 safe_path
= g_strdup(path
);
1184 for_dir_contents(do_chmod
, safe_path
, safe_path
);
1190 static void do_settype(const char *path
, const char *unused
)
1196 if (mc_lstat(path
, &info
))
1201 if (S_ISLNK(info
.st_mode
))
1207 printf_send("<%s", path
);
1209 if (S_ISDIR(info
.st_mode
))
1210 res
=printf_reply(from_parent
, FALSE
,
1211 _("?Change contents of '%s'?"), path
);
1213 res
=printf_reply(from_parent
, FALSE
,
1214 _("?Change type of '%s'?"), path
);
1222 if (new_entry_string
)
1224 type_change
= mime_type_lookup(new_entry_string
);
1225 null_g_free(&new_entry_string
);
1231 printf_send(_("!Invalid type - "
1232 "change it and try again\n"));
1233 if (!printf_reply(from_parent
, TRUE
,
1234 _("?Change type of '%s'?"), path
))
1238 if (mc_lstat(path
, &info
))
1243 if (S_ISLNK(info
.st_mode
))
1246 if (S_ISREG(info
.st_mode
))
1250 const char *comment
;
1252 comment
= mime_type_comment(type_change
);
1253 printf_send(_("'Changing type of '%s' to '%s'\n"), path
,
1257 if (xtype_set(path
, type_change
))
1263 send_check_path(path
);
1265 else if (S_ISDIR(info
.st_mode
))
1270 safe_path
= g_strdup(path
);
1271 for_dir_contents(do_settype
, safe_path
, unused
);
1276 printf_send(_("'Not changing type of directory '%s'\n"),
1282 printf_send(_("'Non-regular file '%s' not changed\n"),
1287 /* We want to copy 'object' into directory 'dir'. If 'action_leaf'
1288 * is set then that is the new leafname, otherwise the leafname stays
1291 static const char *make_dest_path(const char *object
, const char *dir
)
1299 leaf
= strrchr(object
, '/');
1301 leaf
= object
; /* Error? */
1306 return make_path(dir
, leaf
);
1309 /* If action_leaf is not NULL it specifies the new leaf name */
1310 static void do_copy2(const char *path
, const char *dest
)
1312 const char *dest_path
;
1314 struct stat dest_info
;
1318 dest_path
= make_dest_path(path
, dest
);
1320 if (mc_lstat(path
, &info
))
1326 if (mc_lstat(dest_path
, &dest_info
) == 0)
1331 merge
= S_ISDIR(info
.st_mode
) && S_ISDIR(dest_info
.st_mode
);
1333 if (!merge
&& o_newer
&& info
.st_mtime
> dest_info
.st_mtime
)
1335 /* Newer; keep going */
1339 printf_send("<%s", path
);
1340 printf_send(">%s", dest_path
);
1341 if (!printf_reply(from_parent
, TRUE
,
1342 _("?'%s' already exists - %s?"),
1344 merge
? _("merge contents")
1351 if (S_ISDIR(dest_info
.st_mode
))
1352 err
= rmdir(dest_path
);
1354 err
= unlink(dest_path
);
1359 if (errno
!= ENOENT
)
1361 printf_send(_("'Trying copy anyway...\n"));
1367 printf_send("<%s", path
);
1369 if (!printf_reply(from_parent
, FALSE
,
1370 _("?Copy %s as %s?"), path
, dest_path
))
1373 else if (!o_brief
|| S_ISDIR(info
.st_mode
))
1374 printf_send(_("'Copying %s as %s\n"), path
, dest_path
);
1376 if (S_ISDIR(info
.st_mode
))
1378 mode_t mode
= info
.st_mode
;
1379 char *safe_path
, *safe_dest
;
1380 struct stat dest_info
;
1383 safe_path
= g_strdup(path
);
1384 safe_dest
= g_strdup(dest_path
);
1386 exists
= !mc_lstat(dest_path
, &dest_info
);
1388 if (exists
&& !S_ISDIR(dest_info
.st_mode
))
1389 printf_send(_("!ERROR: Destination already exists, "
1390 "but is not a directory\n"));
1391 else if (exists
== FALSE
&& mkdir(dest_path
, 0700 | mode
))
1396 /* (just been created then) */
1397 send_check_path(dest_path
);
1400 for_dir_contents(do_copy2
, safe_path
, safe_dest
);
1401 /* Note: dest_path now invalid... */
1407 /* We may have created the directory with
1408 * more permissions than the source so that
1409 * we could write to it... change it back now.
1411 if (chmod(safe_dest
, mode
))
1413 /* Some filesystems don't support
1414 * SetGID and SetUID bits. Ignore
1421 /* Also, try to preserve the timestamps */
1422 utb
.actime
= info
.st_atime
;
1423 utb
.modtime
= info
.st_mtime
;
1425 utime(safe_dest
, &utb
);
1432 else if (S_ISLNK(info
.st_mode
))
1436 /* Not all versions of cp(1) can make symlinks,
1437 * so we special-case it.
1440 target
= readlink_dup(path
);
1443 if (symlink(target
, dest_path
))
1446 send_check_path(dest_path
);
1457 error
= copy_file(path
, dest_path
);
1461 printf_send(_("!%s\nFailed to copy '%s'\n"),
1466 send_check_path(dest_path
);
1470 /* If action_leaf is not NULL it specifies the new leaf name */
1471 static void do_move2(const char *path
, const char *dest
)
1473 const char *dest_path
;
1474 const char *argv
[] = {"mv", "-f", NULL
, NULL
, NULL
};
1481 dest_path
= make_dest_path(path
, dest
);
1483 is_dir
= mc_lstat(path
, &info2
) == 0 && S_ISDIR(info2
.st_mode
);
1485 if (access(dest_path
, F_OK
) == 0)
1490 if (mc_lstat(dest_path
, &info
))
1496 if (!is_dir
&& o_newer
&& info2
.st_mtime
> info
.st_mtime
)
1498 /* Newer; keep going */
1502 printf_send("<%s", path
);
1503 printf_send(">%s", dest_path
);
1504 if (!printf_reply(from_parent
, TRUE
,
1505 _("?'%s' already exists - overwrite?"),
1510 if (S_ISDIR(info
.st_mode
))
1511 err
= rmdir(dest_path
);
1513 err
= unlink(dest_path
);
1518 if (errno
!= ENOENT
)
1520 printf_send(_("'Trying move anyway...\n"));
1525 printf_send("<%s", path
);
1527 if (!printf_reply(from_parent
, FALSE
,
1528 _("?Move %s as %s?"), path
, dest_path
))
1532 printf_send(_("'Moving %s as %s\n"), path
, dest_path
);
1535 argv
[3] = dest_path
;
1537 err
= fork_exec_wait(argv
);
1540 printf_send(_("!%s\nFailed to move %s as %s\n"),
1541 err
, path
, dest_path
);
1546 send_check_path(dest_path
);
1549 send_mount_path(path
);
1551 send_check_path(path
);
1555 /* Copy path to dest.
1556 * Check that path not copied into itself.
1558 static void do_copy(const char *path
, const char *dest
)
1560 if (is_sub_dir(make_dest_path(path
, dest
), path
))
1561 printf_send(_("!ERROR: Can't copy object into itself\n"));
1564 do_copy2(path
, dest
);
1565 send_check_path(dest
);
1569 /* Move path to dest.
1570 * Check that path not moved into itself.
1572 static void do_move(const char *path
, const char *dest
)
1574 if (is_sub_dir(make_dest_path(path
, dest
), path
))
1576 _("!ERROR: Can't move/rename object into itself\n"));
1579 do_move2(path
, dest
);
1580 send_check_path(dest
);
1584 /* Common code for do_link_relative() and do_link_absolute(). */
1585 static void do_link(const char *path
, const char *dest_path
)
1588 printf_send(_("'Linking %s as %s\n"), path
, dest_path
);
1590 printf_send("<%s", path
);
1592 if (!printf_reply(from_parent
, FALSE
,
1593 _("?Link %s as %s?"), path
, dest_path
))
1597 if (symlink(path
, dest_path
))
1600 send_check_path(dest_path
);
1603 static void do_link_relative(const char *path
, const char *dest
)
1606 const char *dest_path
;
1608 dest_path
= make_dest_path(path
, dest
);
1612 rel_path
= get_relative_path(dest_path
, path
);
1613 do_link(rel_path
, dest_path
);
1617 static void do_link_absolute(const char *path
, const char *dest
)
1620 do_link(path
, make_dest_path(path
, dest
));
1623 /* Mount/umount this item (depending on 'mount') */
1624 static void do_mount(const guchar
*path
, gboolean mount
)
1626 const char *argv
[] = {"sh", "-c", NULL
, NULL
};
1631 argv
[2] = build_command_with_path(mount
? o_action_mount_command
.value
1632 : o_action_umount_command
.value
,
1636 printf_send(mount
? _("'Mounting %s\n")
1637 : _("'Unmounting %s\n"),
1639 else if (!printf_reply(from_parent
, FALSE
,
1640 mount
? _("?Mount %s?")
1641 : _("?Unmount %s?"),
1648 /* Need to close all sub-directories now, or we
1649 * can't unmount if dnotify is used.
1651 printf_send("X%s", path
);
1652 /* Wait until it's safe... */
1653 read(from_parent
, &c
, 1);
1654 g_return_if_fail(c
== 'X');
1657 err
= fork_exec_wait(argv
);
1658 g_free((gchar
*) argv
[2]);
1662 _("!%s\nMount failed\n") :
1663 _("!%s\nUnmount failed\n"), err
);
1666 /* Mount may have worked even on error, eg if we try to mount
1667 * a read-only disk read/write, it gets mounted read-only
1670 if (mount
&& mount_is_mounted(path
, NULL
, NULL
))
1671 printf_send(_("'(seems to be mounted now anyway)\n"));
1676 printf_send("M%s", path
);
1677 if (mount
&& mount_open_dir
)
1678 printf_send("o%s", path
);
1681 /* CHILD MAIN LOOPS */
1683 /* After forking, the child calls one of these functions */
1685 /* We use a double for total size in order to count beyond 4Gb */
1686 static void usage_cb(gpointer data
)
1688 GList
*paths
= (GList
*) data
;
1689 double total_size
= 0;
1692 n
=g_list_length(paths
);
1693 dir_counter
= file_counter
= 0;
1695 for (i
=0; paths
; paths
= paths
->next
, i
++)
1697 guchar
*path
= (guchar
*) paths
->data
;
1706 printf_send("%%%d", per
);
1708 do_usage(path
, NULL
);
1710 printf_send("'%s: %s\n",
1712 format_double_size(size_tally
));
1713 total_size
+= size_tally
;
1715 printf_send("%%-1");
1717 g_string_printf(message
, _("'\nTotal: %s ("),
1718 format_double_size(total_size
));
1721 g_string_append_printf(message
,
1722 "%ld %s%s", file_counter
,
1723 file_counter
== 1 ? _("file") : _("files"),
1724 dir_counter
? ", " : ")\n");
1726 if (file_counter
== 0 && dir_counter
== 0)
1727 g_string_append(message
, _("no directories)\n"));
1728 else if (dir_counter
)
1729 g_string_append_printf(message
,
1730 "%ld %s)\n", dir_counter
,
1731 dir_counter
== 1 ? _("directory")
1732 : _("directories"));
1737 #ifdef DO_MOUNT_POINTS
1738 static void mount_cb(gpointer data
)
1740 GList
*paths
= (GList
*) data
;
1741 gboolean mount_points
= FALSE
;
1744 n
=g_list_length(paths
);
1745 for (i
=0; paths
; paths
= paths
->next
, i
++)
1747 guchar
*path
= (guchar
*) paths
->data
;
1750 target
= pathdup(path
);
1757 printf_send("%%%d", per
);
1759 if (mount_is_mounted(target
, NULL
, NULL
) ||
1760 g_hash_table_lookup(fstab_mounts
, target
))
1762 mount_points
= TRUE
;
1763 do_mount(target
, mount_mount
); /* Mount */
1773 printf_send(_("!No mount points selected!\n"));
1777 /* (use g_dirname() instead?) */
1778 static guchar
*dirname(guchar
*path
)
1782 slash
= strrchr(path
, '/');
1783 g_return_val_if_fail(slash
!= NULL
, g_strdup(path
));
1786 return g_strndup(path
, slash
- path
);
1787 return g_strdup("/");
1790 static void delete_cb(gpointer data
)
1792 GList
*paths
= (GList
*) data
;
1795 n
=g_list_length(paths
);
1796 for (i
=0; paths
; paths
= paths
->next
, i
++)
1798 guchar
*path
= (guchar
*) paths
->data
;
1801 dir
= dirname(path
);
1807 printf_send("%%%d", per
);
1809 do_delete(path
, dir
);
1817 static void eject_cb(gpointer data
)
1819 GList
*paths
= (GList
*) data
;
1822 n
=g_list_length(paths
);
1824 for (i
=0; paths
; paths
= paths
->next
, i
++)
1826 guchar
*path
= (guchar
*) paths
->data
;
1831 printf_send("%%%d", per
);
1841 static void find_cb(gpointer data
)
1843 GList
*all_paths
= (GList
*) data
;
1848 for (paths
= all_paths
; paths
; paths
= paths
->next
)
1850 guchar
*path
= (guchar
*) paths
->data
;
1854 do_find(path
, NULL
);
1857 if (!printf_reply(from_parent
, TRUE
,
1858 _("?Another search?")))
1866 static void chmod_cb(gpointer data
)
1868 GList
*paths
= (GList
*) data
;
1871 n
=g_list_length(paths
);
1873 for (i
=0; paths
; paths
= paths
->next
, i
++)
1875 guchar
*path
= (guchar
*) paths
->data
;
1881 printf_send("%%%d", per
);
1885 if (mc_stat(path
, &info
) != 0)
1887 else if (S_ISLNK(info
.st_mode
))
1888 printf_send(_("!'%s' is a symbolic link\n"),
1891 do_chmod(path
, NULL
);
1897 static void settype_cb(gpointer data
)
1899 GList
*paths
= (GList
*) data
;
1902 n
=g_list_length(paths
);
1904 for (i
=0; paths
; paths
= paths
->next
, i
++)
1906 guchar
*path
= (guchar
*) paths
->data
;
1912 printf_send("%%%d", per
);
1916 if (mc_stat(path
, &info
) != 0)
1918 else if (S_ISLNK(info
.st_mode
))
1919 printf_send(_("!'%s' is a symbolic link\n"),
1922 do_settype(path
, NULL
);
1928 static void list_cb(gpointer data
)
1930 GList
*paths
= (GList
*) data
;
1933 n
=g_list_length(paths
);
1935 for (i
=0; paths
; paths
= paths
->next
, i
++)
1940 printf_send("%%%d", per
);
1942 send_dir((char *) paths
->data
);
1944 action_do_func((char *) paths
->data
, action_dest
);
1950 /* EXTERNAL INTERFACE */
1952 void action_find(GList
*paths
)
1959 report_error(_("You need to select some items "
1960 "to search through"));
1964 if (!last_find_string
)
1965 last_find_string
= g_strdup("'core'");
1967 new_entry_string
= last_find_string
;
1969 abox
= abox_new(_("Find"), FALSE
);
1970 gui_side
= start_action(abox
, find_cb
, paths
,
1971 o_action_force
.int_value
,
1972 o_action_brief
.int_value
,
1973 o_action_recurse
.int_value
,
1974 o_action_newer
.int_value
);
1978 abox_add_results(ABOX(abox
));
1980 gui_side
->default_string
= &last_find_string
;
1981 abox_add_entry(ABOX(abox
), last_find_string
,
1982 new_help_button(show_condition_help
, NULL
));
1983 g_signal_connect(ABOX(abox
)->entry
, "changed",
1984 G_CALLBACK(entry_changed
), gui_side
);
1985 set_find_string_colour(ABOX(abox
)->entry
, last_find_string
);
1987 gui_side
->show_info
= TRUE
;
1988 gui_side
->entry_string_func
= set_find_string_colour
;
1990 number_of_windows
++;
1991 gtk_widget_show(abox
);
1994 /* Count disk space used by selected items */
1995 void action_usage(GList
*paths
)
2002 report_error(_("You need to select some items to count"));
2006 abox
= abox_new(_("Disk Usage"), TRUE
);
2007 if(paths
&& paths
->next
)
2008 abox_set_percentage(ABOX(abox
), 0);
2010 gui_side
= start_action(abox
, usage_cb
, paths
,
2011 o_action_force
.int_value
,
2012 o_action_brief
.int_value
,
2013 o_action_recurse
.int_value
,
2014 o_action_newer
.int_value
);
2018 gui_side
->show_info
= TRUE
;
2020 number_of_windows
++;
2022 gtk_widget_show(abox
);
2025 /* Mount/unmount listed items (paths).
2026 * Free the list after this function returns.
2027 * If open_dir is TRUE and the dir is successfully mounted, open it.
2028 * quiet can be -1 for default.
2030 void action_mount(GList
*paths
, gboolean open_dir
, gboolean mount
, int quiet
)
2032 #ifdef DO_MOUNT_POINTS
2037 quiet
= o_action_mount
.int_value
;
2039 mount_open_dir
= open_dir
;
2040 mount_mount
= mount
;
2042 abox
= abox_new(_("Mount / Unmount"), quiet
);
2043 if(paths
&& paths
->next
)
2044 abox_set_percentage(ABOX(abox
), 0);
2045 gui_side
= start_action(abox
, mount_cb
, paths
,
2046 o_action_force
.int_value
,
2047 o_action_brief
.int_value
,
2048 o_action_recurse
.int_value
,
2049 o_action_newer
.int_value
);
2053 log_info_paths("Mount", paths
, NULL
);
2055 number_of_windows
++;
2056 gtk_widget_show(abox
);
2059 _("ROX-Filer does not yet support mount points on your "
2061 #endif /* DO_MOUNT_POINTS */
2064 /* Delete these paths */
2065 void action_delete(GList
*paths
)
2070 if (!remove_pinned_ok(paths
))
2073 abox
= abox_new(_("Delete"), o_action_delete
.int_value
);
2074 if(paths
&& paths
->next
)
2075 abox_set_percentage(ABOX(abox
), 0);
2076 gui_side
= start_action(abox
, delete_cb
, paths
,
2077 o_action_force
.int_value
,
2078 o_action_brief
.int_value
,
2079 o_action_recurse
.int_value
,
2080 o_action_newer
.int_value
);
2084 abox_add_flag(ABOX(abox
),
2085 _("Force"), _("Don't confirm deletion of non-writeable items"),
2086 'F', o_action_force
.int_value
);
2087 abox_add_flag(ABOX(abox
),
2088 _("Brief"), _("Only log directories being deleted"),
2089 'B', o_action_brief
.int_value
);
2091 log_info_paths("Delete", paths
, NULL
);
2093 number_of_windows
++;
2094 gtk_widget_show(abox
);
2097 /* Change the permissions of the selected items */
2098 void action_chmod(GList
*paths
, gboolean force_recurse
, const char *action
)
2102 static GList
*presets
= NULL
;
2103 gboolean recurse
= force_recurse
|| o_action_recurse
.int_value
;
2107 report_error(_("You need to select the items "
2108 "whose permissions you want to change"));
2114 presets
= g_list_append(presets
, (gchar
*)
2115 _("a+x (Make executable/searchable)"));
2116 presets
= g_list_append(presets
, (gchar
*)
2117 _("a-x (Make non-executable/non-searchable)"));
2118 presets
= g_list_append(presets
, (gchar
*)
2119 _("u+rw (Give owner read+write)"));
2120 presets
= g_list_append(presets
, (gchar
*)
2121 _("go-rwx (Private - owner access only)"));
2122 presets
= g_list_append(presets
, (gchar
*)
2123 _("go=u-w (Public access, not write)"));
2126 if (!last_chmod_string
)
2127 last_chmod_string
= g_strdup((guchar
*) presets
->data
);
2130 new_entry_string
= g_strdup(action
);
2132 new_entry_string
= g_strdup(last_chmod_string
);
2134 abox
= abox_new(_("Permissions"), FALSE
);
2135 if(paths
&& paths
->next
)
2136 abox_set_percentage(ABOX(abox
), 0);
2137 gui_side
= start_action(abox
, chmod_cb
, paths
,
2138 o_action_force
.int_value
,
2139 o_action_brief
.int_value
,
2141 o_action_newer
.int_value
);
2146 abox_add_flag(ABOX(abox
),
2147 _("Brief"), _("Don't list processed files"),
2148 'B', o_action_brief
.int_value
);
2149 abox_add_flag(ABOX(abox
),
2150 _("Recurse"), _("Also change contents of subdirectories"),
2153 gui_side
->default_string
= &last_chmod_string
;
2154 abox_add_combo(ABOX(abox
), _("Command:"), presets
, new_entry_string
,
2155 new_help_button(show_chmod_help
, NULL
));
2157 g_signal_connect(ABOX(abox
)->entry
, "changed",
2158 G_CALLBACK(entry_changed
), gui_side
);
2160 g_signal_connect_swapped(gui_side
->entry
, "activate",
2161 G_CALLBACK(gtk_button_clicked
),
2165 log_info_paths("Change permissions", paths
, NULL
);
2167 number_of_windows
++;
2168 gtk_widget_show(abox
);
2171 null_g_free(&new_entry_string
);
2174 /* Set the MIME type of the selected items */
2175 void action_settype(GList
*paths
, gboolean force_recurse
, const char *oldtype
)
2179 GList
*presets
= NULL
;
2180 gboolean recurse
= force_recurse
|| o_action_recurse
.int_value
;
2184 report_error(_("You need to select the items "
2185 "whose type you want to change"));
2189 if (!last_settype_string
)
2190 last_settype_string
= g_strdup("text/plain");
2193 new_entry_string
= g_strdup(oldtype
);
2195 new_entry_string
= g_strdup(last_settype_string
);
2197 abox
= abox_new(_("Set type"), FALSE
);
2198 if(paths
&& paths
->next
)
2199 abox_set_percentage(ABOX(abox
), 0);
2200 gui_side
= start_action(abox
, settype_cb
, paths
,
2201 o_action_force
.int_value
,
2202 o_action_brief
.int_value
,
2204 o_action_newer
.int_value
);
2209 abox_add_flag(ABOX(abox
),
2210 _("Brief"), _("Don't list processed files"),
2211 'B', o_action_brief
.int_value
);
2212 abox_add_flag(ABOX(abox
),
2213 _("Recurse"), _("Change contents of subdirectories"),
2216 gui_side
->default_string
= &last_settype_string
;
2218 /* Note: get the list again each time -- it can change */
2219 presets
= mime_type_name_list(TRUE
);
2220 abox_add_combo(ABOX(abox
), _("Type:"), presets
, new_entry_string
,
2221 new_help_button(show_settype_help
, NULL
));
2222 g_list_free(presets
);
2224 g_signal_connect(ABOX(abox
)->entry
, "changed",
2225 G_CALLBACK(entry_changed
), gui_side
);
2227 log_info_paths("Set file type", paths
, NULL
);
2229 number_of_windows
++;
2230 gtk_widget_show(abox
);
2233 null_g_free(&new_entry_string
);
2236 static void log_info_paths_leaf(const gchar
*message
, GList
*paths
,
2237 const gchar
*dest
, const char *leaf
)
2241 log_info_paths(message
, paths
, dest
);
2246 new_dest
= g_build_filename(dest
, leaf
, NULL
);
2247 log_info_paths(message
, paths
, new_dest
);
2252 /* If leaf is NULL then the copy has the same name as the original.
2253 * quiet can be -1 for default.
2255 void action_copy(GList
*paths
, const char *dest
, const char *leaf
, int quiet
)
2261 quiet
= o_action_copy
.int_value
;
2265 action_do_func
= do_copy
;
2267 abox
= abox_new(_("Copy"), quiet
);
2268 if(paths
&& paths
->next
)
2269 abox_set_percentage(ABOX(abox
), 0);
2270 gui_side
= start_action(abox
, list_cb
, paths
,
2271 o_action_force
.int_value
,
2272 o_action_brief
.int_value
,
2273 o_action_recurse
.int_value
,
2274 o_action_newer
.int_value
);
2278 abox_add_flag(ABOX(abox
),
2280 _("Only over-write if source is newer than destination."),
2281 'W', o_action_newer
.int_value
);
2282 abox_add_flag(ABOX(abox
),
2283 _("Brief"), _("Only log directories as they are copied"),
2284 'B', o_action_brief
.int_value
);
2286 log_info_paths_leaf("Copy", paths
, dest
, leaf
);
2288 number_of_windows
++;
2289 gtk_widget_show(abox
);
2292 /* If leaf is NULL then the file is not renamed.
2293 * quiet can be -1 for default.
2295 void action_move(GList
*paths
, const char *dest
, const char *leaf
, int quiet
)
2301 quiet
= o_action_move
.int_value
;
2305 action_do_func
= do_move
;
2307 abox
= abox_new(_("Move"), quiet
);
2308 if(paths
&& paths
->next
)
2309 abox_set_percentage(ABOX(abox
), 0);
2310 gui_side
= start_action(abox
, list_cb
, paths
,
2311 o_action_force
.int_value
,
2312 o_action_brief
.int_value
,
2313 o_action_recurse
.int_value
,
2314 o_action_newer
.int_value
);
2318 abox_add_flag(ABOX(abox
),
2320 _("Only over-write if source is newer than destination."),
2321 'W', o_action_newer
.int_value
);
2322 abox_add_flag(ABOX(abox
),
2323 _("Brief"), _("Don't log each file as it is moved"),
2324 'B', o_action_brief
.int_value
);
2326 log_info_paths_leaf("Move", paths
, dest
, leaf
);
2328 number_of_windows
++;
2329 gtk_widget_show(abox
);
2332 /* If leaf is NULL then the link will have the same name */
2333 void action_link(GList
*paths
, const char *dest
, const char *leaf
,
2342 action_do_func
= do_link_relative
;
2344 action_do_func
= do_link_absolute
;
2346 abox
= abox_new(_("Link"), o_action_link
.int_value
);
2347 if(paths
&& paths
->next
)
2348 abox_set_percentage(ABOX(abox
), 0);
2349 gui_side
= start_action(abox
, list_cb
, paths
,
2350 o_action_force
.int_value
,
2351 o_action_brief
.int_value
,
2352 o_action_recurse
.int_value
,
2353 o_action_newer
.int_value
);
2357 log_info_paths_leaf("Link", paths
, dest
, leaf
);
2359 number_of_windows
++;
2360 gtk_widget_show(abox
);
2363 /* Eject these paths */
2364 void action_eject(GList
*paths
)
2369 abox
= abox_new(_("Eject"), TRUE
);
2370 if(paths
&& paths
->next
)
2371 abox_set_percentage(ABOX(abox
), 0);
2372 gui_side
= start_action(abox
, eject_cb
, paths
,
2373 o_action_force
.int_value
,
2374 o_action_brief
.int_value
,
2375 o_action_recurse
.int_value
,
2376 o_action_newer
.int_value
);
2380 log_info_paths("Eject", paths
, NULL
);
2382 number_of_windows
++;
2383 gtk_widget_show(abox
);
2386 void action_init(void)
2388 option_add_int(&o_action_copy
, "action_copy", 1);
2389 option_add_int(&o_action_move
, "action_move", 1);
2390 option_add_int(&o_action_link
, "action_link", 1);
2391 option_add_int(&o_action_delete
, "action_delete", 0);
2392 option_add_int(&o_action_mount
, "action_mount", 1);
2393 option_add_int(&o_action_force
, "action_force", FALSE
);
2394 option_add_int(&o_action_brief
, "action_brief", FALSE
);
2395 option_add_int(&o_action_recurse
, "action_recurse", FALSE
);
2396 option_add_int(&o_action_newer
, "action_newer", FALSE
);
2398 option_add_string(&o_action_mount_command
,
2399 "action_mount_command", "mount");
2400 option_add_string(&o_action_umount_command
,
2401 "action_umount_command", "umount");
2402 option_add_string(&o_action_eject_command
,
2403 "action_eject_command", "eject");
2408 /* Check to see if any of the selected items (or their children) are
2409 * on the pinboard or panel. If so, ask for confirmation.
2411 * TRUE if it's OK to lose them.
2413 static gboolean
remove_pinned_ok(GList
*paths
)
2415 GList
*ask
= NULL
, *next
;
2420 for (; paths
; paths
= paths
->next
)
2422 guchar
*path
= (guchar
*) paths
->data
;
2424 if (icons_require(path
))
2426 if (++ask_n
> MAX_ASK
)
2428 ask
= g_list_append(ask
, path
);
2435 if (ask_n
> MAX_ASK
)
2437 message
= g_string_new(_("Deleting items such as "));
2440 else if (ask_n
== 1)
2441 message
= g_string_new(_("Deleting the item "));
2443 message
= g_string_new(_("Deleting the items "));
2446 for (next
= ask
; next
; next
= next
->next
)
2448 guchar
*path
= (guchar
*) next
->data
;
2451 leaf
= strrchr(path
, '/');
2457 g_string_append_c(message
, '`');
2458 g_string_append(message
, leaf
);
2459 g_string_append_c(message
, '\'');
2461 if (i
== ask_n
- 1 && i
> 0)
2462 g_string_append(message
, _(" and "));
2464 g_string_append(message
, ", ");
2470 message
= g_string_append(message
,
2471 _(" will affect some items on the pinboard "
2472 "or panel - really delete it?"));
2475 if (ask_n
> MAX_ASK
)
2476 message
= g_string_append_c(message
, ',');
2477 message
= g_string_append(message
,
2478 _(" will affect some items on the pinboard "
2479 "or panel - really delete them?"));
2482 retval
= confirm(message
->str
, GTK_STOCK_DELETE
, NULL
);
2484 g_string_free(message
, TRUE
);
2489 void set_find_string_colour(GtkWidget
*widget
, const guchar
*string
)
2491 FindCondition
*cond
;
2493 cond
= find_compile(string
);
2494 entry_set_error(widget
, !cond
);
2496 find_condition_free(cond
);