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 #define VERSION "ROX-Filer 0.1.19\n" \
65 "Copyright (C) 2000 Thomas Leonard.\n" \
66 "ROX-Filer comes with ABSOLUTELY NO WARRANTY,\n" \
67 "to the extent permitted by law.\n" \
68 "You may redistribute copies of ROX-Filer\n" \
69 "under the terms of the GNU General Public License.\n" \
70 "For more information about these matters, " \
71 "see the file named COPYING.\n"
73 #ifdef HAVE_GETOPT_LONG
74 # define USAGE "Try `ROX-Filer/AppRun --help' for more information.\n"
75 # define SHORT_ONLY_WARNING ""
77 # define USAGE "Try `ROX-Filer/AppRun -h' for more information.\n"
78 # define SHORT_ONLY_WARNING \
79 "NOTE: Your system does not support long options - \n" \
80 "you must use the short versions instead.\n\n"
83 #define SHORT_OPS "t:b:ohv"
85 #define HELP "Usage: ROX-Filer/AppRun [OPTION]... [DIR]...\n" \
86 "Open filer windows showing each directory listed, or $HOME \n" \
87 "if no directories are given.\n\n" \
88 " -h, --help display this help and exit\n" \
89 " -v, --version display the version information and exit\n" \
90 " -t, --top [DIR] open DIR as a top-edge panel\n" \
91 " -b, --bottom [DIR] open DIR as a bottom-edge panel\n" \
92 " -o, --override override window manager control of panels\n" \
93 "\n" SHORT_ONLY_WARNING \
94 "Report bugs to <tal197@ecs.soton.ac.uk>.\n"
96 #ifdef HAVE_GETOPT_LONG
97 static struct option long_opts
[] =
99 {"top", 1, NULL
, 't'},
100 {"bottom", 1, NULL
, 'b'},
101 {"override", 0, NULL
, 'o'},
102 {"help", 0, NULL
, 'h'},
103 {"version", 0, NULL
, 'v'},
108 /* Take control of panels away from WM? */
109 gboolean override_redirect
= FALSE
;
111 static void child_died(int signum
)
116 /* Find out which children exited and allow them to die */
119 child
= waitpid(-1, &status
, WNOHANG
);
121 if (child
== 0 || child
== -1)
124 /* fprintf(stderr, "Child %d exited\n", child); */
130 void stderr_cb(gpointer data
, gint source
, GdkInputCondition condition
)
133 static GtkWidget
*log
= NULL
;
134 static GtkWidget
*window
= NULL
;
139 GtkWidget
*hbox
, *scrollbar
;
141 window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
142 gtk_window_set_title(GTK_WINDOW(window
),
143 "ROX-Filer message log");
144 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_CENTER
);
145 gtk_window_set_default_size(GTK_WINDOW(window
), 600, 300);
146 gtk_signal_connect_object(GTK_OBJECT(window
), "delete_event",
147 gtk_widget_hide
, GTK_OBJECT(window
));
150 hbox
= gtk_hbox_new(FALSE
, 0);
151 gtk_container_add(GTK_CONTAINER(window
), hbox
);
152 scrollbar
= gtk_vscrollbar_new(NULL
);
154 log
= gtk_text_new(NULL
,
155 gtk_range_get_adjustment(GTK_RANGE(scrollbar
)));
156 gtk_box_pack_start(GTK_BOX(hbox
), log
, TRUE
, TRUE
, 0);
157 gtk_box_pack_start(GTK_BOX(hbox
), scrollbar
, FALSE
, TRUE
, 0);
160 if (!GTK_WIDGET_MAPPED(window
))
161 gtk_widget_show_all(window
);
163 len
= read(source
, buf
, BUFLEN
);
165 gtk_text_insert(GTK_TEXT(log
), NULL
, NULL
, NULL
, buf
, len
);
168 int main(int argc
, char **argv
)
171 struct sigaction act
;
172 GList
*panel_dirs
= NULL
;
173 GList
*panel_sides
= NULL
;
175 home_dir
= g_get_home_dir();
180 gtk_init(&argc
, &argv
);
185 #ifdef HAVE_GETOPT_LONG
187 c
= getopt_long(argc
, argv
, SHORT_OPS
,
188 long_opts
, &long_index
);
190 c
= getopt(argc
, argv
, SHORT_OPS
);
194 break; /* No more options */
199 override_redirect
= TRUE
;
209 panel_sides
= g_list_prepend(panel_sides
,
211 panel_dirs
= g_list_prepend(panel_dirs
,
212 *optarg
== '=' ? optarg
+ 1
236 /* Let child processes die */
237 act
.sa_handler
= child_died
;
238 sigemptyset(&act
.sa_mask
);
239 act
.sa_flags
= SA_NOCLDSTOP
;
240 sigaction(SIGCHLD
, &act
, NULL
);
242 /* Ignore SIGPIPE - check for EPIPE errors instead */
243 act
.sa_handler
= SIG_IGN
;
244 sigemptyset(&act
.sa_mask
);
246 sigaction(SIGPIPE
, &act
, NULL
);
250 ngroups
= getgroups(0, NULL
);
253 else if (ngroups
> 0)
255 supplemental_groups
= g_malloc(sizeof(gid_t
) * ngroups
);
256 getgroups(ngroups
, supplemental_groups
);
261 if (get_choice("!!!DANGER!!!",
262 "Running ROX-Filer as root is VERY dangerous. If I "
263 "had a warranty (I don't) then doing this would "
265 "Don't click here", "Quit") != 0)
269 if (optind
== argc
&& !panel_dirs
)
270 filer_opendir(home_dir
, PANEL_NO
);
274 GList
*dir
= panel_dirs
;
275 GList
*side
= panel_sides
;
279 int c
= (int) side
->data
;
281 filer_opendir((char *) dir
->data
,
282 c
== 't' ? PANEL_TOP
: PANEL_BOTTOM
);
291 filer_opendir(argv
[i
++], PANEL_NO
);
295 close_on_exec(stderr_pipe
[0], TRUE
);
296 close_on_exec(stderr_pipe
[1], TRUE
);
297 gdk_input_add(stderr_pipe
[0], GDK_INPUT_READ
, stderr_cb
, NULL
);
298 to_error_log
= stderr_pipe
[1];