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"
55 int number_of_windows
= 0; /* Quit when this reaches 0 again... */
56 int to_error_log
= -1; /* Write here to log errors */
60 int ngroups
; /* Number of supplemental groups */
61 gid_t
*supplemental_groups
= NULL
;
64 /* Static prototypes */
65 static void show_features(void);
68 #define VERSION "ROX-Filer 0.1.20\n" \
69 "Copyright (C) 2000 Thomas Leonard.\n" \
70 "ROX-Filer comes with ABSOLUTELY NO WARRANTY,\n" \
71 "to the extent permitted by law.\n" \
72 "You may redistribute copies of ROX-Filer\n" \
73 "under the terms of the GNU General Public License.\n" \
74 "For more information about these matters, " \
75 "see the file named COPYING.\n"
77 #ifdef HAVE_GETOPT_LONG
78 # define USAGE "Try `ROX-Filer/AppRun --help' for more information.\n"
79 # define SHORT_ONLY_WARNING ""
81 # define USAGE "Try `ROX-Filer/AppRun -h' for more information.\n"
82 # define SHORT_ONLY_WARNING \
83 "NOTE: Your system does not support long options - \n" \
84 "you must use the short versions instead.\n\n"
87 #define SHORT_OPS "t:b:ohv"
89 #define HELP "Usage: ROX-Filer/AppRun [OPTION]... [DIR]...\n" \
90 "Open filer windows showing each directory listed, or $HOME \n" \
91 "if no directories are given.\n\n" \
92 " -h, --help display this help and exit\n" \
93 " -v, --version display the version information and exit\n" \
94 " -t, --top [DIR] open DIR as a top-edge panel\n" \
95 " -b, --bottom [DIR] open DIR as a bottom-edge panel\n" \
96 " -o, --override override window manager control of panels\n" \
97 "\n" SHORT_ONLY_WARNING \
98 "Report bugs to <tal197@ecs.soton.ac.uk>.\n"
100 #ifdef HAVE_GETOPT_LONG
101 static struct option long_opts
[] =
103 {"top", 1, NULL
, 't'},
104 {"bottom", 1, NULL
, 'b'},
105 {"override", 0, NULL
, 'o'},
106 {"help", 0, NULL
, 'h'},
107 {"version", 0, NULL
, 'v'},
112 /* Take control of panels away from WM? */
113 gboolean override_redirect
= FALSE
;
115 /* Maps child PIDs to Callback pointers */
116 static GHashTable
*death_callbacks
= NULL
;
117 static gboolean child_died_flag
= FALSE
;
119 /* This is called as a signal handler; simply ensures that
120 * child_died_callback() will get called later.
122 static void child_died(int signum
)
124 child_died_flag
= TRUE
;
125 write(to_error_log
, '\0', 1); /* Wake up! */
128 static void child_died_callback(void)
133 child_died_flag
= FALSE
;
135 /* Find out which children exited and allow them to die */
140 child
= waitpid(-1, &status
, WNOHANG
);
142 if (child
== 0 || child
== -1)
145 cb
= g_hash_table_lookup(death_callbacks
, (gpointer
) child
);
148 cb
->callback(cb
->data
);
149 g_hash_table_remove(death_callbacks
, (gpointer
) child
);
156 void stderr_cb(gpointer data
, gint source
, GdkInputCondition condition
)
159 static GtkWidget
*log
= NULL
;
160 static GtkWidget
*window
= NULL
;
165 GtkWidget
*hbox
, *scrollbar
;
167 window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
168 gtk_window_set_title(GTK_WINDOW(window
),
169 "ROX-Filer message log");
170 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_CENTER
);
171 gtk_window_set_default_size(GTK_WINDOW(window
), 600, 300);
172 gtk_signal_connect_object(GTK_OBJECT(window
), "delete_event",
173 gtk_widget_hide
, GTK_OBJECT(window
));
176 hbox
= gtk_hbox_new(FALSE
, 0);
177 gtk_container_add(GTK_CONTAINER(window
), hbox
);
178 scrollbar
= gtk_vscrollbar_new(NULL
);
180 log
= gtk_text_new(NULL
,
181 gtk_range_get_adjustment(GTK_RANGE(scrollbar
)));
182 gtk_box_pack_start(GTK_BOX(hbox
), log
, TRUE
, TRUE
, 0);
183 gtk_box_pack_start(GTK_BOX(hbox
), scrollbar
, FALSE
, TRUE
, 0);
186 len
= read(source
, buf
, BUFLEN
);
190 child_died_callback();
191 if (len
== 1 && !*buf
)
197 if (!GTK_WIDGET_MAPPED(window
))
198 gtk_widget_show_all(window
);
199 gtk_text_insert(GTK_TEXT(log
), NULL
, NULL
, NULL
, buf
, len
);
203 int main(int argc
, char **argv
)
206 struct sigaction act
;
207 GList
*panel_dirs
= NULL
;
208 GList
*panel_sides
= NULL
;
212 home_dir
= g_get_home_dir();
213 death_callbacks
= g_hash_table_new(NULL
, NULL
);
218 gtk_init(&argc
, &argv
);
223 #ifdef HAVE_GETOPT_LONG
225 c
= getopt_long(argc
, argv
, SHORT_OPS
,
226 long_opts
, &long_index
);
228 c
= getopt(argc
, argv
, SHORT_OPS
);
232 break; /* No more options */
237 override_redirect
= TRUE
;
248 panel_sides
= g_list_prepend(panel_sides
,
250 panel_dirs
= g_list_prepend(panel_dirs
,
251 *optarg
== '=' ? optarg
+ 1
275 /* Let child processes die */
276 act
.sa_handler
= child_died
;
277 sigemptyset(&act
.sa_mask
);
278 act
.sa_flags
= SA_NOCLDSTOP
;
279 sigaction(SIGCHLD
, &act
, NULL
);
281 /* Ignore SIGPIPE - check for EPIPE errors instead */
282 act
.sa_handler
= SIG_IGN
;
283 sigemptyset(&act
.sa_mask
);
285 sigaction(SIGPIPE
, &act
, NULL
);
289 ngroups
= getgroups(0, NULL
);
292 else if (ngroups
> 0)
294 supplemental_groups
= g_malloc(sizeof(gid_t
) * ngroups
);
295 getgroups(ngroups
, supplemental_groups
);
300 if (get_choice("!!!DANGER!!!",
301 "Running ROX-Filer as root is VERY dangerous. If I "
302 "had a warranty (I don't) then doing this would "
304 "Don't click here", "Quit") != 0)
308 if (optind
== argc
&& !panel_dirs
)
309 filer_opendir(home_dir
, PANEL_NO
);
313 GList
*dir
= panel_dirs
;
314 GList
*side
= panel_sides
;
318 int c
= (int) side
->data
;
320 filer_opendir((char *) dir
->data
,
321 c
== 't' ? PANEL_TOP
: PANEL_BOTTOM
);
330 filer_opendir(argv
[i
++], PANEL_NO
);
334 close_on_exec(stderr_pipe
[0], TRUE
);
335 close_on_exec(stderr_pipe
[1], TRUE
);
336 gdk_input_add(stderr_pipe
[0], GDK_INPUT_READ
, stderr_cb
, NULL
);
337 to_error_log
= stderr_pipe
[1];
344 static void show_features(void)
346 g_printerr("\n-- %s --\n\n", _("features set at compile time"));
347 g_printerr("%s... %s\n", _("VFS support"),
351 _("No (couldn't find a valid libvfs)")
354 g_printerr("%s... %s\n", _("ImLib support"),
358 _("No (the imlib-config command didn't work)")
361 g_printerr("%s... %s\n", _("Internationalisation support"),
365 _("No (could not find gettext() function)")
370 /* Register a function to be called when process number 'child' dies. */
371 void on_child_death(int child
, CallbackFn callback
, gpointer data
)
375 g_return_if_fail(callback
!= NULL
);
377 cb
= g_new(Callback
, 1);
379 cb
->callback
= callback
;
382 g_hash_table_insert(death_callbacks
, (gpointer
) child
, cb
);