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"
56 int number_of_windows
= 0; /* Quit when this reaches 0 again... */
57 int to_error_log
= -1; /* Write here to log errors */
61 int ngroups
; /* Number of supplemental groups */
62 gid_t
*supplemental_groups
= NULL
;
65 /* Static prototypes */
66 static void show_features(void);
69 #define VERSION "ROX-Filer 0.1.20\n"
71 N_("Copyright (C) 2000 Thomas Leonard.\n" \
72 "ROX-Filer comes with ABSOLUTELY NO WARRANTY,\n" \
73 "to the extent permitted by law.\n" \
74 "You may redistribute copies of ROX-Filer\n" \
75 "under the terms of the GNU General Public License.\n" \
76 "For more information about these matters, " \
77 "see the file named COPYING.\n")
79 #ifdef HAVE_GETOPT_LONG
80 # define USAGE N_("Try `ROX-Filer/AppRun --help' for more information.\n")
81 # define SHORT_ONLY_WARNING ""
83 # define USAGE N_("Try `ROX-Filer/AppRun -h' for more information.\n")
84 # define SHORT_ONLY_WARNING \
85 _("NOTE: Your system does not support long options - \n" \
86 "you must use the short versions instead.\n\n")
89 #define SHORT_OPS "t:b:ohv"
91 #define HELP N_("Usage: ROX-Filer/AppRun [OPTION]... [DIR]...\n" \
92 "Open filer windows showing each directory listed, or $HOME \n" \
93 "if no directories are given.\n\n" \
94 " -h, --help display this help and exit\n" \
95 " -v, --version display the version information and exit\n" \
96 " -t, --top [DIR] open DIR as a top-edge panel\n" \
97 " -b, --bottom [DIR] open DIR as a bottom-edge panel\n" \
98 " -o, --override override window manager control of panels\n" \
99 "\nReport bugs to <tal197@ecs.soton.ac.uk>.\n")
101 #ifdef HAVE_GETOPT_LONG
102 static struct option long_opts
[] =
104 {"top", 1, NULL
, 't'},
105 {"bottom", 1, NULL
, 'b'},
106 {"override", 0, NULL
, 'o'},
107 {"help", 0, NULL
, 'h'},
108 {"version", 0, NULL
, 'v'},
113 /* Take control of panels away from WM? */
114 gboolean override_redirect
= FALSE
;
116 /* Maps child PIDs to Callback pointers */
117 static GHashTable
*death_callbacks
= NULL
;
118 static gboolean child_died_flag
= FALSE
;
120 /* This is called as a signal handler; simply ensures that
121 * child_died_callback() will get called later.
123 static void child_died(int signum
)
125 child_died_flag
= TRUE
;
126 write(to_error_log
, '\0', 1); /* Wake up! */
129 static void child_died_callback(void)
134 child_died_flag
= FALSE
;
136 /* Find out which children exited and allow them to die */
141 child
= waitpid(-1, &status
, WNOHANG
);
143 if (child
== 0 || child
== -1)
146 cb
= g_hash_table_lookup(death_callbacks
, (gpointer
) child
);
149 cb
->callback(cb
->data
);
150 g_hash_table_remove(death_callbacks
, (gpointer
) child
);
157 void stderr_cb(gpointer data
, gint source
, GdkInputCondition condition
)
160 static GtkWidget
*log
= NULL
;
161 static GtkWidget
*window
= NULL
;
166 GtkWidget
*hbox
, *scrollbar
;
168 window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
169 gtk_window_set_title(GTK_WINDOW(window
),
170 _("ROX-Filer message log"));
171 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_CENTER
);
172 gtk_window_set_default_size(GTK_WINDOW(window
), 600, 300);
173 gtk_signal_connect_object(GTK_OBJECT(window
), "delete_event",
174 gtk_widget_hide
, GTK_OBJECT(window
));
177 hbox
= gtk_hbox_new(FALSE
, 0);
178 gtk_container_add(GTK_CONTAINER(window
), hbox
);
179 scrollbar
= gtk_vscrollbar_new(NULL
);
181 log
= gtk_text_new(NULL
,
182 gtk_range_get_adjustment(GTK_RANGE(scrollbar
)));
183 gtk_box_pack_start(GTK_BOX(hbox
), log
, TRUE
, TRUE
, 0);
184 gtk_box_pack_start(GTK_BOX(hbox
), scrollbar
, FALSE
, TRUE
, 0);
187 len
= read(source
, buf
, BUFLEN
);
191 child_died_callback();
192 if (len
== 1 && !*buf
)
198 if (!GTK_WIDGET_MAPPED(window
))
199 gtk_widget_show_all(window
);
200 gtk_text_insert(GTK_TEXT(log
), NULL
, NULL
, NULL
, buf
, len
);
204 int main(int argc
, char **argv
)
207 struct sigaction act
;
208 GList
*panel_dirs
= NULL
;
209 GList
*panel_sides
= NULL
;
214 home_dir
= g_get_home_dir();
215 death_callbacks
= g_hash_table_new(NULL
, NULL
);
220 gtk_init(&argc
, &argv
);
225 #ifdef HAVE_GETOPT_LONG
227 c
= getopt_long(argc
, argv
, SHORT_OPS
,
228 long_opts
, &long_index
);
230 c
= getopt(argc
, argv
, SHORT_OPS
);
234 break; /* No more options */
239 override_redirect
= TRUE
;
248 printf(_(SHORT_ONLY_WARNING
));
252 panel_sides
= g_list_prepend(panel_sides
,
254 panel_dirs
= g_list_prepend(panel_dirs
,
255 *optarg
== '=' ? optarg
+ 1
277 /* Let child processes die */
278 act
.sa_handler
= child_died
;
279 sigemptyset(&act
.sa_mask
);
280 act
.sa_flags
= SA_NOCLDSTOP
;
281 sigaction(SIGCHLD
, &act
, NULL
);
283 /* Ignore SIGPIPE - check for EPIPE errors instead */
284 act
.sa_handler
= SIG_IGN
;
285 sigemptyset(&act
.sa_mask
);
287 sigaction(SIGPIPE
, &act
, NULL
);
291 ngroups
= getgroups(0, NULL
);
294 else if (ngroups
> 0)
296 supplemental_groups
= g_malloc(sizeof(gid_t
) * ngroups
);
297 getgroups(ngroups
, supplemental_groups
);
302 if (get_choice(_("!!!DANGER!!!"),
303 _("Running ROX-Filer as root is VERY dangerous. If I "
304 "had a warranty (I don't) then doing this would "
306 _("Don't click here"), _("Quit")) != 0)
310 if (optind
== argc
&& !panel_dirs
)
311 filer_opendir(home_dir
, PANEL_NO
);
315 GList
*dir
= panel_dirs
;
316 GList
*side
= panel_sides
;
320 int c
= (int) side
->data
;
322 filer_opendir((char *) dir
->data
,
323 c
== 't' ? PANEL_TOP
: PANEL_BOTTOM
);
332 filer_opendir(argv
[i
++], PANEL_NO
);
336 close_on_exec(stderr_pipe
[0], TRUE
);
337 close_on_exec(stderr_pipe
[1], TRUE
);
338 gdk_input_add(stderr_pipe
[0], GDK_INPUT_READ
, stderr_cb
, NULL
);
339 to_error_log
= stderr_pipe
[1];
346 static void show_features(void)
348 g_printerr("\n-- %s --\n\n", _("features set at compile time"));
349 g_printerr("%s... %s\n", _("VFS support"),
353 _("No (couldn't find a valid libvfs)")
356 g_printerr("%s... %s\n", _("ImLib support"),
360 _("No (the imlib-config command didn't work)")
363 g_printerr("%s... %s\n", _("Internationalisation support"),
367 _("No (could not find gettext() function)")
372 /* Register a function to be called when process number 'child' dies. */
373 void on_child_death(int child
, CallbackFn callback
, gpointer data
)
377 g_return_if_fail(callback
!= NULL
);
379 cb
= g_new(Callback
, 1);
381 cb
->callback
= callback
;
384 g_hash_table_insert(death_callbacks
, (gpointer
) child
, cb
);