Use new panels config file to decide which panels to create with -S.
[rox-filer.git] / ROX-Filer / src / main.c
blob0522fee0c4ad4b9fb01444ae1d687bd8c0d3562f
1 /*
2 * ROX-Filer, filer for the ROX desktop project
3 * Copyright (C) 2006, Thomas Leonard and others (see changelog for details).
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
8 * any later version.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17 * Place, Suite 330, Boston, MA 02111-1307 USA
20 /* main.c - parses command-line options and parameters, plus some global
21 * housekeeping.
23 * New to the code and feeling lost? Read global.h now.
26 #include "config.h"
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <sys/types.h>
31 #include <signal.h>
32 #include <string.h>
33 #include <sys/wait.h>
34 #include <unistd.h>
35 #include <fcntl.h>
36 #include <pwd.h>
37 #include <grp.h>
38 #include <libxml/parser.h>
40 #ifdef HAVE_GETOPT_LONG
41 # include <getopt.h>
42 #endif
44 #include <gtk/gtk.h>
45 #include <gdk/gdkx.h> /* For rox_x_error */
47 #include "global.h"
49 #include "main.h"
50 #include "log.h"
51 #include "support.h"
52 #include "gui_support.h"
53 #include "filer.h"
54 #include "display.h"
55 #include "mount.h"
56 #include "menu.h"
57 #include "dnd.h"
58 #include "options.h"
59 #include "choices.h"
60 #include "type.h"
61 #include "pixmaps.h"
62 #include "dir.h"
63 #include "diritem.h"
64 #include "action.h"
65 #include "i18n.h"
66 #include "remote.h"
67 #include "pinboard.h"
68 #include "run.h"
69 #include "toolbar.h"
70 #include "bind.h"
71 #include "panel.h"
72 #include "session.h"
73 #include "minibuffer.h"
74 #include "xtypes.h"
76 int number_of_windows = 0; /* Quit when this reaches 0 again... */
77 int to_wakeup_pipe = -1; /* Write here to get noticed */
79 /* Information about the ROX-Filer process */
80 uid_t euid;
81 gid_t egid;
82 int ngroups; /* Number of supplemental groups */
83 gid_t *supplemental_groups = NULL;
85 /* Message to display at the top of each filer window */
86 const gchar *show_user_message = NULL;
88 int home_dir_len;
89 const char *home_dir, *app_dir;
91 GtkTooltips *tooltips = NULL;
93 #define COPYING \
94 N_("Copyright (C) 2005 Thomas Leonard.\n" \
95 "ROX-Filer comes with ABSOLUTELY NO WARRANTY,\n" \
96 "to the extent permitted by law.\n" \
97 "You may redistribute copies of ROX-Filer\n" \
98 "under the terms of the GNU General Public License.\n" \
99 "For more information about these matters, " \
100 "see the file named COPYING.\n")
102 #ifdef HAVE_GETOPT_LONG
103 # define USAGE N_("Try `ROX-Filer/AppRun --help' for more information.\n")
104 # define SHORT_ONLY_WARNING ""
105 #else
106 # define USAGE N_("Try `ROX-Filer/AppRun -h' for more information.\n")
107 # define SHORT_ONLY_WARNING \
108 _("NOTE: Your system does not support long options - \n" \
109 "you must use the short versions instead.\n\n")
110 #endif
112 #define BUGS_TO "<rox-devel@lists.sourceforge.net>"
114 #define HELP N_("Usage: ROX-Filer/AppRun [OPTION]... [FILE]...\n" \
115 "Open each directory or file listed, or the current working\n" \
116 "directory if no arguments are given.\n\n" \
117 " -b, --border=PANEL open PANEL as a border panel\n" \
118 " -B, --bottom=PANEL open PAN as a bottom-edge panel\n" \
119 " -c, --client-id=ID used for session management\n" \
120 " -d, --dir=DIR open DIR as directory (not application)\n" \
121 " -D, --close=DIR close DIR and its subdirectories\n" \
122 " -h, --help display this help and exit\n" \
123 " -l, --left=PANEL open PAN as a left-edge panel\n" \
124 " -m, --mime-type=FILE print MIME type of FILE and exit\n" \
125 " -n, --new start new copy; for debugging the filer\n" \
126 " -p, --pinboard=PIN use pinboard PIN as the pinboard\n" \
127 " -r, --right=PANEL open PAN as a right-edge panel\n" \
128 " -R, --RPC invoke method call read from stdin\n" \
129 " -s, --show=FILE open a directory showing FILE\n" \
130 " -S, --rox-session use default panel and pinboard options, and -n\n"\
131 " -t, --top=PANEL open PANEL as a top-edge panel\n" \
132 " -u, --user show user name in each window \n" \
133 " -U, --url=URL open file or directory in URI form\n" \
134 " -v, --version display the version information and exit\n" \
135 " -x, --examine=FILE FILE has changed - re-examine it\n" \
136 "\nReport bugs to %s.\n" \
137 "Home page (including updated versions): http://rox.sourceforge.net/\n")
139 #define SHORT_OPS "c:d:t:b:l:r:B:op:s:hvnux:m:D:RSU:"
141 #ifdef HAVE_GETOPT_LONG
142 static struct option long_opts[] =
144 {"dir", 1, NULL, 'd'},
145 {"top", 1, NULL, 't'},
146 {"bottom", 1, NULL, 'B'},
147 {"border", 1, NULL, 'b'},
148 {"left", 1, NULL, 'l'},
149 {"override", 0, NULL, 'o'},
150 {"pinboard", 1, NULL, 'p'},
151 {"right", 1, NULL, 'r'},
152 {"help", 0, NULL, 'h'},
153 {"version", 0, NULL, 'v'},
154 {"user", 0, NULL, 'u'},
155 {"new", 0, NULL, 'n'},
156 {"RPC", 0, NULL, 'R'},
157 {"show", 1, NULL, 's'},
158 {"rox-session", 0, NULL, 'S'},
159 {"examine", 1, NULL, 'x'},
160 {"close", 1, NULL, 'D'},
161 {"mime-type", 1, NULL, 'm'},
162 {"client-id", 1, NULL, 'c'},
163 {"url", 1, NULL, 'u'},
164 {NULL, 0, NULL, 0},
166 #endif
168 /* Take control of panels away from WM? */
169 Option o_override_redirect;
171 /* Options used when we are called by ROX-Session */
172 enum {
173 SESSION_PANEL_ONLY,
174 SESSION_PINBOARD_ONLY,
175 SESSION_BOTH,
177 Option o_session_panel_or_pin;
178 Option o_session_panel_name; /* Now a comma-separated list */
179 Option o_session_pinboard_name;
181 /* Always start a new filer, even if one seems to be already running */
182 gboolean new_copy = FALSE;
184 /* Maps child PIDs to Callback pointers */
185 static GHashTable *death_callbacks = NULL;
186 static gboolean child_died_flag = FALSE;
188 Option o_dnd_no_hostnames;
190 /* Static prototypes */
191 static void show_features(void);
192 static void soap_add(xmlNodePtr body,
193 xmlChar *function,
194 const xmlChar *arg1_name, const xmlChar *arg1_value,
195 const xmlChar *arg2_name, const xmlChar *arg2_value);
196 static void soap_reply(xmlDocPtr reply, gboolean rpc_mode);
197 static void child_died(int signum);
198 static void child_died_callback(void);
199 static void wake_up_cb(gpointer data, gint source, GdkInputCondition condition);
200 static void xrandr_size_change(GdkScreen *screen, gpointer user_data);
201 static void add_default_panel_and_pinboard(xmlNodePtr body);
202 static GList *build_launch(Option *option, xmlNode *node, guchar *label);
204 /****************************************************************
205 * EXTERNAL INTERFACE *
206 ****************************************************************/
208 /* The value that goes with an option */
209 #define VALUE (*optarg == '=' ? optarg + 1 : optarg)
211 static int rox_x_error(Display *display, XErrorEvent *error)
213 gchar buf[64];
215 XGetErrorText(display, error->error_code, buf, 63);
217 g_warning ("The program '%s' received an X Window System error.\n"
218 "This probably reflects a bug in the program.\n"
219 "The error was '%s'.\n"
220 " (Details: serial %ld error_code %d request_code %d minor_code %d)\n"
221 " (Note to programmers: normally, X errors are reported asynchronously;\n"
222 " that is, you will receive the error a while after causing it.\n"
223 " To debug your program, run it with the --sync command line\n"
224 " option to change this behavior. You can then get a meaningful\n"
225 " backtrace from your debugger.)",
226 g_get_prgname (),
227 buf,
228 error->serial,
229 error->error_code,
230 error->request_code,
231 error->minor_code);
233 /* Try to cope with BadWindow errors */
234 if (error->error_code == BadWindow || error->error_code == BadDrawable)
236 g_warning(_("We got a BadWindow error from the X server. "
237 "This might be due to this GTK bug (during drag-and-drop?):\n"
238 "http://bugzilla.gnome.org/show_bug.cgi?id=152151\n"
239 "Trying to continue..."));
240 return 0;
243 abort();
246 /* Parses the command-line to work out what the user wants to do.
247 * Tries to send the request to an already-running copy of the filer.
248 * If that fails, it initialises all the other modules and executes the
249 * request itself.
251 int main(int argc, char **argv)
253 int wakeup_pipe[2];
254 int i;
255 struct sigaction act;
256 guchar *tmp, *dir;
257 gchar *client_id = NULL;
258 gboolean show_user = FALSE;
259 gboolean rpc_mode = FALSE;
260 xmlDocPtr rpc, soap_rpc = NULL, reply;
261 xmlNodePtr body;
262 int fd, ofd0=-1;
264 /* Relocate stdin. We do need it (-R), but it can cause problems if
265 * a child process wants a password, etc...
266 * Do this BEFORE opening anything (e.g., the X connection), in
267 * case fd 0 isn't open at this point.
269 fd = open("/dev/null", O_RDONLY);
270 if (fd > 0)
272 ofd0=dup(0);
273 close(0);
274 dup2(fd, 0);
275 close(fd);
278 home_dir = g_get_home_dir();
279 home_dir_len = strlen(home_dir);
280 app_dir = g_strdup(getenv("APP_DIR"));
282 /* Get internationalisation up and running. This requires the
283 * choices system, to discover the user's preferred language.
285 choices_init();
286 options_init();
287 i18n_init();
288 xattr_init();
290 if (!app_dir)
292 g_warning("APP_DIR environment variable was unset!\n"
293 "Use the AppRun script to invoke ROX-Filer...\n");
294 app_dir = g_get_current_dir();
296 #ifdef HAVE_UNSETENV
297 else
299 /* Don't pass it on to our child processes... */
300 unsetenv("APP_DIR");
302 #endif
304 /* Sometimes we want to take special action when a child
305 * process exits. This hash table is used to convert the
306 * child's PID to the callback function.
308 death_callbacks = g_hash_table_new(NULL, NULL);
310 /* Find out some information about ourself */
311 euid = geteuid();
312 egid = getegid();
313 ngroups = getgroups(0, NULL);
314 if (ngroups < 0)
315 ngroups = 0;
316 else if (ngroups > 0)
318 supplemental_groups = g_malloc(sizeof(gid_t) * ngroups);
319 getgroups(ngroups, supplemental_groups);
322 if (argc == 2 && strcmp(argv[1], "-v") == 0)
324 /* This is used by install.sh to test if the filer
325 * compiled OK. Do this test before gtk_init so that
326 * we don't need an X server to install.
328 g_print("ROX-Filer %s\n", VERSION);
329 g_print(_(COPYING));
330 show_features();
331 return EXIT_SUCCESS;
334 option_add_int(&o_override_redirect, "override_redirect", FALSE);
336 option_add_int(&o_session_panel_or_pin, "session_panel_or_pin",
337 SESSION_BOTH);
338 option_add_string(&o_session_panel_name, "session_panel_name",
339 "Default");
340 option_add_string(&o_session_pinboard_name, "session_pinboard_name",
341 "Default");
342 option_register_widget("launch", build_launch);
344 /* The idea here is to convert the command-line arguments
345 * into a SOAP RPC.
346 * We attempt to invoke the call on an already-running copy of
347 * the filer if possible, or execute it ourselves if not.
349 rpc = soap_new(&body);
351 /* Note: must do this before checking our options,
352 * otherwise we report an error for Gtk's options.
354 gtk_init(&argc, &argv);
355 /* Set a default style for the collection widget */
356 gtk_rc_parse_string("style \"rox-default-collection-style\" {\n"
357 " bg[NORMAL] = \"#f3f3f3\"\n"
358 " fg[NORMAL] = \"#000000\"\n"
359 " bg[INSENSITIVE] = \"#bfbfbf\"\n"
360 " fg[INSENSITIVE] = \"#000000\"\n"
361 "}\n"
362 "style \"rox-default-pinboard-style\" {\n"
363 " bg[NORMAL] = \"#666666\"\n"
364 "}\n"
365 "widget \"rox-pinboard\" style : gtk "
366 "\"rox-default-pinboard-style\"\n"
368 "class \"Collection\" style : gtk "
369 "\"rox-default-collection-style\"\n");
371 g_signal_connect(gdk_screen_get_default(), "size-changed",
372 G_CALLBACK(xrandr_size_change), NULL);
374 /* Process each option in turn */
375 while (1)
377 int c;
378 #ifdef HAVE_GETOPT_LONG
379 int long_index;
380 c = getopt_long(argc, argv, SHORT_OPS,
381 long_opts, &long_index);
382 #else
383 c = getopt(argc, argv, SHORT_OPS);
384 #endif
386 if (c == EOF)
387 break; /* No more options */
389 switch (c)
391 case 'n':
392 new_copy = TRUE;
393 break;
394 case 'o':
395 info_message(_("The -o argument is no longer "
396 "used. You can turn on override "
397 "redirect from the Options box "
398 "instead."));
399 break;
400 case 'v':
401 g_print("ROX-Filer %s\n", VERSION);
402 g_print("%s", _(COPYING));
403 show_features();
404 return EXIT_SUCCESS;
405 case 'h':
406 g_print(_(HELP), BUGS_TO);
407 g_print("%s", _(SHORT_ONLY_WARNING));
408 return EXIT_SUCCESS;
409 case 'D':
410 case 'd':
411 case 'x':
412 /* Argument is a path */
413 if (c == 'd' && VALUE[0] == '/')
414 tmp = g_strdup(VALUE);
415 else
416 tmp = pathdup(VALUE);
417 soap_add(body,
418 c == 'D' ? "CloseDir" :
419 c == 'd' ? "OpenDir" :
420 c == 'x' ? "Examine" : "Unknown",
421 "Filename", tmp,
422 NULL, NULL);
423 g_free(tmp);
424 break;
425 case 's':
426 tmp = g_path_get_dirname(VALUE);
428 if (tmp[0] == '/')
429 dir = NULL;
430 else
431 dir = pathdup(tmp);
433 soap_add(body, "Show",
434 "Directory", dir ? dir : tmp,
435 "Leafname", g_basename(VALUE));
436 g_free(tmp);
437 g_free(dir);
438 break;
439 case 'l':
440 case 'r':
441 case 't':
442 case 'B':
443 /* Argument is a leaf (or starts with /) */
444 soap_add(body, "Panel", "Name", VALUE,
445 "Side", c == 'l' ? "Left" :
446 c == 'r' ? "Right" :
447 c == 't' ? "Top" :
448 c == 'B' ? "Bottom" :
449 "Unkown");
450 break;
451 case 'b':
452 /* Argument is a leaf (or starts with /) */
453 if (*VALUE)
454 soap_add(body, "Panel", "Name", VALUE,
455 NULL, NULL);
456 else
457 soap_add(body, "Panel",
458 "Side", "Bottom",
459 NULL, NULL);
460 break;
461 case 'p':
462 soap_add(body, "Pinboard",
463 "Name", VALUE, NULL, NULL);
464 break;
465 case 'u':
466 show_user = TRUE;
467 break;
468 case 'm':
470 MIME_type *type;
471 type_init();
472 diritem_init();
473 pixmaps_init();
474 type = type_get_type(VALUE);
475 printf("%s/%s\n", type->media_type,
476 type->subtype);
477 return EXIT_SUCCESS;
479 case 'c':
480 client_id = g_strdup(VALUE);
481 break;
482 case 'R':
483 /* Reconnect stdin */
484 if(ofd0>-1) {
485 close(0);
486 dup2(ofd0, 0);
488 soap_rpc = xmlParseFile("-");
489 if (!soap_rpc)
490 g_error("Invalid XML in RPC");
491 /* Disconnect stdin again */
492 fd = open("/dev/null", O_RDONLY);
493 if (fd > 0)
495 close(0);
496 dup2(fd, 0);
497 close(fd);
499 /* Want to print return uninterpreted */
500 rpc_mode=TRUE;
502 break;
504 case 'S':
505 new_copy = TRUE;
506 add_default_panel_and_pinboard(body);
507 session_auto_respawn = TRUE;
508 break;
510 case 'U':
511 soap_add(body, "RunURI",
512 "URI", VALUE, NULL, NULL);
513 break;
515 default:
516 printf(_(USAGE));
517 return EXIT_FAILURE;
521 tooltips = gtk_tooltips_new();
523 if (euid == 0 || show_user)
524 show_user_message = g_strdup_printf(_("Running as user '%s'"),
525 user_name(euid));
527 /* Add each remaining (non-option) argument to the list of files
528 * to run.
530 i = optind;
531 while (i < argc)
533 tmp = pathdup(argv[i++]);
535 soap_add(body, "Run", "Filename", tmp, NULL, NULL);
537 g_free(tmp);
540 if (soap_rpc)
542 if (body->xmlChildrenNode)
543 g_error("Can't use -R with other options - sorry!");
544 xmlFreeDoc(rpc);
545 body = NULL;
546 rpc = soap_rpc;
548 else if (!body->xmlChildrenNode)
550 /* The user didn't request any action. Open the current
551 * directory.
553 guchar *dir;
555 dir = g_get_current_dir();
556 soap_add(body, "OpenDir", "Filename", dir, NULL, NULL);
557 g_free(dir);
560 option_add_int(&o_dnd_no_hostnames, "dnd_no_hostnames", 1);
562 /* Try to send the request to an already-running copy of the filer */
563 gui_support_init();
564 if (remote_init(rpc, new_copy))
565 return EXIT_SUCCESS; /* It worked - exit */
567 /* Put ourselves into the background (so 'rox' always works the
568 * same, whether we're already running or not).
569 * Not for -n, though (helps when debugging).
571 if (!new_copy)
573 pid_t child;
575 child = fork();
576 if (child > 0)
577 _exit(0); /* Parent exits */
578 /* Otherwise we're the child (or an error occurred - ignore
579 * it!).
583 /* Initialize the rest of the filer... */
585 pixmaps_init();
587 log_init();
588 dnd_init();
589 bind_init();
590 dir_init();
591 diritem_init();
592 menu_init();
593 minibuffer_init();
594 filer_init();
595 toolbar_init();
596 display_init();
597 mount_init();
598 type_init();
599 action_init();
601 pinboard_init();
602 panel_init();
604 /* Let everyone update */
605 options_notify();
607 /* When we get a signal, we can't do much right then. Instead,
608 * we send a char down this pipe, which causes the main loop to
609 * deal with the event next time we're idle.
611 pipe(wakeup_pipe);
612 close_on_exec(wakeup_pipe[0], TRUE);
613 close_on_exec(wakeup_pipe[1], TRUE);
614 gdk_input_add_full(wakeup_pipe[0], GDK_INPUT_READ, wake_up_cb,
615 NULL, NULL);
616 to_wakeup_pipe = wakeup_pipe[1];
618 /* If the pipe is full then we're going to get woken up anyway... */
619 set_blocking(to_wakeup_pipe, FALSE);
621 /* Let child processes die */
622 act.sa_handler = child_died;
623 sigemptyset(&act.sa_mask);
624 act.sa_flags = SA_NOCLDSTOP;
625 sigaction(SIGCHLD, &act, NULL);
627 /* Ignore SIGPIPE - check for EPIPE errors instead */
628 act.sa_handler = SIG_IGN;
629 sigemptyset(&act.sa_mask);
630 act.sa_flags = 0;
631 sigaction(SIGPIPE, &act, NULL);
633 /* Set up session managament if available */
634 session_init(client_id);
635 g_free(client_id);
637 /* See if we need to migrate the Choices directories*/
638 choices_migrate();
640 /* Finally, execute the request */
641 reply = run_soap(rpc);
642 xmlFreeDoc(rpc);
643 soap_reply(reply, rpc_mode);
645 /* Try to find out why we crash with GTK 2.4 */
646 XSetErrorHandler(rox_x_error);
648 /* Enter the main loop, processing events until all our windows
649 * are closed.
651 if (number_of_windows > 0)
652 gtk_main();
654 return EXIT_SUCCESS;
657 /* Register a function to be called when process number 'child' dies. */
658 void on_child_death(gint child, CallbackFn callback, gpointer data)
660 Callback *cb;
662 g_return_if_fail(callback != NULL);
664 cb = g_new(Callback, 1);
666 cb->callback = callback;
667 cb->data = data;
669 g_hash_table_insert(death_callbacks, GINT_TO_POINTER(child), cb);
672 void one_less_window(void)
674 if (--number_of_windows < 1)
675 gtk_main_quit();
678 /****************************************************************
679 * INTERNAL FUNCTIONS *
680 ****************************************************************/
682 static void show_features(void)
684 g_print("\n");
685 g_print(_("Compiled with GTK version %s\n"), GTK_VERSION);
686 g_print(_("Running with GTK version %d.%d.%d\n"),
687 gtk_major_version,
688 gtk_minor_version,
689 gtk_micro_version);
690 g_print("\n-- %s --\n\n", _("features set at compile time"));
691 g_print("%s... %s\n", _("Large File Support"),
692 #ifdef LARGE_FILE_SUPPORT
693 _("Yes")
694 #else
695 _("No")
696 #endif
698 g_print("%s... %s\n", _("Dnotify support"),
699 #ifdef USE_DNOTIFY
700 _("Yes")
701 #else
702 _("No")
703 #endif
705 g_print("%s... %s\n", _("Binary compatibility"),
706 #if defined(HAVE_APSYMBOLS_H) || defined(HAVE_APBUILD_APSYMBOLS_H)
707 _("Yes (can run with older glibc versions)")
708 #else
709 _("No (apsymbols.h not found)")
710 #endif
713 g_print("%s... %s\n", _("Extended attribute support"),
714 xattr_supported(NULL)? _("Yes"): _("No"));
717 static void soap_add(xmlNodePtr body,
718 xmlChar *function,
719 const xmlChar *arg1_name, const xmlChar *arg1_value,
720 const xmlChar *arg2_name, const xmlChar *arg2_value)
722 xmlNodePtr node;
723 xmlNs *rox;
725 rox = xmlSearchNsByHref(body->doc, body, ROX_NS);
727 node = xmlNewChild(body, rox, function, NULL);
729 if (arg1_name)
731 xmlNewTextChild(node, rox, arg1_name, arg1_value);
732 if (arg2_name)
733 xmlNewTextChild(node, rox, arg2_name, arg2_value);
737 static void soap_reply(xmlDocPtr reply, gboolean rpc_mode)
739 gboolean print=TRUE;
741 if(!reply)
742 return;
744 if(!rpc_mode) {
745 gchar **errs=extract_soap_errors(reply);
747 if(errs) {
748 int i;
750 print=FALSE;
752 for(i=0; errs[i]; i++)
753 fprintf(stderr, "%s\n", errs[i]);
755 g_strfreev(errs);
759 /* Write the result, if any, to stdout */
760 if(print)
761 save_xml_file(reply, "-");
762 xmlFreeDoc(reply);
765 /* This is called as a signal handler; simply ensures that
766 * child_died_callback() will get called later.
768 static void child_died(int signum)
770 child_died_flag = TRUE;
771 write(to_wakeup_pipe, "\0", 1); /* Wake up! */
774 static void child_died_callback(void)
776 int status;
777 gint child;
779 child_died_flag = FALSE;
781 /* Find out which children exited and allow them to die */
784 Callback *cb;
786 child = waitpid(-1, &status, WNOHANG);
788 if (child == 0 || child == -1)
789 return;
791 cb = g_hash_table_lookup(death_callbacks,
792 GINT_TO_POINTER(child));
793 if (cb)
795 cb->callback(cb->data);
796 g_hash_table_remove(death_callbacks,
797 GINT_TO_POINTER(child));
800 } while (1);
803 #define BUFLEN 40
804 /* When data is written to_wakeup_pipe, this gets called from the event
805 * loop some time later. Useful for getting out of signal handlers, etc.
807 static void wake_up_cb(gpointer data, gint source, GdkInputCondition condition)
809 char buf[BUFLEN];
811 read(source, buf, BUFLEN);
813 if (child_died_flag)
814 child_died_callback();
815 #ifdef USE_DNOTIFY
816 if (dnotify_wakeup_flag)
817 dnotify_wakeup();
818 #endif
821 static void xrandr_size_change(GdkScreen *screen, gpointer user_data)
823 gui_store_screen_geometry(screen);
825 panel_update_size();
826 pinboard_update_size();
829 static void add_default_panel_and_pinboard(xmlNodePtr body)
831 const char *name;
833 if (o_session_panel_or_pin.int_value != SESSION_PANEL_ONLY)
835 name=o_session_pinboard_name.value;
836 if (!name[0])
837 name="Default";
838 soap_add(body, "Pinboard","Name", name, NULL, NULL);
841 if (o_session_panel_or_pin.int_value != SESSION_PINBOARD_ONLY)
843 gboolean use_old_option = TRUE;
844 GIOChannel *fp = NULL;
845 GError *err = NULL;
846 char *line = NULL;
847 gsize term;
848 char *filename = choices_find_xdg_path_load("panels",
849 "ROX-Filer", "rox.sourceforge.net");
851 if (filename)
852 fp = g_io_channel_new_file(filename, "r", &err);
853 while (fp && g_io_channel_read_line(fp, &line, NULL, &term, &err) ==
854 G_IO_STATUS_NORMAL)
856 if (line && (line[term] = 0, line[0]))
858 soap_add(body, "Panel", "Name", line, NULL, NULL);
859 use_old_option = FALSE;
862 if (err)
864 g_critical(_("Unable to read '%s': %s"),
865 filename, err->message);
866 g_error_free(err);
868 if (fp)
869 g_io_channel_shutdown(fp, FALSE, NULL);
870 if (use_old_option)
872 name = o_session_panel_name.value;
873 if (!name[0])
874 name="Default";
875 soap_add(body, "Panel", "Name", name, NULL, NULL);
877 g_free(filename);
881 static GtkWidget *launch_button_new(const char *label, const char *uri)
883 GtkWidget *button;
884 GClosure *closure;
885 const gchar *slash;
886 gchar *tip;
888 button = button_new_mixed(GTK_STOCK_PREFERENCES, label);
889 closure = g_cclosure_new_swap(G_CALLBACK(launch_uri),
890 g_strdup(uri),
891 (GClosureNotify) g_free);
892 g_signal_connect_closure(button, "clicked", closure, FALSE);
894 allow_right_click(button);
896 slash = strrchr(uri, '/');
897 if (!slash)
898 slash = uri - 1;
899 tip = g_strdup_printf(
900 _("Left-click to run %s.\n"
901 "Right-click for a list of versions."),
902 slash + 1);
904 gtk_tooltips_set_tip(tooltips, button, tip, NULL);
906 g_free(tip);
908 return button;
911 static GList *build_launch(Option *option, xmlNode *node, guchar *label)
913 GtkWidget *align;
914 char *uri;
916 g_return_val_if_fail(option == NULL, NULL);
917 g_return_val_if_fail(label != NULL, NULL);
919 uri = xmlGetProp(node, "uri");
921 g_return_val_if_fail(uri != NULL, NULL);
923 align = gtk_alignment_new(0, 0.5, 0, 0);
925 gtk_container_add(GTK_CONTAINER(align),
926 launch_button_new(_(label), uri));
928 g_free(uri);
930 return g_list_append(NULL, align);