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"
55 #if defined(HAVE_GETXATTR)
56 # define ATTR_MAN_PAGE N_("See the attr(5) man page for full details.")
57 #elif defined(HAVE_ATTROPEN)
58 # define ATTR_MAN_PAGE N_("See the fsattr(5) man page for full details.")
60 # define ATTR_MAN_PAGE N_("You do not appear to have OS support.")
63 /* Parent->Child messages are one character each:
65 * Y/N Yes/No button clicked
66 * F Force deletion of non-writeable items
68 * E Entry text changed
72 typedef struct _GUIside GUIside
;
73 typedef void ActionChild(gpointer data
);
74 typedef void ForDirCB(const char *path
, const char *dest_path
);
78 ABox
*abox
; /* The action window widget */
80 int from_child
; /* File descriptor */
82 int input_tag
; /* gdk_input_add() */
83 pid_t child
; /* Process ID */
84 int errors
; /* Number of errors so far */
85 gboolean show_info
; /* For Disk Usage */
87 guchar
**default_string
; /* Changed when the entry changes */
88 void (*entry_string_func
)(GtkWidget
*widget
,
89 const guchar
*string
);
94 /* These don't need to be in a structure because we fork() before
97 static gboolean mount_open_dir
= FALSE
;
98 static gboolean mount_mount
= FALSE
; /* (FALSE => unmount) */
99 static int from_parent
= 0;
100 static FILE *to_parent
= NULL
;
101 static gboolean quiet
= FALSE
;
102 static GString
*message
= NULL
;
103 static const char *action_dest
= NULL
;
104 static const char *action_leaf
= NULL
;
105 static void (*action_do_func
)(const char *source
, const char *dest
);
106 static double size_tally
; /* For Disk Usage */
107 static unsigned long dir_counter
; /* For Disk Usage */
108 static unsigned long file_counter
; /* For Disk Usage */
110 static struct mode_change
*mode_change
= NULL
; /* For Permissions */
111 static FindCondition
*find_condition
= NULL
; /* For Find */
112 static MIME_type
*type_change
= NULL
;
114 /* Only used by child */
115 static gboolean o_force
= FALSE
;
116 static gboolean o_brief
= FALSE
;
117 static gboolean o_recurse
= FALSE
;
118 static gboolean o_newer
= FALSE
;
120 static Option o_action_copy
, o_action_move
, o_action_link
;
121 static Option o_action_delete
, o_action_mount
;
122 static Option o_action_force
, o_action_brief
, o_action_recurse
;
123 static Option o_action_newer
;
125 static Option o_action_mount_command
;
126 static Option o_action_umount_command
;
127 static Option o_action_eject_command
;
129 /* Whenever the text in these boxes is changed we store a copy of the new
130 * string to be used as the default next time.
132 static guchar
*last_chmod_string
= NULL
;
133 static guchar
*last_find_string
= NULL
;
134 static guchar
*last_settype_string
= NULL
;
136 /* Set to one of the above before forking. This may change over a call to
137 * reply(). It is reset to NULL once the text is parsed.
139 static guchar
*new_entry_string
= NULL
;
141 /* Static prototypes */
142 static void send_done(void);
143 static void send_check_path(const gchar
*path
);
144 static void send_mount_path(const gchar
*path
);
145 static gboolean
printf_send(const char *msg
, ...);
146 static gboolean
send_msg(void);
147 static gboolean
send_error(void);
148 static gboolean
send_dir(const char *dir
);
149 static gboolean
read_exact(int source
, char *buffer
, ssize_t len
);
150 static void do_mount(const guchar
*path
, gboolean mount
);
151 static gboolean
printf_reply(int fd
, gboolean ignore_quiet
,
152 const char *msg
, ...);
153 static gboolean
remove_pinned_ok(GList
*paths
);
158 /* This is called whenever the user edits the entry box (if any) - send the
161 static void entry_changed(GtkEditable
*entry
, GUIside
*gui_side
)
165 g_return_if_fail(gui_side
->default_string
!= NULL
);
167 text
= gtk_editable_get_chars(entry
, 0, -1);
169 if (gui_side
->entry_string_func
)
170 gui_side
->entry_string_func(GTK_WIDGET(entry
), text
);
172 g_free(*(gui_side
->default_string
));
173 *(gui_side
->default_string
) = text
; /* Gets text's ref */
175 if (!gui_side
->to_child
)
178 fputc('E', gui_side
->to_child
);
179 fputs(text
, gui_side
->to_child
);
180 fputc('\n', gui_side
->to_child
);
181 fflush(gui_side
->to_child
);
184 void show_condition_help(gpointer data
)
189 help
= gtk_dialog_new_with_buttons(
190 _("Find expression reference"),
192 GTK_STOCK_CLOSE
, GTK_RESPONSE_CANCEL
,
194 gtk_dialog_set_default_response(GTK_DIALOG(help
), GTK_RESPONSE_CANCEL
);
196 text
= gtk_label_new(NULL
);
197 gtk_misc_set_padding(GTK_MISC(text
), 2, 2);
198 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(help
)->vbox
), text
);
199 gtk_label_set_selectable(GTK_LABEL(text
), TRUE
);
200 gtk_label_set_markup(GTK_LABEL(text
), _(
201 "<u>Quick Start</u>\n"
202 "Just put the name of the file you're looking for in single quotes:\n"
203 "<b>'index.html'</b> (to find a file called 'index.html')\n"
206 "<b>'*.htm', '*.html'</b> (finds HTML files)\n"
207 "<b>IsDir 'lib'</b> (finds directories called 'lib')\n"
208 "<b>IsReg 'core'</b> (finds a regular file called 'core')\n"
209 "<b>! (IsDir, IsReg)</b> (is neither a directory nor a regular file)\n"
210 "<b>mtime after 1 day ago and size > 1Mb</b> (big, and recently modified)\n"
211 "<b>'CVS' prune, isreg</b> (a regular file not in CVS)\n"
212 "<b>IsReg system(grep -q fred \"%\")</b> (contains the word 'fred')\n"
214 "<u>Simple Tests</u>\n"
215 "<b>IsReg, IsLink, IsDir, IsChar, IsBlock, IsDev, IsPipe, IsSocket, IsDoor</b> "
217 "<b>IsSUID, IsSGID, IsSticky, IsReadable, IsWriteable, IsExecutable</b> "
219 "<b>IsEmpty, IsMine</b>\n"
220 "A pattern in single quotes is a shell-style wildcard pattern to match. If it\n"
221 "contains a slash then the match is against the full path; otherwise it is\n"
222 "against the leafname only.\n"
224 "<u>Comparisons</u>\n"
225 "<b><, <=, =, !=, >, >=, After, Before</b> (compare two values)\n"
226 "<b>5 bytes, 1Kb, 2Mb, 3Gb</b> (file sizes)\n"
227 "<b>2 secs|mins|hours|days|weeks|years ago|hence</b> (times)\n"
228 "<b>atime, ctime, mtime, now, size, inode, nlinks, uid, gid, blocks</b> "
232 "<b>system(command)</b> (true if 'command' returns with a zero exit status;\n"
233 "a % in 'command' is replaced with the path of the current file)\n"
234 "<b>prune</b> (false, and prevents searching the contents of a directory)."));
236 g_signal_connect(help
, "response",
237 G_CALLBACK(gtk_widget_destroy
), NULL
);
239 gtk_widget_show_all(help
);
242 static void show_chmod_help(gpointer data
)
247 help
= gtk_dialog_new_with_buttons(
248 _("Change permissions reference"),
250 GTK_STOCK_CLOSE
, GTK_RESPONSE_CANCEL
,
252 gtk_dialog_set_default_response(GTK_DIALOG(help
), GTK_RESPONSE_CANCEL
);
254 text
= gtk_label_new(NULL
);
255 gtk_misc_set_padding(GTK_MISC(text
), 2, 2);
256 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(help
)->vbox
), text
);
257 gtk_label_set_selectable(GTK_LABEL(text
), TRUE
);
258 gtk_label_set_markup(GTK_LABEL(text
), _(
259 "Normally, you can just select a command from the menu (click \n"
260 "on the arrow beside the command box). Sometimes, you need more...\n"
262 "The format of a command is: <b>CHANGE, CHANGE, ...</b>\n"
263 "Each <b>CHANGE</b> is: <b>WHO HOW PERMISSIONS</b>\n"
264 "<b>WHO</b> is some combination of <b>u</b>, <b>g</b> and <b>o</b> which "
265 "determines whether to\n"
266 "change the permissions for the User (owner), Group or Others.\n"
267 "<b>HOW</b> is <b>+</b>, <b>-</b> or <b>=</b> to add, remove or set "
268 "exactly the permissions.\n"
269 "<b>PERMISSIONS</b> is some combination of the letters <b>rwxXstugo</b>\n"
271 "Bracketed text and spaces are ignored.\n"
274 "<b>u+rw</b>: the file owner gains read and write permission\n"
275 "<b>g=u</b>: the group permissions are set to be the same as the user's\n"
276 "<b>o=u-w</b>: others get the same permissions as the owner, but without "
278 "<b>a+x</b>: <b>a</b>ll get execute/access permission - same as <b>ugo+x</b>\n"
279 "<b>a+X</b>: directories become accessable by everyone; files which were\n"
280 "executable by anyone become executable by everyone\n"
281 "<b>u+rw, go+r</b>: two commands at once!\n"
282 "<b>u+s</b>: set the SetUID bit - often has no effect on script files\n"
283 "<b>755</b>: set the permissions directly\n"
285 "See the chmod(1) man page for full details."));
287 g_signal_connect(help
, "response",
288 G_CALLBACK(gtk_widget_destroy
), NULL
);
290 gtk_widget_show_all(help
);
294 static void show_settype_help(gpointer data
)
299 help
= gtk_dialog_new_with_buttons(
300 _("Set type reference"),
302 GTK_STOCK_CLOSE
, GTK_RESPONSE_CANCEL
,
304 gtk_dialog_set_default_response(GTK_DIALOG(help
), GTK_RESPONSE_CANCEL
);
306 text
= gtk_label_new(NULL
);
307 gtk_misc_set_padding(GTK_MISC(text
), 2, 2);
308 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(help
)->vbox
), text
);
309 gtk_label_set_selectable(GTK_LABEL(text
), TRUE
);
310 gtk_label_set_markup(GTK_LABEL(text
), _(
311 "Normally ROX-Filer determines the type of a regular file\n"
312 "by matching it's name against a pattern. To change the\n"
313 "type of the file you must rename it.\n"
315 "Newer file systems can support something called 'Extended\n"
316 "Attributes' which can be used to store additional data with\n"
317 "each file as named parameters. ROX-Filer uses the\n"
318 "'user.mime_type' attribute to store file types.\n"
320 "File types are only supported for regular files, not\n"
321 "directories, devices, pipes or sockets, and then only\n"
322 "on certain file systems and where the OS implements them.\n"));
324 text
= gtk_label_new(_(ATTR_MAN_PAGE
));
325 gtk_misc_set_padding(GTK_MISC(text
), 2, 2);
326 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(help
)->vbox
), text
);
328 g_signal_connect(help
, "response",
329 G_CALLBACK(gtk_widget_destroy
), NULL
);
331 gtk_widget_show_all(help
);
334 static void process_message(GUIside
*gui_side
, const gchar
*buffer
)
336 ABox
*abox
= gui_side
->abox
;
339 abox_ask(abox
, buffer
+ 1);
340 else if (*buffer
== 's')
341 dir_check_this(buffer
+ 1); /* Update this item */
342 else if (*buffer
== '=')
343 abox_add_filename(abox
, buffer
+ 1);
344 else if (*buffer
== '#')
345 abox_clear_results(abox
);
346 else if (*buffer
== 'X')
348 filer_close_recursive(buffer
+ 1);
349 /* Let child know it's safe to continue... */
350 fputc('X', gui_side
->to_child
);
351 fflush(gui_side
->to_child
);
353 else if (*buffer
== 'm' || *buffer
== 'M')
355 /* Mount / major changes to this path */
359 mount_user_mount(buffer
+ 1);
361 filer_check_mounted(buffer
+ 1);
363 else if (*buffer
== '/')
364 abox_set_current_object(abox
, buffer
+ 1);
365 else if (*buffer
== 'o')
366 filer_opendir(buffer
+ 1, NULL
, NULL
);
367 else if (*buffer
== '!')
370 abox_log(abox
, buffer
+ 1, "error");
372 else if (*buffer
== '<')
373 abox_set_file(abox
, 0, buffer
+1);
374 else if (*buffer
== '>')
376 abox_set_file(abox
, 1, buffer
+1);
377 abox_show_compare(abox
, TRUE
);
379 else if (*buffer
== '%')
381 abox_set_percentage(abox
, atoi(buffer
+1));
384 abox_log(abox
, buffer
+ 1, NULL
);
387 /* Called when the child sends us a message */
388 static void message_from_child(gpointer data
,
390 GdkInputCondition condition
)
393 GUIside
*gui_side
= (GUIside
*) data
;
394 ABox
*abox
= gui_side
->abox
;
395 GtkTextBuffer
*text_buffer
;
397 text_buffer
= gtk_text_view_get_buffer(GTK_TEXT_VIEW(abox
->log
));
399 if (read_exact(source
, buf
, 4))
405 message_len
= strtol(buf
, NULL
, 16);
406 buffer
= g_malloc(message_len
+ 1);
407 if (message_len
> 0 && read_exact(source
, buffer
, message_len
))
409 buffer
[message_len
] = '\0';
410 process_message(gui_side
, buffer
);
414 g_printerr("Child died in the middle of a message.\n");
417 if (gui_side
->abort_attempts
)
418 abox_log(abox
, _("\nProcess terminated.\n"), "error");
420 /* The child is dead */
423 fclose(gui_side
->to_child
);
424 gui_side
->to_child
= NULL
;
425 close(gui_side
->from_child
);
426 g_source_remove(gui_side
->input_tag
);
427 abox_cancel_ask(gui_side
->abox
);
429 if (gui_side
->errors
)
433 if (gui_side
->errors
== 1)
434 report
= g_strdup(_("There was one error.\n"));
436 report
= g_strdup_printf(_("There were %d errors.\n"),
439 gtk_text_buffer_insert_at_cursor(text_buffer
, report
, -1);
443 else if (gui_side
->show_info
== FALSE
)
444 gtk_widget_destroy(GTK_WIDGET(gui_side
->abox
));
447 /* Scans src_dir, calling cb(item, dest_path) for each item */
448 static void for_dir_contents(ForDirCB
*cb
,
450 const char *dest_path
)
454 GList
*list
= NULL
, *next
;
456 d
= mc_opendir(src_dir
);
459 /* Message displayed is "ERROR reading 'path': message" */
460 printf_send("!%s '%s': %s\n", _("ERROR reading"),
461 src_dir
, g_strerror(errno
));
467 while ((ent
= mc_readdir(d
)))
469 if (ent
->d_name
[0] == '.' && (ent
->d_name
[1] == '\0'
470 || (ent
->d_name
[1] == '.' && ent
->d_name
[2] == '\0')))
472 list
= g_list_prepend(list
, g_strdup(make_path(src_dir
,
477 for (next
= list
; next
; next
= next
->next
)
479 cb((char *) next
->data
, dest_path
);
486 /* Read this many bytes into the buffer. TRUE on success. */
487 static gboolean
read_exact(int source
, char *buffer
, ssize_t len
)
492 got
= read(source
, buffer
, len
);
501 static void send_done(void)
503 printf_send(_("'\nDone\n"));
506 /* Notify the filer that this item has been updated */
507 static void send_check_path(const gchar
*path
)
509 printf_send("s%s", path
);
512 /* Notify the filer that this whole subtree has changed (eg, been unmounted) */
513 static void send_mount_path(const gchar
*path
)
515 printf_send("m%s", path
);
518 /* Send a message to the filer process. The first character indicates the
519 * type of the message.
521 static gboolean
printf_send(const char *msg
, ...)
527 tmp
= g_strdup_vprintf(msg
, args
);
530 g_string_assign(message
, tmp
);
536 /* Send 'message' to our parent process. TRUE on success. */
537 static gboolean
send_msg(void)
542 g_return_val_if_fail(message
->len
< 0xffff, FALSE
);
544 sprintf(len_buffer
, "%04" G_GSIZE_MODIFIER
"x", message
->len
);
545 fwrite(len_buffer
, 1, 4, to_parent
);
546 len
= fwrite(message
->str
, 1, message
->len
, to_parent
);
548 return len
== (ssize_t
) message
->len
;
551 /* Set the directory indicator at the top of the window */
552 static gboolean
send_dir(const char *dir
)
554 return printf_send("/%s", dir
);
557 static gboolean
send_error(void)
559 return printf_send("!%s: %s\n", _("ERROR"), g_strerror(errno
));
562 static void response(GtkDialog
*dialog
, gint response
, GUIside
*gui_side
)
566 if (!gui_side
->to_child
)
569 if (response
== GTK_RESPONSE_YES
)
571 else if (response
== GTK_RESPONSE_NO
)
576 fputc(code
, gui_side
->to_child
);
577 fflush(gui_side
->to_child
);
578 abox_show_compare(gui_side
->abox
, FALSE
);
581 static void flag_toggled(ABox
*abox
, gint flag
, GUIside
*gui_side
)
583 if (!gui_side
->to_child
)
586 fputc(flag
, gui_side
->to_child
);
587 fflush(gui_side
->to_child
);
590 static void read_new_entry_text(void)
596 new = g_string_new(NULL
);
600 len
= read(from_parent
, &c
, 1);
603 fprintf(stderr
, "read() error: %s\n",
605 _exit(1); /* Parent died? */
610 g_string_append_c(new, c
);
613 g_free(new_entry_string
);
614 new_entry_string
= new->str
;
615 g_string_free(new, FALSE
);
618 static void process_flag(char flag
)
629 o_recurse
= !o_recurse
;
638 read_new_entry_text();
641 printf_send("!ERROR: Bad message '%c'\n", flag
);
646 /* If the parent has sent any flag toggles, read them */
647 static void check_flags(void)
658 FD_SET(from_parent
, &set
);
661 got
= select(from_parent
+ 1, &set
, NULL
, NULL
, &tv
);
664 g_error("select() failed: %s\n", g_strerror(errno
));
668 got
= read(from_parent
, &retval
, 1);
670 g_error("read() error: %s\n", g_strerror(errno
));
672 process_flag(retval
);
676 /* Read until the user sends a reply. If ignore_quiet is TRUE then
677 * the user MUST click Yes or No, else treat quiet on as Yes.
678 * If the user needs prompting then does send_msg().
680 static gboolean
printf_reply(int fd
, gboolean ignore_quiet
,
681 const char *msg
, ...)
688 if (quiet
&& !ignore_quiet
)
692 tmp
= g_strdup_vprintf(msg
, args
);
695 g_string_assign(message
, tmp
);
702 len
= read(fd
, &retval
, 1);
705 fprintf(stderr
, "read() error: %s\n",
707 _exit(1); /* Parent died? */
713 printf_send("' %s\n", _("Yes"));
716 printf_send("' %s\n", _("No"));
719 process_flag(retval
);
725 static void abort_operation(GtkWidget
*widget
, gpointer data
)
727 GUIside
*gui_side
= (GUIside
*) data
;
731 if (gui_side
->abort_attempts
== 0)
733 abox_log(ABOX(widget
),
734 _("\nAsking child process to terminate...\n"),
736 kill(-gui_side
->child
, SIGTERM
);
740 abox_log(ABOX(widget
),
741 _("\nTrying to KILL run-away process...\n"),
743 kill(-gui_side
->child
, SIGKILL
);
744 kill(-gui_side
->child
, SIGCONT
);
746 gui_side
->abort_attempts
++;
749 gtk_widget_destroy(widget
);
752 static void destroy_action_window(GtkWidget
*widget
, gpointer data
)
754 GUIside
*gui_side
= (GUIside
*) data
;
758 kill(-gui_side
->child
, SIGTERM
);
759 fclose(gui_side
->to_child
);
760 close(gui_side
->from_child
);
761 g_source_remove(gui_side
->input_tag
);
769 /* Create two pipes, fork() a child and return a pointer to a GUIside struct
770 * (NULL on failure). The child calls func().
772 static GUIside
*start_action(GtkWidget
*abox
, ActionChild
*func
, gpointer data
,
773 int force
, int brief
, int recurse
, int newer
)
776 int filedes
[4]; /* 0 and 2 are for reading */
779 struct sigaction act
;
783 report_error("pipe: %s", g_strerror(errno
));
784 gtk_widget_destroy(abox
);
788 if (pipe(filedes
+ 2))
792 report_error("pipe: %s", g_strerror(errno
));
793 gtk_widget_destroy(abox
);
797 autoq
= gtk_toggle_button_get_active(
798 GTK_TOGGLE_BUTTON(ABOX(abox
)->quiet
));
809 report_error("fork: %s", g_strerror(errno
));
810 gtk_widget_destroy(abox
);
813 /* We are the child */
815 /* Create a new process group */
820 dir_drop_all_dnotifies();
822 /* Reset the SIGCHLD handler */
823 act
.sa_handler
= SIG_DFL
;
824 sigemptyset(&act
.sa_mask
);
826 sigaction(SIGCHLD
, &act
, NULL
);
828 message
= g_string_new(NULL
);
831 to_parent
= fdopen(filedes
[1], "wb");
832 from_parent
= filedes
[2];
838 /* We are the parent */
841 gui_side
= g_new(GUIside
, 1);
842 gui_side
->from_child
= filedes
[0];
843 gui_side
->to_child
= fdopen(filedes
[3], "wb");
844 gui_side
->child
= child
;
845 gui_side
->errors
= 0;
846 gui_side
->show_info
= FALSE
;
847 gui_side
->default_string
= NULL
;
848 gui_side
->entry_string_func
= NULL
;
849 gui_side
->abort_attempts
= 0;
851 gui_side
->abox
= ABOX(abox
);
852 g_signal_connect(abox
, "destroy",
853 G_CALLBACK(destroy_action_window
), gui_side
);
855 g_signal_connect(abox
, "response", G_CALLBACK(response
), gui_side
);
856 g_signal_connect(abox
, "flag_toggled",
857 G_CALLBACK(flag_toggled
), gui_side
);
858 g_signal_connect(abox
, "abort_operation",
859 G_CALLBACK(abort_operation
), gui_side
);
861 gui_side
->input_tag
= gdk_input_add_full(gui_side
->from_child
,
869 /* ACTIONS ON ONE ITEM */
871 /* These may call themselves recursively, or ask questions, etc */
873 /* Updates the global size_tally, file_counter and dir_counter */
874 static void do_usage(const char *src_path
, const char *unused
)
880 if (mc_lstat(src_path
, &info
))
882 printf_send("'%s:\n", src_path
);
885 else if (S_ISREG(info
.st_mode
) || S_ISLNK(info
.st_mode
))
888 size_tally
+= info
.st_size
;
890 else if (S_ISDIR(info
.st_mode
))
893 if (printf_reply(from_parent
, FALSE
,
894 _("?Count contents of %s?"), src_path
))
897 safe_path
= g_strdup(src_path
);
898 for_dir_contents(do_usage
, safe_path
, safe_path
);
906 /* dest_path is the dir containing src_path */
907 static void do_delete(const char *src_path
, const char *unused
)
915 if (mc_lstat(src_path
, &info
))
921 write_prot
= S_ISLNK(info
.st_mode
) ? FALSE
922 : access(src_path
, W_OK
) != 0;
923 if (write_prot
|| !quiet
)
927 printf_send("<%s", src_path
);
929 res
=printf_reply(from_parent
, write_prot
&& !o_force
,
930 _("?Delete %s'%s'?"),
931 write_prot
? _("WRITE-PROTECTED ") : "",
938 printf_send(_("'Deleting '%s'\n"), src_path
);
940 safe_path
= g_strdup(src_path
);
942 if (S_ISDIR(info
.st_mode
))
944 for_dir_contents(do_delete
, safe_path
, safe_path
);
945 if (rmdir(safe_path
))
951 printf_send(_("'Directory '%s' deleted\n"), safe_path
);
952 send_mount_path(safe_path
);
954 else if (unlink(src_path
))
958 send_check_path(safe_path
);
959 if (strcmp(g_basename(safe_path
), ".DirIcon") == 0)
962 dir
= g_path_get_dirname(safe_path
);
963 send_check_path(dir
);
971 static void do_eject(const char *path
)
973 const char *argv
[]={"sh", "-c", NULL
, NULL
};
981 printf_send("<%s", path
);
983 res
=printf_reply(from_parent
, !o_force
,
991 printf_send(_("'Eject '%s'\n"), path
);
993 /* Need to close all sub-directories now, or we
994 * can't unmount if dnotify is used.
998 printf_send("X%s", path
);
999 /* Wait until it's safe... */
1000 read(from_parent
, &c
, 1);
1001 g_return_if_fail(c
== 'X');
1004 argv
[2] = build_command_with_path(o_action_eject_command
.value
,
1006 err
= fork_exec_wait((const char**)argv
);
1007 g_free((gchar
*) argv
[2]);
1010 printf_send(_("!%s\neject failed\n"), err
);
1014 printf_send("M%s", path
);
1018 /* path is the item to check. If is is a directory then we may recurse
1019 * (unless prune is used).
1021 static void do_find(const char *path
, const char *unused
)
1029 if (!printf_reply(from_parent
, FALSE
, _("?Check '%s'?"), path
))
1035 if (new_entry_string
)
1037 find_condition_free(find_condition
);
1038 find_condition
= find_compile(new_entry_string
);
1039 null_g_free(&new_entry_string
);
1045 printf_send(_("!Invalid find condition - "
1046 "change it and try again\n"));
1047 if (!printf_reply(from_parent
, TRUE
,
1048 _("?Check '%s'?"), path
))
1052 if (mc_lstat(path
, &info
.stats
))
1055 printf_send(_("'(while checking '%s')\n"), path
);
1059 info
.fullpath
= path
;
1060 time(&info
.now
); /* XXX: Not for each check! */
1062 info
.leaf
= g_basename(path
);
1064 if (find_test_condition(find_condition
, &info
))
1065 printf_send("=%s", path
);
1067 if (S_ISDIR(info
.stats
.st_mode
) && !info
.prune
)
1070 safe_path
= g_strdup(path
);
1071 for_dir_contents(do_find
, safe_path
, safe_path
);
1076 /* Like mode_compile(), but ignores spaces and bracketed bits */
1077 static struct mode_change
*nice_mode_compile(const char *mode_string
,
1078 unsigned int masked_ops
)
1082 struct mode_change
*retval
= NULL
;
1084 new = g_string_new(NULL
);
1086 for (; *mode_string
; mode_string
++)
1088 if (*mode_string
== '(')
1090 if (*mode_string
== ')')
1098 if (brackets
== 0 && *mode_string
!= ' ')
1099 g_string_append_c(new, *mode_string
);
1103 retval
= mode_compile(new->str
, masked_ops
);
1104 g_string_free(new, TRUE
);
1108 static void do_chmod(const char *path
, const char *unused
)
1115 if (mc_lstat(path
, &info
))
1120 if (S_ISLNK(info
.st_mode
))
1126 printf_send("<%s", path
);
1128 res
=printf_reply(from_parent
, FALSE
,
1129 _("?Change permissions of '%s'?"), path
);
1135 printf_send(_("'Changing permissions of '%s'\n"), path
);
1139 if (new_entry_string
)
1142 mode_free(mode_change
);
1143 mode_change
= nice_mode_compile(new_entry_string
,
1145 null_g_free(&new_entry_string
);
1152 _("!Invalid mode command - change it and try again\n"));
1153 if (!printf_reply(from_parent
, TRUE
,
1154 _("?Change permissions of '%s'?"), path
))
1158 if (mc_lstat(path
, &info
))
1163 if (S_ISLNK(info
.st_mode
))
1166 new_mode
= mode_adjust(info
.st_mode
, mode_change
);
1167 if (chmod(path
, new_mode
))
1173 send_check_path(path
);
1175 if (S_ISDIR(info
.st_mode
))
1177 send_mount_path(path
);
1182 safe_path
= g_strdup(path
);
1183 for_dir_contents(do_chmod
, safe_path
, safe_path
);
1189 static void do_settype(const char *path
, const char *unused
)
1195 if (mc_lstat(path
, &info
))
1200 if (S_ISLNK(info
.st_mode
))
1206 printf_send("<%s", path
);
1208 if (S_ISDIR(info
.st_mode
))
1209 res
=printf_reply(from_parent
, FALSE
,
1210 _("?Change contents of '%s'?"), path
);
1212 res
=printf_reply(from_parent
, FALSE
,
1213 _("?Change type of '%s'?"), path
);
1221 if (new_entry_string
)
1223 type_change
= mime_type_lookup(new_entry_string
);
1224 null_g_free(&new_entry_string
);
1230 printf_send(_("!Invalid type - "
1231 "change it and try again\n"));
1232 if (!printf_reply(from_parent
, TRUE
,
1233 _("?Change type of '%s'?"), path
))
1237 if (mc_lstat(path
, &info
))
1242 if (S_ISLNK(info
.st_mode
))
1245 if (S_ISREG(info
.st_mode
))
1249 const char *comment
;
1251 comment
= mime_type_comment(type_change
);
1252 printf_send(_("'Changing type of '%s' to '%s'\n"), path
,
1256 if (xtype_set(path
, type_change
))
1262 send_check_path(path
);
1264 else if (S_ISDIR(info
.st_mode
))
1269 safe_path
= g_strdup(path
);
1270 for_dir_contents(do_settype
, safe_path
, unused
);
1275 printf_send(_("'Not changing type of directory '%s'\n"),
1281 printf_send(_("'Non-regular file '%s' not changed\n"),
1286 /* We want to copy 'object' into directory 'dir'. If 'action_leaf'
1287 * is set then that is the new leafname, otherwise the leafname stays
1290 static const char *make_dest_path(const char *object
, const char *dir
)
1298 leaf
= strrchr(object
, '/');
1300 leaf
= object
; /* Error? */
1305 return make_path(dir
, leaf
);
1308 /* If action_leaf is not NULL it specifies the new leaf name */
1309 static void do_copy2(const char *path
, const char *dest
)
1311 const char *dest_path
;
1313 struct stat dest_info
;
1317 dest_path
= make_dest_path(path
, dest
);
1319 if (mc_lstat(path
, &info
))
1325 if (mc_lstat(dest_path
, &dest_info
) == 0)
1330 merge
= S_ISDIR(info
.st_mode
) && S_ISDIR(dest_info
.st_mode
);
1332 if (!merge
&& o_newer
&& info
.st_mtime
> dest_info
.st_mtime
)
1334 /* Newer; keep going */
1338 printf_send("<%s", path
);
1339 printf_send(">%s", dest_path
);
1340 if (!printf_reply(from_parent
, TRUE
,
1341 _("?'%s' already exists - %s?"),
1343 merge
? _("merge contents")
1350 if (S_ISDIR(dest_info
.st_mode
))
1351 err
= rmdir(dest_path
);
1353 err
= unlink(dest_path
);
1358 if (errno
!= ENOENT
)
1360 printf_send(_("'Trying copy anyway...\n"));
1366 printf_send("<%s", path
);
1368 if (!printf_reply(from_parent
, FALSE
,
1369 _("?Copy %s as %s?"), path
, dest_path
))
1372 else if (!o_brief
|| S_ISDIR(info
.st_mode
))
1373 printf_send(_("'Copying %s as %s\n"), path
, dest_path
);
1375 if (S_ISDIR(info
.st_mode
))
1377 mode_t mode
= info
.st_mode
;
1378 char *safe_path
, *safe_dest
;
1379 struct stat dest_info
;
1382 safe_path
= g_strdup(path
);
1383 safe_dest
= g_strdup(dest_path
);
1385 exists
= !mc_lstat(dest_path
, &dest_info
);
1387 if (exists
&& !S_ISDIR(dest_info
.st_mode
))
1388 printf_send(_("!ERROR: Destination already exists, "
1389 "but is not a directory\n"));
1390 else if (exists
== FALSE
&& mkdir(dest_path
, 0700 | mode
))
1395 /* (just been created then) */
1396 send_check_path(dest_path
);
1399 for_dir_contents(do_copy2
, safe_path
, safe_dest
);
1400 /* Note: dest_path now invalid... */
1406 /* We may have created the directory with
1407 * more permissions than the source so that
1408 * we could write to it... change it back now.
1410 if (chmod(safe_dest
, mode
))
1412 /* Some filesystems don't support
1413 * SetGID and SetUID bits. Ignore
1420 /* Also, try to preserve the timestamps */
1421 utb
.actime
= info
.st_atime
;
1422 utb
.modtime
= info
.st_mtime
;
1424 utime(safe_dest
, &utb
);
1431 else if (S_ISLNK(info
.st_mode
))
1435 /* Not all versions of cp(1) can make symlinks,
1436 * so we special-case it.
1439 target
= readlink_dup(path
);
1442 if (symlink(target
, dest_path
))
1445 send_check_path(dest_path
);
1456 error
= copy_file(path
, dest_path
);
1460 printf_send(_("!%s\nFailed to copy '%s'\n"),
1465 send_check_path(dest_path
);
1469 /* If action_leaf is not NULL it specifies the new leaf name */
1470 static void do_move2(const char *path
, const char *dest
)
1472 const char *dest_path
;
1473 const char *argv
[] = {"mv", "-f", NULL
, NULL
, NULL
};
1480 dest_path
= make_dest_path(path
, dest
);
1482 is_dir
= mc_lstat(path
, &info2
) == 0 && S_ISDIR(info2
.st_mode
);
1484 if (access(dest_path
, F_OK
) == 0)
1489 if (mc_lstat(dest_path
, &info
))
1495 if (!is_dir
&& o_newer
&& info2
.st_mtime
> info
.st_mtime
)
1497 /* Newer; keep going */
1501 printf_send("<%s", path
);
1502 printf_send(">%s", dest_path
);
1503 if (!printf_reply(from_parent
, TRUE
,
1504 _("?'%s' already exists - overwrite?"),
1509 if (S_ISDIR(info
.st_mode
))
1510 err
= rmdir(dest_path
);
1512 err
= unlink(dest_path
);
1517 if (errno
!= ENOENT
)
1519 printf_send(_("'Trying move anyway...\n"));
1524 printf_send("<%s", path
);
1526 if (!printf_reply(from_parent
, FALSE
,
1527 _("?Move %s as %s?"), path
, dest_path
))
1531 printf_send(_("'Moving %s as %s\n"), path
, dest_path
);
1534 argv
[3] = dest_path
;
1536 err
= fork_exec_wait(argv
);
1539 printf_send(_("!%s\nFailed to move %s as %s\n"),
1540 err
, path
, dest_path
);
1545 send_check_path(dest_path
);
1548 send_mount_path(path
);
1550 send_check_path(path
);
1554 /* Copy path to dest.
1555 * Check that path not copied into itself.
1557 static void do_copy(const char *path
, const char *dest
)
1559 if (is_sub_dir(make_dest_path(path
, dest
), path
))
1560 printf_send(_("!ERROR: Can't copy object into itself\n"));
1563 do_copy2(path
, dest
);
1564 send_check_path(dest
);
1568 /* Move path to dest.
1569 * Check that path not moved into itself.
1571 static void do_move(const char *path
, const char *dest
)
1573 if (is_sub_dir(make_dest_path(path
, dest
), path
))
1575 _("!ERROR: Can't move/rename object into itself\n"));
1578 do_move2(path
, dest
);
1579 send_check_path(dest
);
1583 /* Common code for do_link_relative() and do_link_absolute(). */
1584 static void do_link(const char *path
, const char *dest_path
)
1587 printf_send(_("'Linking %s as %s\n"), path
, dest_path
);
1589 printf_send("<%s", path
);
1591 if (!printf_reply(from_parent
, FALSE
,
1592 _("?Link %s as %s?"), path
, dest_path
))
1596 if (symlink(path
, dest_path
))
1599 send_check_path(dest_path
);
1602 static void do_link_relative(const char *path
, const char *dest
)
1605 const char *dest_path
;
1607 dest_path
= make_dest_path(path
, dest
);
1611 rel_path
= get_relative_path(dest_path
, path
);
1612 do_link(rel_path
, dest_path
);
1616 static void do_link_absolute(const char *path
, const char *dest
)
1619 do_link(path
, make_dest_path(path
, dest
));
1622 /* Mount/umount this item (depending on 'mount') */
1623 static void do_mount(const guchar
*path
, gboolean mount
)
1625 const char *argv
[] = {"sh", "-c", NULL
, NULL
};
1630 argv
[2] = build_command_with_path(mount
? o_action_mount_command
.value
1631 : o_action_umount_command
.value
,
1635 printf_send(mount
? _("'Mounting %s\n")
1636 : _("'Unmounting %s\n"),
1638 else if (!printf_reply(from_parent
, FALSE
,
1639 mount
? _("?Mount %s?")
1640 : _("?Unmount %s?"),
1647 /* Need to close all sub-directories now, or we
1648 * can't unmount if dnotify is used.
1650 printf_send("X%s", path
);
1651 /* Wait until it's safe... */
1652 read(from_parent
, &c
, 1);
1653 g_return_if_fail(c
== 'X');
1656 err
= fork_exec_wait(argv
);
1657 g_free((gchar
*) argv
[2]);
1661 _("!%s\nMount failed\n") :
1662 _("!%s\nUnmount failed\n"), err
);
1665 /* Mount may have worked even on error, eg if we try to mount
1666 * a read-only disk read/write, it gets mounted read-only
1669 if (mount
&& mount_is_mounted(path
, NULL
, NULL
))
1670 printf_send(_("'(seems to be mounted now anyway)\n"));
1675 printf_send("M%s", path
);
1676 if (mount
&& mount_open_dir
)
1677 printf_send("o%s", path
);
1680 /* CHILD MAIN LOOPS */
1682 /* After forking, the child calls one of these functions */
1684 /* We use a double for total size in order to count beyond 4Gb */
1685 static void usage_cb(gpointer data
)
1687 GList
*paths
= (GList
*) data
;
1688 double total_size
= 0;
1691 n
=g_list_length(paths
);
1692 dir_counter
= file_counter
= 0;
1694 for (i
=0; paths
; paths
= paths
->next
, i
++)
1696 guchar
*path
= (guchar
*) paths
->data
;
1705 printf_send("%%%d", per
);
1707 do_usage(path
, NULL
);
1709 printf_send("'%s: %s\n",
1711 format_double_size(size_tally
));
1712 total_size
+= size_tally
;
1714 printf_send("%%-1");
1716 g_string_printf(message
, _("'\nTotal: %s ("),
1717 format_double_size(total_size
));
1720 g_string_append_printf(message
,
1721 "%ld %s%s", file_counter
,
1722 file_counter
== 1 ? _("file") : _("files"),
1723 dir_counter
? ", " : ")\n");
1725 if (file_counter
== 0 && dir_counter
== 0)
1726 g_string_append(message
, _("no directories)\n"));
1727 else if (dir_counter
)
1728 g_string_append_printf(message
,
1729 "%ld %s)\n", dir_counter
,
1730 dir_counter
== 1 ? _("directory")
1731 : _("directories"));
1736 #ifdef DO_MOUNT_POINTS
1737 static void mount_cb(gpointer data
)
1739 GList
*paths
= (GList
*) data
;
1740 gboolean mount_points
= FALSE
;
1743 n
=g_list_length(paths
);
1744 for (i
=0; paths
; paths
= paths
->next
, i
++)
1746 guchar
*path
= (guchar
*) paths
->data
;
1749 target
= pathdup(path
);
1756 printf_send("%%%d", per
);
1758 if (mount_is_mounted(target
, NULL
, NULL
) ||
1759 g_hash_table_lookup(fstab_mounts
, target
))
1761 mount_points
= TRUE
;
1762 do_mount(target
, mount_mount
); /* Mount */
1772 printf_send(_("!No mount points selected!\n"));
1776 /* (use g_dirname() instead?) */
1777 static guchar
*dirname(guchar
*path
)
1781 slash
= strrchr(path
, '/');
1782 g_return_val_if_fail(slash
!= NULL
, g_strdup(path
));
1785 return g_strndup(path
, slash
- path
);
1786 return g_strdup("/");
1789 static void delete_cb(gpointer data
)
1791 GList
*paths
= (GList
*) data
;
1794 n
=g_list_length(paths
);
1795 for (i
=0; paths
; paths
= paths
->next
, i
++)
1797 guchar
*path
= (guchar
*) paths
->data
;
1800 dir
= dirname(path
);
1806 printf_send("%%%d", per
);
1808 do_delete(path
, dir
);
1816 static void eject_cb(gpointer data
)
1818 GList
*paths
= (GList
*) data
;
1821 n
=g_list_length(paths
);
1823 for (i
=0; paths
; paths
= paths
->next
, i
++)
1825 guchar
*path
= (guchar
*) paths
->data
;
1830 printf_send("%%%d", per
);
1840 static void find_cb(gpointer data
)
1842 GList
*all_paths
= (GList
*) data
;
1847 for (paths
= all_paths
; paths
; paths
= paths
->next
)
1849 guchar
*path
= (guchar
*) paths
->data
;
1853 do_find(path
, NULL
);
1856 if (!printf_reply(from_parent
, TRUE
,
1857 _("?Another search?")))
1865 static void chmod_cb(gpointer data
)
1867 GList
*paths
= (GList
*) data
;
1870 n
=g_list_length(paths
);
1872 for (i
=0; paths
; paths
= paths
->next
, i
++)
1874 guchar
*path
= (guchar
*) paths
->data
;
1880 printf_send("%%%d", per
);
1884 if (mc_stat(path
, &info
) != 0)
1886 else if (S_ISLNK(info
.st_mode
))
1887 printf_send(_("!'%s' is a symbolic link\n"),
1890 do_chmod(path
, NULL
);
1896 static void settype_cb(gpointer data
)
1898 GList
*paths
= (GList
*) data
;
1901 n
=g_list_length(paths
);
1903 for (i
=0; paths
; paths
= paths
->next
, i
++)
1905 guchar
*path
= (guchar
*) paths
->data
;
1911 printf_send("%%%d", per
);
1915 if (mc_stat(path
, &info
) != 0)
1917 else if (S_ISLNK(info
.st_mode
))
1918 printf_send(_("!'%s' is a symbolic link\n"),
1921 do_settype(path
, NULL
);
1927 static void list_cb(gpointer data
)
1929 GList
*paths
= (GList
*) data
;
1932 n
=g_list_length(paths
);
1934 for (i
=0; paths
; paths
= paths
->next
, i
++)
1939 printf_send("%%%d", per
);
1941 send_dir((char *) paths
->data
);
1943 action_do_func((char *) paths
->data
, action_dest
);
1949 /* EXTERNAL INTERFACE */
1951 void action_find(GList
*paths
)
1958 report_error(_("You need to select some items "
1959 "to search through"));
1963 if (!last_find_string
)
1964 last_find_string
= g_strdup("'core'");
1966 new_entry_string
= last_find_string
;
1968 abox
= abox_new(_("Find"), FALSE
);
1969 gui_side
= start_action(abox
, find_cb
, paths
,
1970 o_action_force
.int_value
,
1971 o_action_brief
.int_value
,
1972 o_action_recurse
.int_value
,
1973 o_action_newer
.int_value
);
1977 abox_add_results(ABOX(abox
));
1979 gui_side
->default_string
= &last_find_string
;
1980 abox_add_entry(ABOX(abox
), last_find_string
,
1981 new_help_button(show_condition_help
, NULL
));
1982 g_signal_connect(ABOX(abox
)->entry
, "changed",
1983 G_CALLBACK(entry_changed
), gui_side
);
1984 set_find_string_colour(ABOX(abox
)->entry
, last_find_string
);
1986 gui_side
->show_info
= TRUE
;
1987 gui_side
->entry_string_func
= set_find_string_colour
;
1989 number_of_windows
++;
1990 gtk_widget_show(abox
);
1993 /* Count disk space used by selected items */
1994 void action_usage(GList
*paths
)
2001 report_error(_("You need to select some items to count"));
2005 abox
= abox_new(_("Disk Usage"), TRUE
);
2006 if(paths
&& paths
->next
)
2007 abox_set_percentage(ABOX(abox
), 0);
2009 gui_side
= start_action(abox
, usage_cb
, paths
,
2010 o_action_force
.int_value
,
2011 o_action_brief
.int_value
,
2012 o_action_recurse
.int_value
,
2013 o_action_newer
.int_value
);
2017 gui_side
->show_info
= TRUE
;
2019 number_of_windows
++;
2021 gtk_widget_show(abox
);
2024 /* Mount/unmount listed items (paths).
2025 * Free the list after this function returns.
2026 * If open_dir is TRUE and the dir is successfully mounted, open it.
2027 * quiet can be -1 for default.
2029 void action_mount(GList
*paths
, gboolean open_dir
, gboolean mount
, int quiet
)
2031 #ifdef DO_MOUNT_POINTS
2036 quiet
= o_action_mount
.int_value
;
2038 mount_open_dir
= open_dir
;
2039 mount_mount
= mount
;
2041 abox
= abox_new(_("Mount / Unmount"), quiet
);
2042 if(paths
&& paths
->next
)
2043 abox_set_percentage(ABOX(abox
), 0);
2044 gui_side
= start_action(abox
, mount_cb
, paths
,
2045 o_action_force
.int_value
,
2046 o_action_brief
.int_value
,
2047 o_action_recurse
.int_value
,
2048 o_action_newer
.int_value
);
2052 number_of_windows
++;
2053 gtk_widget_show(abox
);
2056 _("ROX-Filer does not yet support mount points on your "
2058 #endif /* DO_MOUNT_POINTS */
2061 /* Delete these paths */
2062 void action_delete(GList
*paths
)
2067 if (!remove_pinned_ok(paths
))
2070 abox
= abox_new(_("Delete"), o_action_delete
.int_value
);
2071 if(paths
&& paths
->next
)
2072 abox_set_percentage(ABOX(abox
), 0);
2073 gui_side
= start_action(abox
, delete_cb
, paths
,
2074 o_action_force
.int_value
,
2075 o_action_brief
.int_value
,
2076 o_action_recurse
.int_value
,
2077 o_action_newer
.int_value
);
2081 abox_add_flag(ABOX(abox
),
2082 _("Force"), _("Don't confirm deletion of non-writeable items"),
2083 'F', o_action_force
.int_value
);
2084 abox_add_flag(ABOX(abox
),
2085 _("Brief"), _("Only log directories being deleted"),
2086 'B', o_action_brief
.int_value
);
2088 number_of_windows
++;
2089 gtk_widget_show(abox
);
2092 /* Change the permissions of the selected items */
2093 void action_chmod(GList
*paths
, gboolean force_recurse
, const char *action
)
2097 static GList
*presets
= NULL
;
2098 gboolean recurse
= force_recurse
|| o_action_recurse
.int_value
;
2102 report_error(_("You need to select the items "
2103 "whose permissions you want to change"));
2109 presets
= g_list_append(presets
, (gchar
*)
2110 _("a+x (Make executable/searchable)"));
2111 presets
= g_list_append(presets
, (gchar
*)
2112 _("a-x (Make non-executable/non-searchable)"));
2113 presets
= g_list_append(presets
, (gchar
*)
2114 _("u+rw (Give owner read+write)"));
2115 presets
= g_list_append(presets
, (gchar
*)
2116 _("go-rwx (Private - owner access only)"));
2117 presets
= g_list_append(presets
, (gchar
*)
2118 _("go=u-w (Public access, not write)"));
2121 if (!last_chmod_string
)
2122 last_chmod_string
= g_strdup((guchar
*) presets
->data
);
2125 new_entry_string
= g_strdup(action
);
2127 new_entry_string
= g_strdup(last_chmod_string
);
2129 abox
= abox_new(_("Permissions"), FALSE
);
2130 if(paths
&& paths
->next
)
2131 abox_set_percentage(ABOX(abox
), 0);
2132 gui_side
= start_action(abox
, chmod_cb
, paths
,
2133 o_action_force
.int_value
,
2134 o_action_brief
.int_value
,
2136 o_action_newer
.int_value
);
2141 abox_add_flag(ABOX(abox
),
2142 _("Brief"), _("Don't list processed files"),
2143 'B', o_action_brief
.int_value
);
2144 abox_add_flag(ABOX(abox
),
2145 _("Recurse"), _("Also change contents of subdirectories"),
2148 gui_side
->default_string
= &last_chmod_string
;
2149 abox_add_combo(ABOX(abox
), _("Command:"), presets
, new_entry_string
,
2150 new_help_button(show_chmod_help
, NULL
));
2152 g_signal_connect(ABOX(abox
)->entry
, "changed",
2153 G_CALLBACK(entry_changed
), gui_side
);
2155 g_signal_connect_swapped(gui_side
->entry
, "activate",
2156 G_CALLBACK(gtk_button_clicked
),
2160 number_of_windows
++;
2161 gtk_widget_show(abox
);
2164 null_g_free(&new_entry_string
);
2167 /* Set the MIME type of the selected items */
2168 void action_settype(GList
*paths
, gboolean force_recurse
, const char *oldtype
)
2172 GList
*presets
= NULL
;
2173 gboolean recurse
= force_recurse
|| o_action_recurse
.int_value
;
2177 report_error(_("You need to select the items "
2178 "whose type you want to change"));
2182 if (!last_settype_string
)
2183 last_settype_string
= g_strdup("text/plain");
2186 new_entry_string
= g_strdup(oldtype
);
2188 new_entry_string
= g_strdup(last_settype_string
);
2190 abox
= abox_new(_("Set type"), FALSE
);
2191 if(paths
&& paths
->next
)
2192 abox_set_percentage(ABOX(abox
), 0);
2193 gui_side
= start_action(abox
, settype_cb
, paths
,
2194 o_action_force
.int_value
,
2195 o_action_brief
.int_value
,
2197 o_action_newer
.int_value
);
2202 abox_add_flag(ABOX(abox
),
2203 _("Brief"), _("Don't list processed files"),
2204 'B', o_action_brief
.int_value
);
2205 abox_add_flag(ABOX(abox
),
2206 _("Recurse"), _("Change contents of subdirectories"),
2209 gui_side
->default_string
= &last_settype_string
;
2211 /* Note: get the list again each time -- it can change */
2212 presets
= mime_type_name_list(TRUE
);
2213 abox_add_combo(ABOX(abox
), _("Type:"), presets
, new_entry_string
,
2214 new_help_button(show_settype_help
, NULL
));
2215 g_list_free(presets
);
2217 g_signal_connect(ABOX(abox
)->entry
, "changed",
2218 G_CALLBACK(entry_changed
), gui_side
);
2220 number_of_windows
++;
2221 gtk_widget_show(abox
);
2224 null_g_free(&new_entry_string
);
2227 /* If leaf is NULL then the copy has the same name as the original.
2228 * quiet can be -1 for default.
2230 void action_copy(GList
*paths
, const char *dest
, const char *leaf
, int quiet
)
2236 quiet
= o_action_copy
.int_value
;
2240 action_do_func
= do_copy
;
2242 abox
= abox_new(_("Copy"), quiet
);
2243 if(paths
&& paths
->next
)
2244 abox_set_percentage(ABOX(abox
), 0);
2245 gui_side
= start_action(abox
, list_cb
, paths
,
2246 o_action_force
.int_value
,
2247 o_action_brief
.int_value
,
2248 o_action_recurse
.int_value
,
2249 o_action_newer
.int_value
);
2253 abox_add_flag(ABOX(abox
),
2255 _("Only over-write if source is newer than destination."),
2256 'W', o_action_newer
.int_value
);
2257 abox_add_flag(ABOX(abox
),
2258 _("Brief"), _("Only log directories as they are copied"),
2259 'B', o_action_brief
.int_value
);
2261 number_of_windows
++;
2262 gtk_widget_show(abox
);
2265 /* If leaf is NULL then the file is not renamed.
2266 * quiet can be -1 for default.
2268 void action_move(GList
*paths
, const char *dest
, const char *leaf
, int quiet
)
2274 quiet
= o_action_move
.int_value
;
2278 action_do_func
= do_move
;
2280 abox
= abox_new(_("Move"), quiet
);
2281 if(paths
&& paths
->next
)
2282 abox_set_percentage(ABOX(abox
), 0);
2283 gui_side
= start_action(abox
, list_cb
, paths
,
2284 o_action_force
.int_value
,
2285 o_action_brief
.int_value
,
2286 o_action_recurse
.int_value
,
2287 o_action_newer
.int_value
);
2291 abox_add_flag(ABOX(abox
),
2293 _("Only over-write if source is newer than destination."),
2294 'W', o_action_newer
.int_value
);
2295 abox_add_flag(ABOX(abox
),
2296 _("Brief"), _("Don't log each file as it is moved"),
2297 'B', o_action_brief
.int_value
);
2298 number_of_windows
++;
2299 gtk_widget_show(abox
);
2302 /* If leaf is NULL then the link will have the same name */
2303 void action_link(GList
*paths
, const char *dest
, const char *leaf
,
2312 action_do_func
= do_link_relative
;
2314 action_do_func
= do_link_absolute
;
2316 abox
= abox_new(_("Link"), o_action_link
.int_value
);
2317 if(paths
&& paths
->next
)
2318 abox_set_percentage(ABOX(abox
), 0);
2319 gui_side
= start_action(abox
, list_cb
, paths
,
2320 o_action_force
.int_value
,
2321 o_action_brief
.int_value
,
2322 o_action_recurse
.int_value
,
2323 o_action_newer
.int_value
);
2327 number_of_windows
++;
2328 gtk_widget_show(abox
);
2331 /* Eject these paths */
2332 void action_eject(GList
*paths
)
2337 abox
= abox_new(_("Eject"), TRUE
);
2338 if(paths
&& paths
->next
)
2339 abox_set_percentage(ABOX(abox
), 0);
2340 gui_side
= start_action(abox
, eject_cb
, paths
,
2341 o_action_force
.int_value
,
2342 o_action_brief
.int_value
,
2343 o_action_recurse
.int_value
,
2344 o_action_newer
.int_value
);
2348 number_of_windows
++;
2349 gtk_widget_show(abox
);
2352 void action_init(void)
2354 option_add_int(&o_action_copy
, "action_copy", 1);
2355 option_add_int(&o_action_move
, "action_move", 1);
2356 option_add_int(&o_action_link
, "action_link", 1);
2357 option_add_int(&o_action_delete
, "action_delete", 0);
2358 option_add_int(&o_action_mount
, "action_mount", 1);
2359 option_add_int(&o_action_force
, "action_force", FALSE
);
2360 option_add_int(&o_action_brief
, "action_brief", FALSE
);
2361 option_add_int(&o_action_recurse
, "action_recurse", FALSE
);
2362 option_add_int(&o_action_newer
, "action_newer", FALSE
);
2364 option_add_string(&o_action_mount_command
,
2365 "action_mount_command", "mount");
2366 option_add_string(&o_action_umount_command
,
2367 "action_umount_command", "umount");
2368 option_add_string(&o_action_eject_command
,
2369 "action_eject_command", "eject");
2374 /* Check to see if any of the selected items (or their children) are
2375 * on the pinboard or panel. If so, ask for confirmation.
2377 * TRUE if it's OK to lose them.
2379 static gboolean
remove_pinned_ok(GList
*paths
)
2381 GList
*ask
= NULL
, *next
;
2386 for (; paths
; paths
= paths
->next
)
2388 guchar
*path
= (guchar
*) paths
->data
;
2390 if (icons_require(path
))
2392 if (++ask_n
> MAX_ASK
)
2394 ask
= g_list_append(ask
, path
);
2401 if (ask_n
> MAX_ASK
)
2403 message
= g_string_new(_("Deleting items such as "));
2406 else if (ask_n
== 1)
2407 message
= g_string_new(_("Deleting the item "));
2409 message
= g_string_new(_("Deleting the items "));
2412 for (next
= ask
; next
; next
= next
->next
)
2414 guchar
*path
= (guchar
*) next
->data
;
2417 leaf
= strrchr(path
, '/');
2423 g_string_append_c(message
, '`');
2424 g_string_append(message
, leaf
);
2425 g_string_append_c(message
, '\'');
2427 if (i
== ask_n
- 1 && i
> 0)
2428 g_string_append(message
, _(" and "));
2430 g_string_append(message
, ", ");
2436 message
= g_string_append(message
,
2437 _(" will affect some items on the pinboard "
2438 "or panel - really delete it?"));
2441 if (ask_n
> MAX_ASK
)
2442 message
= g_string_append_c(message
, ',');
2443 message
= g_string_append(message
,
2444 _(" will affect some items on the pinboard "
2445 "or panel - really delete them?"));
2448 retval
= confirm(message
->str
, GTK_STOCK_DELETE
, NULL
);
2450 g_string_free(message
, TRUE
);
2455 void set_find_string_colour(GtkWidget
*widget
, const guchar
*string
)
2457 FindCondition
*cond
;
2459 cond
= find_compile(string
);
2460 entry_set_error(widget
, !cond
);
2462 find_condition_free(cond
);