4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2000, Thomas Leonard, <tal197@ecs.soton.ac.uk>.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 * Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <sys/types.h>
34 #ifdef HAVE_GETOPT_LONG
39 #include "collection.h"
43 #include "gui_support.h"
60 int number_of_windows
= 0; /* Quit when this reaches 0 again... */
61 int to_error_log
= -1; /* Write here to log errors */
65 int ngroups
; /* Number of supplemental groups */
66 gid_t
*supplemental_groups
= NULL
;
69 /* Static prototypes */
70 static void show_features(void);
74 N_("Copyright (C) 2000 Thomas Leonard.\n" \
75 "ROX-Filer comes with ABSOLUTELY NO WARRANTY,\n" \
76 "to the extent permitted by law.\n" \
77 "You may redistribute copies of ROX-Filer\n" \
78 "under the terms of the GNU General Public License.\n" \
79 "For more information about these matters, " \
80 "see the file named COPYING.\n")
82 #ifdef HAVE_GETOPT_LONG
83 # define USAGE N_("Try `ROX-Filer/AppRun --help' for more information.\n")
84 # define SHORT_ONLY_WARNING ""
86 # define USAGE N_("Try `ROX-Filer/AppRun -h' for more information.\n")
87 # define SHORT_ONLY_WARNING \
88 _("NOTE: Your system does not support long options - \n" \
89 "you must use the short versions instead.\n\n")
92 #define HELP N_("Usage: ROX-Filer/AppRun [OPTION]... [FILE]...\n" \
93 "Open each directory or file listed, or the current working\n" \
94 "directory if no arguments are given.\n\n" \
95 " -b, --bottom=DIR open DIR as a bottom-edge panel\n" \
96 " -h, --help display this help and exit\n" \
97 " -n, --new start a new filer, even if already running\n" \
98 " -o, --override override window manager control of panels\n" \
99 " -p, --pinboard=PIN use pinboard PIN as the pinboard\n" \
100 " -t, --top=DIR open DIR as a top-edge panel\n" \
101 " -v, --version display the version information and exit\n" \
102 "\nThe latest version can be found at:\n" \
103 "\thttp://rox.sourceforge.net\n" \
104 "\nReport bugs to <tal197@users.sourceforge.net>.\n")
106 #define SHORT_OPS "t:b:op:hvn"
108 #ifdef HAVE_GETOPT_LONG
109 static struct option long_opts
[] =
111 {"top", 1, NULL
, 't'},
112 {"bottom", 1, NULL
, 'b'},
113 {"override", 0, NULL
, 'o'},
114 {"pinboard", 1, NULL
, 'p'},
115 {"help", 0, NULL
, 'h'},
116 {"version", 0, NULL
, 'v'},
117 {"new", 0, NULL
, 'n'},
122 /* Take control of panels away from WM? */
123 gboolean override_redirect
= FALSE
;
125 /* Always start a new filer, even if one seems to be already running */
126 gboolean new_copy
= FALSE
;
128 /* Maps child PIDs to Callback pointers */
129 static GHashTable
*death_callbacks
= NULL
;
130 static gboolean child_died_flag
= FALSE
;
132 /* This is called as a signal handler; simply ensures that
133 * child_died_callback() will get called later.
135 static void child_died(int signum
)
137 child_died_flag
= TRUE
;
138 write(to_error_log
, '\0', 1); /* Wake up! */
141 static void child_died_callback(void)
146 child_died_flag
= FALSE
;
148 /* Find out which children exited and allow them to die */
153 child
= waitpid(-1, &status
, WNOHANG
);
155 if (child
== 0 || child
== -1)
158 cb
= g_hash_table_lookup(death_callbacks
, (gpointer
) child
);
161 cb
->callback(cb
->data
);
162 g_hash_table_remove(death_callbacks
, (gpointer
) child
);
169 void stderr_cb(gpointer data
, gint source
, GdkInputCondition condition
)
172 static GtkWidget
*log
= NULL
;
173 static GtkWidget
*window
= NULL
;
178 GtkWidget
*hbox
, *scrollbar
;
180 window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
181 gtk_window_set_title(GTK_WINDOW(window
),
182 _("ROX-Filer message log"));
183 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_CENTER
);
184 gtk_window_set_default_size(GTK_WINDOW(window
), 600, 300);
185 gtk_signal_connect_object(GTK_OBJECT(window
), "delete_event",
186 gtk_widget_hide
, GTK_OBJECT(window
));
189 hbox
= gtk_hbox_new(FALSE
, 0);
190 gtk_container_add(GTK_CONTAINER(window
), hbox
);
191 scrollbar
= gtk_vscrollbar_new(NULL
);
193 log
= gtk_text_new(NULL
,
194 gtk_range_get_adjustment(GTK_RANGE(scrollbar
)));
195 gtk_box_pack_start(GTK_BOX(hbox
), log
, TRUE
, TRUE
, 0);
196 gtk_box_pack_start(GTK_BOX(hbox
), scrollbar
, FALSE
, TRUE
, 0);
199 len
= read(source
, buf
, BUFLEN
);
203 child_died_callback();
204 if (len
== 1 && !*buf
)
210 if (!GTK_WIDGET_MAPPED(window
))
211 gtk_widget_show_all(window
);
212 gtk_text_insert(GTK_TEXT(log
), NULL
, NULL
, NULL
, buf
, len
);
216 /* The value that goes with an option */
217 #define VALUE (*optarg == '=' ? optarg + 1 : optarg)
219 int main(int argc
, char **argv
)
223 struct sigaction act
;
226 /* This is a list of \0 separated strings. Each string starts with a
227 * character indicating what kind of operation to perform:
229 * fFILE open this file (or directory)
230 * dDIR open this dir (even if it looks like an app)
231 * pPIN display this pinboard
232 * tDIR open DIR as a top-panel
233 * bDIR open DIR as a bottom-panel
237 to_open
= g_string_new(NULL
);
242 home_dir
= g_get_home_dir();
243 death_callbacks
= g_hash_table_new(NULL
, NULL
);
248 gtk_init(&argc
, &argv
);
253 #ifdef HAVE_GETOPT_LONG
255 c
= getopt_long(argc
, argv
, SHORT_OPS
,
256 long_opts
, &long_index
);
258 c
= getopt(argc
, argv
, SHORT_OPS
);
262 break; /* No more options */
270 override_redirect
= TRUE
;
273 fprintf(stderr
, "ROX-Filer %s\n", VERSION
);
274 fprintf(stderr
, _(COPYING
));
278 fprintf(stderr
, _(HELP
));
279 fprintf(stderr
, _(SHORT_ONLY_WARNING
));
283 g_string_append_c(to_open
, '<');
284 g_string_append_c(to_open
, c
);
285 g_string_append_c(to_open
, '>');
286 tmp
= pathdup(VALUE
);
287 g_string_append(to_open
, tmp
);
291 g_string_append(to_open
, "<p>");
292 g_string_append(to_open
, VALUE
);
303 tmp
= pathdup(argv
[i
++]);
305 g_string_append(to_open
, "<f>");
306 g_string_append(to_open
, tmp
);
309 if (to_open
->len
== 0)
313 dir
= g_get_current_dir();
314 g_string_sprintf(to_open
, "<d>%s", dir
);
319 if (remote_init(to_open
, new_copy
))
320 return EXIT_SUCCESS
; /* Already running */
335 /* Let child processes die */
336 act
.sa_handler
= child_died
;
337 sigemptyset(&act
.sa_mask
);
338 act
.sa_flags
= SA_NOCLDSTOP
;
339 sigaction(SIGCHLD
, &act
, NULL
);
341 /* Ignore SIGPIPE - check for EPIPE errors instead */
342 act
.sa_handler
= SIG_IGN
;
343 sigemptyset(&act
.sa_mask
);
345 sigaction(SIGPIPE
, &act
, NULL
);
349 ngroups
= getgroups(0, NULL
);
352 else if (ngroups
> 0)
354 supplemental_groups
= g_malloc(sizeof(gid_t
) * ngroups
);
355 getgroups(ngroups
, supplemental_groups
);
360 if (get_choice(_("!!!DANGER!!!"),
361 _("Running ROX-Filer as root is VERY dangerous. If I "
362 "had a warranty (I don't) then doing this would "
364 _("Don't click here"), _("Quit")) != 0)
368 run_list(to_open
->str
);
369 g_string_free(to_open
, TRUE
);
372 close_on_exec(stderr_pipe
[0], TRUE
);
373 close_on_exec(stderr_pipe
[1], TRUE
);
374 gdk_input_add(stderr_pipe
[0], GDK_INPUT_READ
, stderr_cb
, NULL
);
375 to_error_log
= stderr_pipe
[1];
377 if (number_of_windows
> 0)
383 static void show_features(void)
385 g_printerr("\n-- %s --\n\n", _("features set at compile time"));
386 g_printerr("%s... %s\n", _("VFS support"),
390 _("No (couldn't find a valid libvfs)")
393 g_printerr("%s... %s\n", _("ImLib support"),
397 _("No (the imlib-config command didn't work)")
402 /* Register a function to be called when process number 'child' dies. */
403 void on_child_death(int child
, CallbackFn callback
, gpointer data
)
407 g_return_if_fail(callback
!= NULL
);
409 cb
= g_new(Callback
, 1);
411 cb
->callback
= callback
;
414 g_hash_table_insert(death_callbacks
, (gpointer
) child
, cb
);