r163: Choosing something from the selection menu when nothing is selected
[rox-filer/ma.git] / ROX-Filer / src / main.c
blob0f55d87e2b06f3aba1bd4ed141612812d275c202
1 /*
2 * $Id$
4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 1999, 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)
10 * any later version.
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
15 * more details.
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
22 #include "config.h"
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <sys/types.h>
27 #include <signal.h>
28 #include <sys/wait.h>
29 #include <unistd.h>
30 #include <fcntl.h>
32 #ifdef HAVE_GETOPT_LONG
33 # include <getopt.h>
34 #endif
36 #include <gtk/gtk.h>
37 #include "collection.h"
39 #include "main.h"
40 #include "gui_support.h"
41 #include "filer.h"
42 #include "mount.h"
43 #include "menu.h"
44 #include "dnd.h"
45 #include "options.h"
46 #include "choices.h"
47 #include "savebox.h"
48 #include "type.h"
49 #include "pixmaps.h"
50 #include "dir.h"
52 int number_of_windows = 0; /* Quit when this reaches 0 again... */
53 int to_error_log = -1; /* Write here to log errors */
55 #define VERSION "ROX-Filer 0.1.11\n" \
56 "Copyright (C) 1999 Thomas Leonard.\n" \
57 "ROX-Filer comes with ABSOLUTELY NO WARRANTY,\n" \
58 "to the extent permitted by law.\n" \
59 "You may redistribute copies of ROX-Filer\n" \
60 "under the terms of the GNU General Public License.\n" \
61 "For more information about these matters, " \
62 "see the file named COPYING.\n"
64 #ifdef HAVE_GETOPT_LONG
65 # define USAGE "Try `ROX-Filer/AppRun --help' for more information.\n"
66 # define SHORT_ONLY_WARNING ""
67 #else
68 # define USAGE "Try `ROX-Filer/AppRun -h' for more information.\n"
69 # define SHORT_ONLY_WARNING "NOTE: Your system does not support long options - \n" \
70 "you must use the short versions instead.\n\n"
71 #endif \
73 #define HELP "Usage: ROX-Filer/AppRun [OPTION]... [DIR]...\n" \
74 "Open filer windows showing each directory listed, or $HOME \n" \
75 "if no directories are given.\n\n" \
76 " -h, --help display this help and exit\n" \
77 " -v, --version display the version information and exit\n" \
78 " -t, --top [DIR] open DIR as a top-edge panel\n" \
79 " -b, --bottom [DIR] open DIR as a bottom-edge panel\n" \
80 " -l, --left [DIR] open DIR as a left-edge panel\n" \
81 " -r, --right [DIR] open DIR as a right-edge panel\n" \
82 " -o, --override override window manager control of panels\n" \
83 "\n" SHORT_ONLY_WARNING \
84 "Report bugs to <tal197@ecs.soton.ac.uk>.\n"
86 #ifdef HAVE_GETOPT_LONG
87 static struct option long_opts[] =
89 {"top", 1, NULL, 't'},
90 {"bottom", 1, NULL, 'b'},
91 {"left", 1, NULL, 'l'},
92 {"right", 1, NULL, 'r'},
93 {"override", 0, NULL, 'o'},
94 {"help", 0, NULL, 'h'},
95 {"version", 0, NULL, 'v'},
96 {NULL, 0, NULL, 0},
98 #endif
100 /* Take control of panels away from WM? */
101 gboolean override_redirect = FALSE;
103 static void child_died(int signum)
105 int status;
106 int child;
108 /* Find out which children exited and allow them to die */
111 child = waitpid(-1, &status, WNOHANG);
113 if (child == 0 || child == -1)
114 return;
116 /* fprintf(stderr, "Child %d exited\n", child); */
118 } while (1);
121 #define BUFLEN 40
122 void stderr_cb(gpointer data, gint source, GdkInputCondition condition)
124 char buf[BUFLEN];
125 static GtkWidget *log = NULL;
126 static GtkWidget *window = NULL;
127 ssize_t len;
129 if (!window)
131 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
132 gtk_window_set_title(GTK_WINDOW(window), "ROX-Filer error log");
133 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
134 gtk_window_set_default_size(GTK_WINDOW(window), 600, 300);
135 gtk_signal_connect_object(GTK_OBJECT(window), "delete_event",
136 gtk_widget_hide, GTK_OBJECT(window));
137 log = gtk_text_new(NULL, NULL);
138 gtk_container_add(GTK_CONTAINER(window), log);
141 if (!GTK_WIDGET_MAPPED(window))
142 gtk_widget_show_all(window);
144 len = read(source, buf, BUFLEN);
145 if (len > 0)
146 gtk_text_insert(GTK_TEXT(log), NULL, NULL, NULL, buf, len);
149 int main(int argc, char **argv)
151 int stderr_pipe[2];
152 struct sigaction act;
153 GList *panel_dirs = NULL;
154 GList *panel_sides = NULL;
156 gtk_init(&argc, &argv);
158 while (1)
160 int c;
161 #ifdef HAVE_GETOPT_LONG
162 int long_index;
163 c = getopt_long(argc, argv, "t:b:l:r:ohv",
164 long_opts, &long_index);
165 #else
166 c = getopt(argc, argv, "t:b:l:r:ohv");
167 #endif
169 if (c == EOF)
170 break; /* No more options */
172 switch (c)
174 case 'o':
175 override_redirect = TRUE;
176 break;
177 case 'v':
178 printf(VERSION);
179 return EXIT_SUCCESS;
180 case 'h':
181 printf(HELP);
182 return EXIT_SUCCESS;
183 case 't':
184 case 'b':
185 case 'l':
186 case 'r':
187 panel_sides = g_list_prepend(panel_sides,
188 (gpointer) c);
189 panel_dirs = g_list_prepend(panel_dirs,
190 *optarg == '=' ? optarg + 1
191 : optarg);
192 break;
193 default:
194 printf(USAGE);
195 return EXIT_FAILURE;
199 choices_init("ROX-Filer");
201 gui_support_init();
202 pixmaps_init();
203 dir_init();
204 menu_init();
205 dnd_init();
206 filer_init();
207 mount_init();
208 options_init();
209 savebox_init();
210 type_init();
212 options_load();
214 /* Let child processes die */
215 act.sa_handler = child_died;
216 sigemptyset(&act.sa_mask);
217 act.sa_flags = SA_NOCLDSTOP;
218 sigaction(SIGCHLD, &act, NULL);
220 if (geteuid() == 0)
222 if (get_choice("!!!DANGER!!!",
223 "Running ROX-Filer as root is VERY dangerous. If I "
224 "had a warranty (I don't) then doing this would "
225 "void it", 2,
226 "Don't click here", "Quit") != 0)
227 exit(EXIT_SUCCESS);
230 if (optind == argc && !panel_dirs)
231 filer_opendir(getenv("HOME"), FALSE, BOTTOM);
232 else
234 int i = optind;
235 GList *dir = panel_dirs;
236 GList *side = panel_sides;
238 while (dir)
240 int c = (int) side->data;
242 filer_opendir((char *) dir->data, TRUE,
243 c == 't' ? TOP :
244 c == 'b' ? BOTTOM :
245 c == 'l' ? LEFT :
246 RIGHT);
247 dir = dir->next;
248 side = side->next;
251 g_list_free(dir);
252 g_list_free(side);
254 while (i < argc)
255 filer_opendir(argv[i++], FALSE, BOTTOM);
258 pipe(stderr_pipe);
259 gdk_input_add(stderr_pipe[0], GDK_INPUT_READ, stderr_cb, NULL);
260 to_error_log = stderr_pipe[1];
262 gtk_main();
264 return EXIT_SUCCESS;