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"
57 int number_of_windows
= 0; /* Quit when this reaches 0 again... */
58 int to_error_log
= -1; /* Write here to log errors */
62 int ngroups
; /* Number of supplemental groups */
63 gid_t
*supplemental_groups
= NULL
;
66 /* Static prototypes */
67 static void show_features(void);
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:ohvn"
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 " -b, --bottom=DIR open DIR as a bottom-edge panel\n" \
95 " -h, --help display this help and exit\n" \
96 " -n, --new start a new filer, even if already running\n" \
97 " -o, --override override window manager control of panels\n" \
98 " -t, --top=DIR open DIR as a top-edge panel\n" \
99 " -v, --version display the version information and exit\n" \
100 "\nReport bugs to <tal197@ecs.soton.ac.uk>.\n")
102 #ifdef HAVE_GETOPT_LONG
103 static struct option long_opts
[] =
105 {"top", 1, NULL
, 't'},
106 {"bottom", 1, NULL
, 'b'},
107 {"override", 0, NULL
, 'o'},
108 {"help", 0, NULL
, 'h'},
109 {"version", 0, NULL
, 'v'},
110 {"new", 0, NULL
, 'n'},
115 /* Take control of panels away from WM? */
116 gboolean override_redirect
= FALSE
;
118 /* Always start a new filer, even if one seems to be already running */
119 gboolean new_copy
= FALSE
;
121 /* Maps child PIDs to Callback pointers */
122 static GHashTable
*death_callbacks
= NULL
;
123 static gboolean child_died_flag
= FALSE
;
125 /* This is called as a signal handler; simply ensures that
126 * child_died_callback() will get called later.
128 static void child_died(int signum
)
130 child_died_flag
= TRUE
;
131 write(to_error_log
, '\0', 1); /* Wake up! */
134 static void child_died_callback(void)
139 child_died_flag
= FALSE
;
141 /* Find out which children exited and allow them to die */
146 child
= waitpid(-1, &status
, WNOHANG
);
148 if (child
== 0 || child
== -1)
151 cb
= g_hash_table_lookup(death_callbacks
, (gpointer
) child
);
154 cb
->callback(cb
->data
);
155 g_hash_table_remove(death_callbacks
, (gpointer
) child
);
162 void stderr_cb(gpointer data
, gint source
, GdkInputCondition condition
)
165 static GtkWidget
*log
= NULL
;
166 static GtkWidget
*window
= NULL
;
171 GtkWidget
*hbox
, *scrollbar
;
173 window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
174 gtk_window_set_title(GTK_WINDOW(window
),
175 _("ROX-Filer message log"));
176 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_CENTER
);
177 gtk_window_set_default_size(GTK_WINDOW(window
), 600, 300);
178 gtk_signal_connect_object(GTK_OBJECT(window
), "delete_event",
179 gtk_widget_hide
, GTK_OBJECT(window
));
182 hbox
= gtk_hbox_new(FALSE
, 0);
183 gtk_container_add(GTK_CONTAINER(window
), hbox
);
184 scrollbar
= gtk_vscrollbar_new(NULL
);
186 log
= gtk_text_new(NULL
,
187 gtk_range_get_adjustment(GTK_RANGE(scrollbar
)));
188 gtk_box_pack_start(GTK_BOX(hbox
), log
, TRUE
, TRUE
, 0);
189 gtk_box_pack_start(GTK_BOX(hbox
), scrollbar
, FALSE
, TRUE
, 0);
192 len
= read(source
, buf
, BUFLEN
);
196 child_died_callback();
197 if (len
== 1 && !*buf
)
203 if (!GTK_WIDGET_MAPPED(window
))
204 gtk_widget_show_all(window
);
205 gtk_text_insert(GTK_TEXT(log
), NULL
, NULL
, NULL
, buf
, len
);
209 int main(int argc
, char **argv
)
212 struct sigaction act
;
213 GList
*panel_dirs
= NULL
;
214 GList
*panel_sides
= NULL
;
219 home_dir
= g_get_home_dir();
220 death_callbacks
= g_hash_table_new(NULL
, NULL
);
225 gtk_init(&argc
, &argv
);
230 #ifdef HAVE_GETOPT_LONG
232 c
= getopt_long(argc
, argv
, SHORT_OPS
,
233 long_opts
, &long_index
);
235 c
= getopt(argc
, argv
, SHORT_OPS
);
239 break; /* No more options */
247 override_redirect
= TRUE
;
250 fprintf(stderr
, "ROX-Filer %s\n", VERSION
);
251 fprintf(stderr
, _(COPYING
));
255 fprintf(stderr
, _(HELP
));
256 fprintf(stderr
, _(SHORT_ONLY_WARNING
));
260 panel_sides
= g_list_prepend(panel_sides
,
262 panel_dirs
= g_list_prepend(panel_dirs
,
263 *optarg
== '=' ? optarg
+ 1
273 if (remote_init(argc
- optind
, argv
+ optind
, new_copy
))
274 return EXIT_SUCCESS
; /* Already running */
287 /* Let child processes die */
288 act
.sa_handler
= child_died
;
289 sigemptyset(&act
.sa_mask
);
290 act
.sa_flags
= SA_NOCLDSTOP
;
291 sigaction(SIGCHLD
, &act
, NULL
);
293 /* Ignore SIGPIPE - check for EPIPE errors instead */
294 act
.sa_handler
= SIG_IGN
;
295 sigemptyset(&act
.sa_mask
);
297 sigaction(SIGPIPE
, &act
, NULL
);
301 ngroups
= getgroups(0, NULL
);
304 else if (ngroups
> 0)
306 supplemental_groups
= g_malloc(sizeof(gid_t
) * ngroups
);
307 getgroups(ngroups
, supplemental_groups
);
312 if (get_choice(_("!!!DANGER!!!"),
313 _("Running ROX-Filer as root is VERY dangerous. If I "
314 "had a warranty (I don't) then doing this would "
316 _("Don't click here"), _("Quit")) != 0)
320 if (optind
== argc
&& !panel_dirs
)
321 filer_opendir(home_dir
, PANEL_NO
);
325 GList
*dir
= panel_dirs
;
326 GList
*side
= panel_sides
;
330 int c
= (int) side
->data
;
332 filer_opendir((char *) dir
->data
,
333 c
== 't' ? PANEL_TOP
: PANEL_BOTTOM
);
342 filer_opendir(argv
[i
++], PANEL_NO
);
346 close_on_exec(stderr_pipe
[0], TRUE
);
347 close_on_exec(stderr_pipe
[1], TRUE
);
348 gdk_input_add(stderr_pipe
[0], GDK_INPUT_READ
, stderr_cb
, NULL
);
349 to_error_log
= stderr_pipe
[1];
356 static void show_features(void)
358 g_printerr("\n-- %s --\n\n", _("features set at compile time"));
359 g_printerr("%s... %s\n", _("VFS support"),
363 _("No (couldn't find a valid libvfs)")
366 g_printerr("%s... %s\n", _("ImLib support"),
370 _("No (the imlib-config command didn't work)")
375 /* Register a function to be called when process number 'child' dies. */
376 void on_child_death(int child
, CallbackFn callback
, gpointer data
)
380 g_return_if_fail(callback
!= NULL
);
382 cb
= g_new(Callback
, 1);
384 cb
->callback
= callback
;
387 g_hash_table_insert(death_callbacks
, (gpointer
) child
, cb
);