4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2000, Thomas Leonard, <tal197@users.sourceforge.net>.
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"
45 #include "gui_support.h"
63 int number_of_windows
= 0; /* Quit when this reaches 0 again... */
64 int to_error_log
= -1; /* Write here to log errors */
68 int ngroups
; /* Number of supplemental groups */
69 gid_t
*supplemental_groups
= NULL
;
70 char *home_dir
, *app_dir
;
72 /* Static prototypes */
73 static void show_features(void);
77 N_("Copyright (C) 2000 Thomas Leonard.\n" \
78 "ROX-Filer comes with ABSOLUTELY NO WARRANTY,\n" \
79 "to the extent permitted by law.\n" \
80 "You may redistribute copies of ROX-Filer\n" \
81 "under the terms of the GNU General Public License.\n" \
82 "For more information about these matters, " \
83 "see the file named COPYING.\n")
85 #ifdef HAVE_GETOPT_LONG
86 # define USAGE N_("Try `ROX-Filer/AppRun --help' for more information.\n")
87 # define SHORT_ONLY_WARNING ""
89 # define USAGE N_("Try `ROX-Filer/AppRun -h' for more information.\n")
90 # define SHORT_ONLY_WARNING \
91 _("NOTE: Your system does not support long options - \n" \
92 "you must use the short versions instead.\n\n")
95 #define HELP N_("Usage: ROX-Filer/AppRun [OPTION]... [FILE]...\n" \
96 "Open each directory or file listed, or the current working\n" \
97 "directory if no arguments are given.\n\n" \
98 " -b, --bottom=DIR open DIR as a bottom-edge panel\n" \
99 " -h, --help display this help and exit\n" \
100 " -n, --new start a new filer, even if already running\n" \
101 " -o, --override override window manager control of panels\n" \
102 " -p, --pinboard=PIN use pinboard PIN as the pinboard\n" \
103 " -t, --top=DIR open DIR as a top-edge panel\n" \
104 " -v, --version display the version information and exit\n" \
105 "\nThe latest version can be found at:\n" \
106 "\thttp://rox.sourceforge.net\n" \
107 "\nReport bugs to <tal197@users.sourceforge.net>.\n")
109 #define SHORT_OPS "t:b:op:hvn"
111 #ifdef HAVE_GETOPT_LONG
112 static struct option long_opts
[] =
114 {"top", 1, NULL
, 't'},
115 {"bottom", 1, NULL
, 'b'},
116 {"override", 0, NULL
, 'o'},
117 {"pinboard", 1, NULL
, 'p'},
118 {"help", 0, NULL
, 'h'},
119 {"version", 0, NULL
, 'v'},
120 {"new", 0, NULL
, 'n'},
125 /* Take control of panels away from WM? */
126 gboolean override_redirect
= FALSE
;
128 /* Always start a new filer, even if one seems to be already running */
129 gboolean new_copy
= FALSE
;
131 /* Maps child PIDs to Callback pointers */
132 static GHashTable
*death_callbacks
= NULL
;
133 static gboolean child_died_flag
= FALSE
;
135 /* This is called as a signal handler; simply ensures that
136 * child_died_callback() will get called later.
138 static void child_died(int signum
)
140 child_died_flag
= TRUE
;
141 write(to_error_log
, '\0', 1); /* Wake up! */
144 static void child_died_callback(void)
149 child_died_flag
= FALSE
;
151 /* Find out which children exited and allow them to die */
156 child
= waitpid(-1, &status
, WNOHANG
);
158 if (child
== 0 || child
== -1)
161 cb
= g_hash_table_lookup(death_callbacks
, (gpointer
) child
);
164 cb
->callback(cb
->data
);
165 g_hash_table_remove(death_callbacks
, (gpointer
) child
);
172 void stderr_cb(gpointer data
, gint source
, GdkInputCondition condition
)
175 static GtkWidget
*log
= NULL
;
176 static GtkWidget
*window
= NULL
;
181 GtkWidget
*hbox
, *scrollbar
;
183 window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
184 gtk_window_set_title(GTK_WINDOW(window
),
185 _("ROX-Filer message log"));
186 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_CENTER
);
187 gtk_window_set_default_size(GTK_WINDOW(window
), 600, 300);
188 gtk_signal_connect_object(GTK_OBJECT(window
), "delete_event",
189 gtk_widget_hide
, GTK_OBJECT(window
));
192 hbox
= gtk_hbox_new(FALSE
, 0);
193 gtk_container_add(GTK_CONTAINER(window
), hbox
);
194 scrollbar
= gtk_vscrollbar_new(NULL
);
196 log
= gtk_text_new(NULL
,
197 gtk_range_get_adjustment(GTK_RANGE(scrollbar
)));
198 gtk_box_pack_start(GTK_BOX(hbox
), log
, TRUE
, TRUE
, 0);
199 gtk_box_pack_start(GTK_BOX(hbox
), scrollbar
, FALSE
, TRUE
, 0);
202 len
= read(source
, buf
, BUFLEN
);
206 child_died_callback();
207 if (len
== 1 && !*buf
)
213 if (!GTK_WIDGET_MAPPED(window
))
214 gtk_widget_show_all(window
);
215 gtk_text_insert(GTK_TEXT(log
), NULL
, NULL
, NULL
, buf
, len
);
219 /* The value that goes with an option */
220 #define VALUE (*optarg == '=' ? optarg + 1 : optarg)
222 int main(int argc
, char **argv
)
226 struct sigaction act
;
229 /* This is a list of \0 separated strings. Each string starts with a
230 * character indicating what kind of operation to perform:
232 * fFILE open this file (or directory)
233 * dDIR open this dir (even if it looks like an app)
234 * pPIN display this pinboard
235 * tDIR open DIR as a top-panel
236 * bDIR open DIR as a bottom-panel
240 to_open
= g_string_new(NULL
);
242 home_dir
= g_get_home_dir();
243 app_dir
= g_strdup(getenv("APP_DIR"));
252 g_warning("APP_DIR environment variable was unset!\n"
253 "Use the AppRun script to invoke ROX-Filer...\n");
254 app_dir
= g_get_current_dir();
257 death_callbacks
= g_hash_table_new(NULL
, NULL
);
262 gtk_init(&argc
, &argv
);
267 #ifdef HAVE_GETOPT_LONG
269 c
= getopt_long(argc
, argv
, SHORT_OPS
,
270 long_opts
, &long_index
);
272 c
= getopt(argc
, argv
, SHORT_OPS
);
276 break; /* No more options */
284 override_redirect
= TRUE
;
287 fprintf(stderr
, "ROX-Filer %s\n", VERSION
);
288 fprintf(stderr
, _(COPYING
));
292 fprintf(stderr
, _(HELP
));
293 fprintf(stderr
, _(SHORT_ONLY_WARNING
));
297 g_string_append_c(to_open
, '<');
298 g_string_append_c(to_open
, c
);
299 g_string_append_c(to_open
, '>');
300 tmp
= pathdup(VALUE
);
301 g_string_append(to_open
, tmp
);
305 g_string_append(to_open
, "<p>");
306 g_string_append(to_open
, VALUE
);
317 tmp
= pathdup(argv
[i
++]);
319 g_string_append(to_open
, "<f>");
320 g_string_append(to_open
, tmp
);
323 if (to_open
->len
== 0)
327 dir
= g_get_current_dir();
328 g_string_sprintf(to_open
, "<d>%s", dir
);
333 if (remote_init(to_open
, new_copy
))
334 return EXIT_SUCCESS
; /* Already running */
351 /* Let child processes die */
352 act
.sa_handler
= child_died
;
353 sigemptyset(&act
.sa_mask
);
354 act
.sa_flags
= SA_NOCLDSTOP
;
355 sigaction(SIGCHLD
, &act
, NULL
);
357 /* Ignore SIGPIPE - check for EPIPE errors instead */
358 act
.sa_handler
= SIG_IGN
;
359 sigemptyset(&act
.sa_mask
);
361 sigaction(SIGPIPE
, &act
, NULL
);
365 ngroups
= getgroups(0, NULL
);
368 else if (ngroups
> 0)
370 supplemental_groups
= g_malloc(sizeof(gid_t
) * ngroups
);
371 getgroups(ngroups
, supplemental_groups
);
376 if (get_choice(_("!!!DANGER!!!"),
377 _("Running ROX-Filer as root is VERY dangerous. If I "
378 "had a warranty (I don't) then doing this would "
380 _("Don't click here"), _("Quit")) != 0)
384 run_list(to_open
->str
);
385 g_string_free(to_open
, TRUE
);
388 close_on_exec(stderr_pipe
[0], TRUE
);
389 close_on_exec(stderr_pipe
[1], TRUE
);
390 gdk_input_add(stderr_pipe
[0], GDK_INPUT_READ
, stderr_cb
, NULL
);
391 to_error_log
= stderr_pipe
[1];
393 if (number_of_windows
> 0)
399 static void show_features(void)
401 g_printerr("\n-- %s --\n\n", _("features set at compile time"));
402 g_printerr("%s... %s\n", _("VFS support"),
406 _("No (couldn't find a valid libvfs)")
409 g_printerr("%s... %s\n", _("ImLib support"),
413 _("No (the imlib-config command didn't work)")
418 /* Register a function to be called when process number 'child' dies. */
419 void on_child_death(int child
, CallbackFn callback
, gpointer data
)
423 g_return_if_fail(callback
!= NULL
);
425 cb
= g_new(Callback
, 1);
427 cb
->callback
= callback
;
430 g_hash_table_insert(death_callbacks
, (gpointer
) child
, cb
);