r73: Put the collection widget sources in with the filer.
[rox-filer/dt.git] / ROX-Filer / src / main.c
blob059770c0044846afd8e320cfd3829430aca3dc05
1 /* vi: set cindent:
2 * $Id$
4 * ROX-Filer, filer for the ROX desktop project
5 * By Thomas Leonard, <tal197@ecs.soton.ac.uk>.
6 */
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <sys/types.h>
11 #include <signal.h>
12 #include <sys/wait.h>
13 #include <unistd.h>
14 #include <fcntl.h>
16 #include <gtk/gtk.h>
17 #include "collection.h"
19 #include "main.h"
20 #include "gui_support.h"
21 #include "filer.h"
22 #include "mount.h"
23 #include "menu.h"
24 #include "dnd.h"
25 #include "options.h"
26 #include "choices.h"
27 #include "savebox.h"
28 #include "type.h"
30 int number_of_windows = 0; /* Quit when this reaches 0 again... */
32 static void child_died(int signum)
34 int status;
35 int child;
37 /* Find out which children exited and allow them to die */
40 child = waitpid(-1, &status, WNOHANG);
42 if (child == 0 || child == -1)
43 return;
45 /* fprintf(stderr, "Child %d exited\n", child); */
47 } while (1);
50 #define BUFLEN 40
51 void stderr_cb(gpointer data, gint source, GdkInputCondition condition)
53 char buf[BUFLEN];
54 static GtkWidget *log = NULL;
55 static GtkWidget *window = NULL;
56 ssize_t len;
58 if (!window)
60 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
61 gtk_window_set_title(GTK_WINDOW(window), "ROX-Filer error log");
62 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
63 gtk_window_set_default_size(GTK_WINDOW(window), 600, 300);
64 gtk_signal_connect_object(GTK_OBJECT(window), "delete_event",
65 gtk_widget_hide, GTK_OBJECT(window));
66 log = gtk_text_new(NULL, NULL);
67 gtk_container_add(GTK_CONTAINER(window), log);
70 if (!GTK_WIDGET_MAPPED(window))
71 gtk_widget_show_all(window);
73 len = read(source, buf, BUFLEN);
74 if (len > 0)
75 gtk_text_insert(GTK_TEXT(log), NULL, NULL, NULL, buf, len);
78 int main(int argc, char **argv)
80 int stderr_pipe[2];
81 struct sigaction act = {};
83 gtk_init(&argc, &argv);
84 choices_init("ROX-Filer");
86 gui_support_init();
87 menu_init();
88 dnd_init();
89 filer_init();
90 mount_init();
91 options_init();
92 savebox_init();
93 type_init();
95 options_load();
97 /* Let child processes die */
98 act.sa_handler = child_died;
99 sigemptyset(&act.sa_mask);
100 act.sa_flags = SA_NOCLDSTOP;
101 sigaction(SIGCHLD, &act, NULL);
103 if (geteuid() == 0)
105 if (get_choice("!!!DANGER!!!",
106 "Running ROX-Filer as root is VERY dangerous. If it "
107 "had a warranty (it doesn't) then doing this would "
108 "void it.", 2,
109 "Don't click here", "Quit") != 0)
110 exit(EXIT_SUCCESS);
113 if (argc < 2)
114 filer_opendir(getenv("HOME"), FALSE, BOTTOM);
115 else
117 int i = 1;
118 gboolean panel = FALSE;
119 Side side = BOTTOM;
121 while (i < argc)
123 if (argv[i][0] == '-')
125 switch (argv[i][1] + (argv[i][2] << 8))
127 case 't': side = TOP; break;
128 case 'b': side = BOTTOM; break;
129 case 'l': side = LEFT; break;
130 case 'r': side = RIGHT; break;
131 default:
132 fprintf(stderr,
133 "Bad option.\n");
134 return EXIT_FAILURE;
136 panel = TRUE;
138 else
140 filer_opendir(argv[i], panel, side);
141 panel = FALSE;
142 side = BOTTOM;
144 i++;
148 pipe(stderr_pipe);
149 dup2(stderr_pipe[1], STDERR_FILENO);
150 gdk_input_add(stderr_pipe[0], GDK_INPUT_READ, stderr_cb, NULL);
151 fcntl(STDERR_FILENO, F_SETFD, 0);
153 gtk_main();
155 return EXIT_SUCCESS;