r4057: Don't abort on BadWindow errors. GTK bug #152151 is still not fixed after
[rox-filer.git] / ROX-Filer / src / main.c
blob0c038f7c614ceb7186fcccc057b2716b501fea52
1 /*
2 * $Id$
4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2005, the ROX-Filer team.
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 /* main.c - parses command-line options and parameters, plus some global
23 * housekeeping.
25 * New to the code and feeling lost? Read global.h now.
28 #include "config.h"
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <sys/types.h>
33 #include <signal.h>
34 #include <string.h>
35 #include <sys/wait.h>
36 #include <unistd.h>
37 #include <fcntl.h>
38 #include <pwd.h>
39 #include <grp.h>
40 #include <time.h>
41 #include <libxml/parser.h>
43 #ifdef HAVE_GETOPT_LONG
44 # include <getopt.h>
45 #endif
47 #include <gtk/gtk.h>
48 #include <gdk/gdkx.h> /* For rox_x_error */
50 #include "global.h"
52 #include "main.h"
53 #include "support.h"
54 #include "gui_support.h"
55 #include "filer.h"
56 #include "display.h"
57 #include "mount.h"
58 #include "menu.h"
59 #include "dnd.h"
60 #include "options.h"
61 #include "choices.h"
62 #include "type.h"
63 #include "pixmaps.h"
64 #include "dir.h"
65 #include "diritem.h"
66 #include "action.h"
67 #include "i18n.h"
68 #include "remote.h"
69 #include "pinboard.h"
70 #include "run.h"
71 #include "toolbar.h"
72 #include "bind.h"
73 #include "panel.h"
74 #include "session.h"
75 #include "minibuffer.h"
76 #include "xtypes.h"
78 int number_of_windows = 0; /* Quit when this reaches 0 again... */
79 int to_wakeup_pipe = -1; /* Write here to get noticed */
81 /* Information about the ROX-Filer process */
82 uid_t euid;
83 gid_t egid;
84 int ngroups; /* Number of supplemental groups */
85 gid_t *supplemental_groups = NULL;
87 /* Message to display at the top of each filer window */
88 const gchar *show_user_message = NULL;
90 int home_dir_len;
91 const char *home_dir, *app_dir;
93 GtkTooltips *tooltips = NULL;
95 #define COPYING \
96 N_("Copyright (C) 2005 Thomas Leonard.\n" \
97 "ROX-Filer comes with ABSOLUTELY NO WARRANTY,\n" \
98 "to the extent permitted by law.\n" \
99 "You may redistribute copies of ROX-Filer\n" \
100 "under the terms of the GNU General Public License.\n" \
101 "For more information about these matters, " \
102 "see the file named COPYING.\n")
104 #ifdef HAVE_GETOPT_LONG
105 # define USAGE N_("Try `ROX-Filer/AppRun --help' for more information.\n")
106 # define SHORT_ONLY_WARNING ""
107 #else
108 # define USAGE N_("Try `ROX-Filer/AppRun -h' for more information.\n")
109 # define SHORT_ONLY_WARNING \
110 _("NOTE: Your system does not support long options - \n" \
111 "you must use the short versions instead.\n\n")
112 #endif
114 #define BUGS_TO "<rox-devel@lists.sourceforge.net>"
116 #define HELP N_("Usage: ROX-Filer/AppRun [OPTION]... [FILE]...\n" \
117 "Open each directory or file listed, or the current working\n" \
118 "directory if no arguments are given.\n\n" \
119 " -b, --border=PANEL open PANEL as a border panel\n" \
120 " -B, --bottom=PANEL open PAN as a bottom-edge panel\n" \
121 " -c, --client-id=ID used for session management\n" \
122 " -d, --dir=DIR open DIR as directory (not application)\n" \
123 " -D, --close=DIR close DIR and its subdirectories\n" \
124 " -h, --help display this help and exit\n" \
125 " -l, --left=PANEL open PAN as a left-edge panel\n" \
126 " -m, --mime-type=FILE print MIME type of FILE and exit\n" \
127 " -n, --new start new copy; for debugging the filer\n" \
128 " -p, --pinboard=PIN use pinboard PIN as the pinboard\n" \
129 " -r, --right=PANEL open PAN as a right-edge panel\n" \
130 " -R, --RPC invoke method call read from stdin\n" \
131 " -s, --show=FILE open a directory showing FILE\n" \
132 " -S, --rox-session use default panel and pinboard options, and -n\n"\
133 " -t, --top=PANEL open PANEL as a top-edge panel\n" \
134 " -u, --user show user name in each window \n" \
135 " -v, --version display the version information and exit\n" \
136 " -x, --examine=FILE FILE has changed - re-examine it\n" \
137 "\nReport bugs to " BUGS_TO ".\n" \
138 "Home page (including updated versions): http://rox.sourceforge.net/\n")
140 #define SHORT_OPS "c:d:t:b:l:r:B:op:s:hvnux:m:D:RS"
142 #ifdef HAVE_GETOPT_LONG
143 static struct option long_opts[] =
145 {"dir", 1, NULL, 'd'},
146 {"top", 1, NULL, 't'},
147 {"bottom", 1, NULL, 'B'},
148 {"border", 1, NULL, 'b'},
149 {"left", 1, NULL, 'l'},
150 {"override", 0, NULL, 'o'},
151 {"pinboard", 1, NULL, 'p'},
152 {"right", 1, NULL, 'r'},
153 {"help", 0, NULL, 'h'},
154 {"version", 0, NULL, 'v'},
155 {"user", 0, NULL, 'u'},
156 {"new", 0, NULL, 'n'},
157 {"RPC", 0, NULL, 'R'},
158 {"show", 1, NULL, 's'},
159 {"rox-session", 0, NULL, 'S'},
160 {"examine", 1, NULL, 'x'},
161 {"close", 1, NULL, 'D'},
162 {"mime-type", 1, NULL, 'm'},
163 {"client-id", 1, NULL, 'c'},
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;
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 child_died(int signum);
197 static void child_died_callback(void);
198 static void wake_up_cb(gpointer data, gint source, GdkInputCondition condition);
199 static void xrandr_size_change(GdkScreen *screen, gpointer user_data);
200 static void add_default_panel_and_pinboard(xmlNodePtr body);
201 static GList *build_launch(Option *option, xmlNode *node, guchar *label);
203 /****************************************************************
204 * EXTERNAL INTERFACE *
205 ****************************************************************/
207 /* The value that goes with an option */
208 #define VALUE (*optarg == '=' ? optarg + 1 : optarg)
210 static int rox_x_error(Display *display, XErrorEvent *error)
212 gchar buf[64];
214 XGetErrorText(display, error->error_code, buf, 63);
216 g_warning ("The program '%s' received an X Window System error.\n"
217 "This probably reflects a bug in the program.\n"
218 "The error was '%s'.\n"
219 " (Details: serial %ld error_code %d request_code %d minor_code %d)\n"
220 " (Note to programmers: normally, X errors are reported asynchronously;\n"
221 " that is, you will receive the error a while after causing it.\n"
222 " To debug your program, run it with the --sync command line\n"
223 " option to change this behavior. You can then get a meaningful\n"
224 " backtrace from your debugger.)",
225 g_get_prgname (),
226 buf,
227 error->serial,
228 error->error_code,
229 error->request_code,
230 error->minor_code);
232 /* Try to cope with BadWindow errors */
233 if (error->error_code == 3)
235 g_warning(_("We got a BadWindow error from the X server. "
236 "This might be due to this GTK bug (during drag-and-drop?):\n"
237 "http://bugzilla.gnome.org/show_bug.cgi?id=152151\n"
238 "Trying to continue..."));
239 return 0;
242 abort();
245 /* Parses the command-line to work out what the user wants to do.
246 * Tries to send the request to an already-running copy of the filer.
247 * If that fails, it initialises all the other modules and executes the
248 * request itself.
250 int main(int argc, char **argv)
252 int wakeup_pipe[2];
253 int i;
254 struct sigaction act;
255 guchar *tmp, *dir;
256 gchar *client_id = NULL;
257 gboolean show_user = FALSE;
258 xmlDocPtr rpc, soap_rpc = NULL, reply;
259 xmlNodePtr body;
261 home_dir = g_get_home_dir();
262 home_dir_len = strlen(home_dir);
263 app_dir = g_strdup(getenv("APP_DIR"));
265 /* Get internationalisation up and running. This requires the
266 * choices system, to discover the user's preferred language.
268 choices_init();
269 options_init();
270 i18n_init();
271 xtype_init();
273 #ifdef HAVE_GNOME_VFS
274 if (!gnome_vfs_init())
275 g_warning("Failed to init gnomevfs!");
276 #endif
278 if (!app_dir)
280 g_warning("APP_DIR environment variable was unset!\n"
281 "Use the AppRun script to invoke ROX-Filer...\n");
282 app_dir = g_get_current_dir();
284 #ifdef HAVE_UNSETENV
285 else
287 /* Don't pass it on to our child processes... */
288 unsetenv("APP_DIR");
290 #endif
292 /* Sometimes we want to take special action when a child
293 * process exits. This hash table is used to convert the
294 * child's PID to the callback function.
296 death_callbacks = g_hash_table_new(NULL, NULL);
298 /* Find out some information about ourself */
299 euid = geteuid();
300 egid = getegid();
301 ngroups = getgroups(0, NULL);
302 if (ngroups < 0)
303 ngroups = 0;
304 else if (ngroups > 0)
306 supplemental_groups = g_malloc(sizeof(gid_t) * ngroups);
307 getgroups(ngroups, supplemental_groups);
310 if (argc == 2 && strcmp(argv[1], "-v") == 0)
312 /* This is used by install.sh to test if the filer
313 * compiled OK. Do this test before gtk_init so that
314 * we don't need an X server to install.
316 g_print("ROX-Filer %s\n", VERSION);
317 g_print(_(COPYING));
318 show_features();
319 return EXIT_SUCCESS;
322 option_add_int(&o_override_redirect, "override_redirect", FALSE);
324 option_add_int(&o_session_panel_or_pin, "session_panel_or_pin",
325 SESSION_BOTH);
326 option_add_string(&o_session_panel_name, "session_panel_name",
327 "Default");
328 option_add_string(&o_session_pinboard_name, "session_pinboard_name",
329 "Default");
330 option_register_widget("launch", build_launch);
332 /* The idea here is to convert the command-line arguments
333 * into a SOAP RPC.
334 * We attempt to invoke the call on an already-running copy of
335 * the filer if possible, or execute it ourselves if not.
337 rpc = soap_new(&body);
339 /* Note: must do this before checking our options,
340 * otherwise we report an error for Gtk's options.
342 gtk_init(&argc, &argv);
343 /* Set a default style for the collection widget */
344 gtk_rc_parse_string("style \"rox-default-collection-style\" {\n"
345 " bg[NORMAL] = \"#f3f3f3\"\n"
346 " fg[NORMAL] = \"#000000\"\n"
347 " bg[INSENSITIVE] = \"#bfbfbf\"\n"
348 " fg[INSENSITIVE] = \"#000000\"\n"
349 "}\n"
350 "style \"rox-default-pinboard-style\" {\n"
351 " bg[NORMAL] = \"#666666\"\n"
352 "}\n"
353 "widget \"rox-pinboard\" style : gtk "
354 "\"rox-default-pinboard-style\"\n"
356 "class \"Collection\" style : gtk "
357 "\"rox-default-collection-style\"\n");
359 g_signal_connect(gdk_screen_get_default(), "size-changed",
360 G_CALLBACK(xrandr_size_change), NULL);
362 /* Process each option in turn */
363 while (1)
365 int c;
366 #ifdef HAVE_GETOPT_LONG
367 int long_index;
368 c = getopt_long(argc, argv, SHORT_OPS,
369 long_opts, &long_index);
370 #else
371 c = getopt(argc, argv, SHORT_OPS);
372 #endif
374 if (c == EOF)
375 break; /* No more options */
377 switch (c)
379 case 'n':
380 new_copy = TRUE;
381 break;
382 case 'o':
383 info_message(_("The -o argument is no longer "
384 "used. You can turn on override "
385 "redirect from the Options box "
386 "instead."));
387 break;
388 case 'v':
389 g_print("ROX-Filer %s\n", VERSION);
390 g_print("%s", _(COPYING));
391 show_features();
392 return EXIT_SUCCESS;
393 case 'h':
394 g_print("%s", _(HELP));
395 g_print("%s", _(SHORT_ONLY_WARNING));
396 return EXIT_SUCCESS;
397 case 'D':
398 case 'd':
399 case 'x':
400 /* Argument is a path */
401 if (c == 'd' && VALUE[0] == '/')
402 tmp = g_strdup(VALUE);
403 else
404 tmp = pathdup(VALUE);
405 soap_add(body,
406 c == 'D' ? "CloseDir" :
407 c == 'd' ? "OpenDir" :
408 c == 'x' ? "Examine" : "Unknown",
409 "Filename", tmp,
410 NULL, NULL);
411 g_free(tmp);
412 break;
413 case 's':
414 tmp = g_path_get_dirname(VALUE);
416 if (tmp[0] == '/')
417 dir = NULL;
418 else
419 dir = pathdup(tmp);
421 soap_add(body, "Show",
422 "Directory", dir ? dir : tmp,
423 "Leafname", g_basename(VALUE));
424 g_free(tmp);
425 g_free(dir);
426 break;
427 case 'l':
428 case 'r':
429 case 't':
430 case 'B':
431 /* Argument is a leaf (or starts with /) */
432 soap_add(body, "Panel", "Name", VALUE,
433 "Side", c == 'l' ? "Left" :
434 c == 'r' ? "Right" :
435 c == 't' ? "Top" :
436 c == 'B' ? "Bottom" :
437 "Unkown");
438 break;
439 case 'b':
440 /* Argument is a leaf (or starts with /) */
441 if (*VALUE)
442 soap_add(body, "Panel", "Name", VALUE,
443 NULL, NULL);
444 else
445 soap_add(body, "Panel",
446 "Side", "Bottom",
447 NULL, NULL);
448 break;
449 case 'p':
450 soap_add(body, "Pinboard",
451 "Name", VALUE, NULL, NULL);
452 break;
453 case 'u':
454 show_user = TRUE;
455 break;
456 case 'm':
458 MIME_type *type;
459 type_init();
460 diritem_init();
461 pixmaps_init();
462 type = type_get_type(VALUE);
463 printf("%s/%s\n", type->media_type,
464 type->subtype);
465 return EXIT_SUCCESS;
467 case 'c':
468 client_id = g_strdup(VALUE);
469 break;
470 case 'R':
471 soap_rpc = xmlParseFile("-");
472 if (!soap_rpc)
473 g_error("Invalid XML in RPC");
474 break;
476 case 'S':
477 new_copy = TRUE;
478 add_default_panel_and_pinboard(body);
479 break;
481 default:
482 printf(_(USAGE));
483 return EXIT_FAILURE;
487 tooltips = gtk_tooltips_new();
489 if (euid == 0 || show_user)
490 show_user_message = g_strdup_printf(_("Running as user '%s'"),
491 user_name(euid));
493 /* Add each remaining (non-option) argument to the list of files
494 * to run.
496 i = optind;
497 while (i < argc)
499 tmp = pathdup(argv[i++]);
501 soap_add(body, "Run", "Filename", tmp, NULL, NULL);
503 g_free(tmp);
506 if (soap_rpc)
508 if (body->xmlChildrenNode)
509 g_error("Can't use -R with other options - sorry!");
510 xmlFreeDoc(rpc);
511 body = NULL;
512 rpc = soap_rpc;
514 else if (!body->xmlChildrenNode)
516 /* The user didn't request any action. Open the current
517 * directory.
519 guchar *dir;
521 dir = g_get_current_dir();
522 soap_add(body, "OpenDir", "Filename", dir, NULL, NULL);
523 g_free(dir);
526 option_add_int(&o_dnd_no_hostnames, "dnd_no_hostnames", 1);
528 /* Try to send the request to an already-running copy of the filer */
529 gui_support_init();
530 if (remote_init(rpc, new_copy))
531 return EXIT_SUCCESS; /* It worked - exit */
533 /* Put ourselves into the background (so 'rox' always works the
534 * same, whether we're already running or not).
535 * Not for -n, though (helps when debugging).
537 if (!new_copy)
539 int fd;
540 pid_t child;
542 child = fork();
543 if (child > 0)
544 _exit(0); /* Parent exits */
545 /* Otherwise we're the child (or an error occurred - ignore
546 * it!).
549 /* Close stdin. We don't need it, and it can cause problems if
550 * a child process wants a password, etc...
552 fd = open("/dev/null", O_RDONLY);
553 if (fd > 0)
555 close(0);
556 dup2(fd, 0);
557 close(fd);
561 /* Initialize the rest of the filer... */
563 pixmaps_init();
565 dnd_init();
566 bind_init();
567 dir_init();
568 diritem_init();
569 menu_init();
570 minibuffer_init();
571 filer_init();
572 toolbar_init();
573 display_init();
574 mount_init();
575 type_init();
576 action_init();
578 pinboard_init();
579 panel_init();
581 /* Let everyone update */
582 options_notify();
584 /* When we get a signal, we can't do much right then. Instead,
585 * we send a char down this pipe, which causes the main loop to
586 * deal with the event next time we're idle.
588 pipe(wakeup_pipe);
589 close_on_exec(wakeup_pipe[0], TRUE);
590 close_on_exec(wakeup_pipe[1], TRUE);
591 gdk_input_add_full(wakeup_pipe[0], GDK_INPUT_READ, wake_up_cb,
592 NULL, NULL);
593 to_wakeup_pipe = wakeup_pipe[1];
595 /* If the pipe is full then we're going to get woken up anyway... */
596 set_blocking(to_wakeup_pipe, FALSE);
598 /* Let child processes die */
599 act.sa_handler = child_died;
600 sigemptyset(&act.sa_mask);
601 act.sa_flags = SA_NOCLDSTOP;
602 sigaction(SIGCHLD, &act, NULL);
604 /* Ignore SIGPIPE - check for EPIPE errors instead */
605 act.sa_handler = SIG_IGN;
606 sigemptyset(&act.sa_mask);
607 act.sa_flags = 0;
608 sigaction(SIGPIPE, &act, NULL);
610 /* Set up session managament if available */
611 session_init(client_id);
612 g_free(client_id);
614 /* See if we need to migrate the Choices directories*/
615 choices_migrate();
617 /* Finally, execute the request */
618 reply = run_soap(rpc);
619 xmlFreeDoc(rpc);
620 if (reply)
622 /* Write the result, if any, to stdout */
623 save_xml_file(reply, "-");
624 xmlFreeDoc(reply);
627 /* Try to find out why we crash with GTK 2.4 */
628 XSetErrorHandler(rox_x_error);
630 /* Enter the main loop, processing events until all our windows
631 * are closed.
633 if (number_of_windows > 0)
634 gtk_main();
636 return EXIT_SUCCESS;
639 /* Register a function to be called when process number 'child' dies. */
640 void on_child_death(gint child, CallbackFn callback, gpointer data)
642 Callback *cb;
644 g_return_if_fail(callback != NULL);
646 cb = g_new(Callback, 1);
648 cb->callback = callback;
649 cb->data = data;
651 g_hash_table_insert(death_callbacks, GINT_TO_POINTER(child), cb);
654 void one_less_window(void)
656 if (--number_of_windows < 1)
657 gtk_main_quit();
660 /****************************************************************
661 * INTERNAL FUNCTIONS *
662 ****************************************************************/
664 static void show_features(void)
666 g_print("\n");
667 g_print(_("Compiled with GTK version %s\n"), GTK_VERSION);
668 g_print(_("Running with GTK version %d.%d.%d\n"),
669 gtk_major_version,
670 gtk_minor_version,
671 gtk_micro_version);
672 g_print("\n-- %s --\n\n", _("features set at compile time"));
673 g_print("%s... %s\n", _("Large File Support"),
674 #ifdef LARGE_FILE_SUPPORT
675 _("Yes")
676 #else
677 _("No")
678 #endif
680 g_print("%s... %s\n", _("GNOME-VFS library"),
681 # ifdef HAVE_GNOME_VFS
682 _("Yes")
683 # else
684 _("No (need 2.8.0 or later)")
685 # endif
687 g_print("%s... %s\n", _("Dnotify support"),
688 #ifdef USE_DNOTIFY
689 _("Yes")
690 #else
691 _("No")
692 #endif
694 g_print("%s... %s\n", _("Binary compatibility"),
695 #if defined(HAVE_APSYMBOLS_H) || defined(HAVE_APBUILD_APSYMBOLS_H)
696 _("Yes (can run with older glibc versions)")
697 #else
698 _("No (apsymbols.h not found)")
699 #endif
703 static void soap_add(xmlNodePtr body,
704 xmlChar *function,
705 const xmlChar *arg1_name, const xmlChar *arg1_value,
706 const xmlChar *arg2_name, const xmlChar *arg2_value)
708 xmlNodePtr node;
709 xmlNs *rox;
711 rox = xmlSearchNsByHref(body->doc, body, ROX_NS);
713 node = xmlNewChild(body, rox, function, NULL);
715 if (arg1_name)
717 xmlNewTextChild(node, rox, arg1_name, arg1_value);
718 if (arg2_name)
719 xmlNewTextChild(node, rox, arg2_name, arg2_value);
723 /* This is called as a signal handler; simply ensures that
724 * child_died_callback() will get called later.
726 static void child_died(int signum)
728 child_died_flag = TRUE;
729 write(to_wakeup_pipe, "\0", 1); /* Wake up! */
732 static void child_died_callback(void)
734 int status;
735 gint child;
737 child_died_flag = FALSE;
739 /* Find out which children exited and allow them to die */
742 Callback *cb;
744 child = waitpid(-1, &status, WNOHANG);
746 if (child == 0 || child == -1)
747 return;
749 cb = g_hash_table_lookup(death_callbacks,
750 GINT_TO_POINTER(child));
751 if (cb)
753 cb->callback(cb->data);
754 g_hash_table_remove(death_callbacks,
755 GINT_TO_POINTER(child));
758 } while (1);
761 #define BUFLEN 40
762 /* When data is written to_wakeup_pipe, this gets called from the event
763 * loop some time later. Useful for getting out of signal handlers, etc.
765 static void wake_up_cb(gpointer data, gint source, GdkInputCondition condition)
767 char buf[BUFLEN];
769 read(source, buf, BUFLEN);
771 if (child_died_flag)
772 child_died_callback();
773 #ifdef USE_DNOTIFY
774 if (dnotify_wakeup_flag)
775 dnotify_wakeup();
776 #endif
779 static void xrandr_size_change(GdkScreen *screen, gpointer user_data)
781 gui_store_screen_geometry(screen);
783 panel_update_size();
784 pinboard_update_size();
787 static void add_default_panel_and_pinboard(xmlNodePtr body)
789 char *name;
791 if (o_session_panel_or_pin.int_value != SESSION_PANEL_ONLY)
793 name=o_session_pinboard_name.value;
794 if (!name[0])
795 name="Default";
796 soap_add(body, "Pinboard","Name", name, NULL, NULL);
799 if (o_session_panel_or_pin.int_value != SESSION_PINBOARD_ONLY)
801 name = o_session_panel_name.value;
802 if (!name[0])
803 name="Default";
805 soap_add(body, "Panel", "Name", name, NULL, NULL);
809 static GtkWidget *launch_button_new(const char *label, const char *uri)
811 GtkWidget *button;
812 GClosure *closure;
814 button = button_new_mixed(GTK_STOCK_PREFERENCES, label);
815 closure = g_cclosure_new_swap(G_CALLBACK(launch_uri),
816 g_strdup(uri),
817 (GClosureNotify) g_free);
818 g_signal_connect_closure(button, "clicked", closure, FALSE);
820 return button;
823 static GList *build_launch(Option *option, xmlNode *node, guchar *label)
825 GtkWidget *align;
826 char *uri;
828 g_return_val_if_fail(option == NULL, NULL);
829 g_return_val_if_fail(label != NULL, NULL);
831 uri = xmlGetProp(node, "uri");
833 g_return_val_if_fail(uri != NULL, NULL);
835 align = gtk_alignment_new(0, 0.5, 0, 0);
837 gtk_container_add(GTK_CONTAINER(align),
838 launch_button_new(_(label), uri));
840 g_free(uri);
842 return g_list_append(NULL, align);