r4716: Fixes for the filter directories option: Initialize properly, inherit from
[rox-filer.git] / ROX-Filer / src / main.c
blob2bdfa4c79aa79f917a12b2371cd624ad6f7f701f
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 "support.h"
51 #include "gui_support.h"
52 #include "filer.h"
53 #include "display.h"
54 #include "mount.h"
55 #include "menu.h"
56 #include "dnd.h"
57 #include "options.h"
58 #include "choices.h"
59 #include "type.h"
60 #include "pixmaps.h"
61 #include "dir.h"
62 #include "diritem.h"
63 #include "action.h"
64 #include "i18n.h"
65 #include "remote.h"
66 #include "pinboard.h"
67 #include "run.h"
68 #include "toolbar.h"
69 #include "bind.h"
70 #include "panel.h"
71 #include "session.h"
72 #include "minibuffer.h"
73 #include "xtypes.h"
75 int number_of_windows = 0; /* Quit when this reaches 0 again... */
76 int to_wakeup_pipe = -1; /* Write here to get noticed */
78 /* Information about the ROX-Filer process */
79 uid_t euid;
80 gid_t egid;
81 int ngroups; /* Number of supplemental groups */
82 gid_t *supplemental_groups = NULL;
84 /* Message to display at the top of each filer window */
85 const gchar *show_user_message = NULL;
87 int home_dir_len;
88 const char *home_dir, *app_dir;
90 GtkTooltips *tooltips = NULL;
92 #define COPYING \
93 N_("Copyright (C) 2005 Thomas Leonard.\n" \
94 "ROX-Filer comes with ABSOLUTELY NO WARRANTY,\n" \
95 "to the extent permitted by law.\n" \
96 "You may redistribute copies of ROX-Filer\n" \
97 "under the terms of the GNU General Public License.\n" \
98 "For more information about these matters, " \
99 "see the file named COPYING.\n")
101 #ifdef HAVE_GETOPT_LONG
102 # define USAGE N_("Try `ROX-Filer/AppRun --help' for more information.\n")
103 # define SHORT_ONLY_WARNING ""
104 #else
105 # define USAGE N_("Try `ROX-Filer/AppRun -h' for more information.\n")
106 # define SHORT_ONLY_WARNING \
107 _("NOTE: Your system does not support long options - \n" \
108 "you must use the short versions instead.\n\n")
109 #endif
111 #define BUGS_TO "<rox-devel@lists.sourceforge.net>"
113 #define HELP N_("Usage: ROX-Filer/AppRun [OPTION]... [FILE]...\n" \
114 "Open each directory or file listed, or the current working\n" \
115 "directory if no arguments are given.\n\n" \
116 " -b, --border=PANEL open PANEL as a border panel\n" \
117 " -B, --bottom=PANEL open PAN as a bottom-edge panel\n" \
118 " -c, --client-id=ID used for session management\n" \
119 " -d, --dir=DIR open DIR as directory (not application)\n" \
120 " -D, --close=DIR close DIR and its subdirectories\n" \
121 " -h, --help display this help and exit\n" \
122 " -l, --left=PANEL open PAN as a left-edge panel\n" \
123 " -m, --mime-type=FILE print MIME type of FILE and exit\n" \
124 " -n, --new start new copy; for debugging the filer\n" \
125 " -p, --pinboard=PIN use pinboard PIN as the pinboard\n" \
126 " -r, --right=PANEL open PAN as a right-edge panel\n" \
127 " -R, --RPC invoke method call read from stdin\n" \
128 " -s, --show=FILE open a directory showing FILE\n" \
129 " -S, --rox-session use default panel and pinboard options, and -n\n"\
130 " -t, --top=PANEL open PANEL as a top-edge panel\n" \
131 " -u, --user show user name in each window \n" \
132 " -v, --version display the version information and exit\n" \
133 " -x, --examine=FILE FILE has changed - re-examine it\n" \
134 "\nReport bugs to %s.\n" \
135 "Home page (including updated versions): http://rox.sourceforge.net/\n")
137 #define SHORT_OPS "c:d:t:b:l:r:B:op:s:hvnux:m:D:RS"
139 #ifdef HAVE_GETOPT_LONG
140 static struct option long_opts[] =
142 {"dir", 1, NULL, 'd'},
143 {"top", 1, NULL, 't'},
144 {"bottom", 1, NULL, 'B'},
145 {"border", 1, NULL, 'b'},
146 {"left", 1, NULL, 'l'},
147 {"override", 0, NULL, 'o'},
148 {"pinboard", 1, NULL, 'p'},
149 {"right", 1, NULL, 'r'},
150 {"help", 0, NULL, 'h'},
151 {"version", 0, NULL, 'v'},
152 {"user", 0, NULL, 'u'},
153 {"new", 0, NULL, 'n'},
154 {"RPC", 0, NULL, 'R'},
155 {"show", 1, NULL, 's'},
156 {"rox-session", 0, NULL, 'S'},
157 {"examine", 1, NULL, 'x'},
158 {"close", 1, NULL, 'D'},
159 {"mime-type", 1, NULL, 'm'},
160 {"client-id", 1, NULL, 'c'},
161 {NULL, 0, NULL, 0},
163 #endif
165 /* Take control of panels away from WM? */
166 Option o_override_redirect;
168 /* Options used when we are called by ROX-Session */
169 enum {
170 SESSION_PANEL_ONLY,
171 SESSION_PINBOARD_ONLY,
172 SESSION_BOTH,
174 Option o_session_panel_or_pin;
175 Option o_session_panel_name;
176 Option o_session_pinboard_name;
178 /* Always start a new filer, even if one seems to be already running */
179 gboolean new_copy = FALSE;
181 /* Maps child PIDs to Callback pointers */
182 static GHashTable *death_callbacks = NULL;
183 static gboolean child_died_flag = FALSE;
185 Option o_dnd_no_hostnames;
187 /* Static prototypes */
188 static void show_features(void);
189 static void soap_add(xmlNodePtr body,
190 xmlChar *function,
191 const xmlChar *arg1_name, const xmlChar *arg1_value,
192 const xmlChar *arg2_name, const xmlChar *arg2_value);
193 static void child_died(int signum);
194 static void child_died_callback(void);
195 static void wake_up_cb(gpointer data, gint source, GdkInputCondition condition);
196 static void xrandr_size_change(GdkScreen *screen, gpointer user_data);
197 static void add_default_panel_and_pinboard(xmlNodePtr body);
198 static GList *build_launch(Option *option, xmlNode *node, guchar *label);
200 /****************************************************************
201 * EXTERNAL INTERFACE *
202 ****************************************************************/
204 /* The value that goes with an option */
205 #define VALUE (*optarg == '=' ? optarg + 1 : optarg)
207 static int rox_x_error(Display *display, XErrorEvent *error)
209 gchar buf[64];
211 XGetErrorText(display, error->error_code, buf, 63);
213 g_warning ("The program '%s' received an X Window System error.\n"
214 "This probably reflects a bug in the program.\n"
215 "The error was '%s'.\n"
216 " (Details: serial %ld error_code %d request_code %d minor_code %d)\n"
217 " (Note to programmers: normally, X errors are reported asynchronously;\n"
218 " that is, you will receive the error a while after causing it.\n"
219 " To debug your program, run it with the --sync command line\n"
220 " option to change this behavior. You can then get a meaningful\n"
221 " backtrace from your debugger.)",
222 g_get_prgname (),
223 buf,
224 error->serial,
225 error->error_code,
226 error->request_code,
227 error->minor_code);
229 /* Try to cope with BadWindow errors */
230 if (error->error_code == BadWindow || error->error_code == BadDrawable)
232 g_warning(_("We got a BadWindow error from the X server. "
233 "This might be due to this GTK bug (during drag-and-drop?):\n"
234 "http://bugzilla.gnome.org/show_bug.cgi?id=152151\n"
235 "Trying to continue..."));
236 return 0;
239 abort();
242 /* Parses the command-line to work out what the user wants to do.
243 * Tries to send the request to an already-running copy of the filer.
244 * If that fails, it initialises all the other modules and executes the
245 * request itself.
247 int main(int argc, char **argv)
249 int wakeup_pipe[2];
250 int i;
251 struct sigaction act;
252 guchar *tmp, *dir;
253 gchar *client_id = NULL;
254 gboolean show_user = FALSE;
255 xmlDocPtr rpc, soap_rpc = NULL, reply;
256 xmlNodePtr body;
257 int fd, ofd0=-1;
259 /* Relocate stdin. We do need it (-R), but it can cause problems if
260 * a child process wants a password, etc...
261 * Do this BEFORE opening anything (e.g., the X connection), in
262 * case fd 0 isn't open at this point.
264 fd = open("/dev/null", O_RDONLY);
265 if (fd > 0)
267 ofd0=dup(0);
268 close(0);
269 dup2(fd, 0);
270 close(fd);
273 home_dir = g_get_home_dir();
274 home_dir_len = strlen(home_dir);
275 app_dir = g_strdup(getenv("APP_DIR"));
277 /* Get internationalisation up and running. This requires the
278 * choices system, to discover the user's preferred language.
280 choices_init();
281 options_init();
282 i18n_init();
283 xattr_init();
285 if (!app_dir)
287 g_warning("APP_DIR environment variable was unset!\n"
288 "Use the AppRun script to invoke ROX-Filer...\n");
289 app_dir = g_get_current_dir();
291 #ifdef HAVE_UNSETENV
292 else
294 /* Don't pass it on to our child processes... */
295 unsetenv("APP_DIR");
297 #endif
299 /* Sometimes we want to take special action when a child
300 * process exits. This hash table is used to convert the
301 * child's PID to the callback function.
303 death_callbacks = g_hash_table_new(NULL, NULL);
305 /* Find out some information about ourself */
306 euid = geteuid();
307 egid = getegid();
308 ngroups = getgroups(0, NULL);
309 if (ngroups < 0)
310 ngroups = 0;
311 else if (ngroups > 0)
313 supplemental_groups = g_malloc(sizeof(gid_t) * ngroups);
314 getgroups(ngroups, supplemental_groups);
317 if (argc == 2 && strcmp(argv[1], "-v") == 0)
319 /* This is used by install.sh to test if the filer
320 * compiled OK. Do this test before gtk_init so that
321 * we don't need an X server to install.
323 g_print("ROX-Filer %s\n", VERSION);
324 g_print(_(COPYING));
325 show_features();
326 return EXIT_SUCCESS;
329 option_add_int(&o_override_redirect, "override_redirect", FALSE);
331 option_add_int(&o_session_panel_or_pin, "session_panel_or_pin",
332 SESSION_BOTH);
333 option_add_string(&o_session_panel_name, "session_panel_name",
334 "Default");
335 option_add_string(&o_session_pinboard_name, "session_pinboard_name",
336 "Default");
337 option_register_widget("launch", build_launch);
339 /* The idea here is to convert the command-line arguments
340 * into a SOAP RPC.
341 * We attempt to invoke the call on an already-running copy of
342 * the filer if possible, or execute it ourselves if not.
344 rpc = soap_new(&body);
346 /* Note: must do this before checking our options,
347 * otherwise we report an error for Gtk's options.
349 gtk_init(&argc, &argv);
350 /* Set a default style for the collection widget */
351 gtk_rc_parse_string("style \"rox-default-collection-style\" {\n"
352 " bg[NORMAL] = \"#f3f3f3\"\n"
353 " fg[NORMAL] = \"#000000\"\n"
354 " bg[INSENSITIVE] = \"#bfbfbf\"\n"
355 " fg[INSENSITIVE] = \"#000000\"\n"
356 "}\n"
357 "style \"rox-default-pinboard-style\" {\n"
358 " bg[NORMAL] = \"#666666\"\n"
359 "}\n"
360 "widget \"rox-pinboard\" style : gtk "
361 "\"rox-default-pinboard-style\"\n"
363 "class \"Collection\" style : gtk "
364 "\"rox-default-collection-style\"\n");
366 g_signal_connect(gdk_screen_get_default(), "size-changed",
367 G_CALLBACK(xrandr_size_change), NULL);
369 /* Process each option in turn */
370 while (1)
372 int c;
373 #ifdef HAVE_GETOPT_LONG
374 int long_index;
375 c = getopt_long(argc, argv, SHORT_OPS,
376 long_opts, &long_index);
377 #else
378 c = getopt(argc, argv, SHORT_OPS);
379 #endif
381 if (c == EOF)
382 break; /* No more options */
384 switch (c)
386 case 'n':
387 new_copy = TRUE;
388 break;
389 case 'o':
390 info_message(_("The -o argument is no longer "
391 "used. You can turn on override "
392 "redirect from the Options box "
393 "instead."));
394 break;
395 case 'v':
396 g_print("ROX-Filer %s\n", VERSION);
397 g_print("%s", _(COPYING));
398 show_features();
399 return EXIT_SUCCESS;
400 case 'h':
401 g_print(_(HELP), BUGS_TO);
402 g_print("%s", _(SHORT_ONLY_WARNING));
403 return EXIT_SUCCESS;
404 case 'D':
405 case 'd':
406 case 'x':
407 /* Argument is a path */
408 if (c == 'd' && VALUE[0] == '/')
409 tmp = g_strdup(VALUE);
410 else
411 tmp = pathdup(VALUE);
412 soap_add(body,
413 c == 'D' ? "CloseDir" :
414 c == 'd' ? "OpenDir" :
415 c == 'x' ? "Examine" : "Unknown",
416 "Filename", tmp,
417 NULL, NULL);
418 g_free(tmp);
419 break;
420 case 's':
421 tmp = g_path_get_dirname(VALUE);
423 if (tmp[0] == '/')
424 dir = NULL;
425 else
426 dir = pathdup(tmp);
428 soap_add(body, "Show",
429 "Directory", dir ? dir : tmp,
430 "Leafname", g_basename(VALUE));
431 g_free(tmp);
432 g_free(dir);
433 break;
434 case 'l':
435 case 'r':
436 case 't':
437 case 'B':
438 /* Argument is a leaf (or starts with /) */
439 soap_add(body, "Panel", "Name", VALUE,
440 "Side", c == 'l' ? "Left" :
441 c == 'r' ? "Right" :
442 c == 't' ? "Top" :
443 c == 'B' ? "Bottom" :
444 "Unkown");
445 break;
446 case 'b':
447 /* Argument is a leaf (or starts with /) */
448 if (*VALUE)
449 soap_add(body, "Panel", "Name", VALUE,
450 NULL, NULL);
451 else
452 soap_add(body, "Panel",
453 "Side", "Bottom",
454 NULL, NULL);
455 break;
456 case 'p':
457 soap_add(body, "Pinboard",
458 "Name", VALUE, NULL, NULL);
459 break;
460 case 'u':
461 show_user = TRUE;
462 break;
463 case 'm':
465 MIME_type *type;
466 type_init();
467 diritem_init();
468 pixmaps_init();
469 type = type_get_type(VALUE);
470 printf("%s/%s\n", type->media_type,
471 type->subtype);
472 return EXIT_SUCCESS;
474 case 'c':
475 client_id = g_strdup(VALUE);
476 break;
477 case 'R':
478 /* Reconnect stdin */
479 if(ofd0>-1) {
480 close(0);
481 dup2(ofd0, 0);
483 soap_rpc = xmlParseFile("-");
484 if (!soap_rpc)
485 g_error("Invalid XML in RPC");
486 /* Disconnect stdin again */
487 fd = open("/dev/null", O_RDONLY);
488 if (fd > 0)
490 close(0);
491 dup2(fd, 0);
492 close(fd);
495 break;
497 case 'S':
498 new_copy = TRUE;
499 add_default_panel_and_pinboard(body);
500 break;
502 default:
503 printf(_(USAGE));
504 return EXIT_FAILURE;
508 tooltips = gtk_tooltips_new();
510 if (euid == 0 || show_user)
511 show_user_message = g_strdup_printf(_("Running as user '%s'"),
512 user_name(euid));
514 /* Add each remaining (non-option) argument to the list of files
515 * to run.
517 i = optind;
518 while (i < argc)
520 tmp = pathdup(argv[i++]);
522 soap_add(body, "Run", "Filename", tmp, NULL, NULL);
524 g_free(tmp);
527 if (soap_rpc)
529 if (body->xmlChildrenNode)
530 g_error("Can't use -R with other options - sorry!");
531 xmlFreeDoc(rpc);
532 body = NULL;
533 rpc = soap_rpc;
535 else if (!body->xmlChildrenNode)
537 /* The user didn't request any action. Open the current
538 * directory.
540 guchar *dir;
542 dir = g_get_current_dir();
543 soap_add(body, "OpenDir", "Filename", dir, NULL, NULL);
544 g_free(dir);
547 option_add_int(&o_dnd_no_hostnames, "dnd_no_hostnames", 1);
549 /* Try to send the request to an already-running copy of the filer */
550 gui_support_init();
551 if (remote_init(rpc, new_copy))
552 return EXIT_SUCCESS; /* It worked - exit */
554 /* Put ourselves into the background (so 'rox' always works the
555 * same, whether we're already running or not).
556 * Not for -n, though (helps when debugging).
558 if (!new_copy)
560 pid_t child;
562 child = fork();
563 if (child > 0)
564 _exit(0); /* Parent exits */
565 /* Otherwise we're the child (or an error occurred - ignore
566 * it!).
570 /* Initialize the rest of the filer... */
572 pixmaps_init();
574 dnd_init();
575 bind_init();
576 dir_init();
577 diritem_init();
578 menu_init();
579 minibuffer_init();
580 filer_init();
581 toolbar_init();
582 display_init();
583 mount_init();
584 type_init();
585 action_init();
587 pinboard_init();
588 panel_init();
590 /* Let everyone update */
591 options_notify();
593 /* When we get a signal, we can't do much right then. Instead,
594 * we send a char down this pipe, which causes the main loop to
595 * deal with the event next time we're idle.
597 pipe(wakeup_pipe);
598 close_on_exec(wakeup_pipe[0], TRUE);
599 close_on_exec(wakeup_pipe[1], TRUE);
600 gdk_input_add_full(wakeup_pipe[0], GDK_INPUT_READ, wake_up_cb,
601 NULL, NULL);
602 to_wakeup_pipe = wakeup_pipe[1];
604 /* If the pipe is full then we're going to get woken up anyway... */
605 set_blocking(to_wakeup_pipe, FALSE);
607 /* Let child processes die */
608 act.sa_handler = child_died;
609 sigemptyset(&act.sa_mask);
610 act.sa_flags = SA_NOCLDSTOP;
611 sigaction(SIGCHLD, &act, NULL);
613 /* Ignore SIGPIPE - check for EPIPE errors instead */
614 act.sa_handler = SIG_IGN;
615 sigemptyset(&act.sa_mask);
616 act.sa_flags = 0;
617 sigaction(SIGPIPE, &act, NULL);
619 /* Set up session managament if available */
620 session_init(client_id);
621 g_free(client_id);
623 /* See if we need to migrate the Choices directories*/
624 choices_migrate();
626 /* Finally, execute the request */
627 reply = run_soap(rpc);
628 xmlFreeDoc(rpc);
629 if (reply)
631 /* Write the result, if any, to stdout */
632 save_xml_file(reply, "-");
633 xmlFreeDoc(reply);
636 /* Try to find out why we crash with GTK 2.4 */
637 XSetErrorHandler(rox_x_error);
639 /* Enter the main loop, processing events until all our windows
640 * are closed.
642 if (number_of_windows > 0)
643 gtk_main();
645 return EXIT_SUCCESS;
648 /* Register a function to be called when process number 'child' dies. */
649 void on_child_death(gint child, CallbackFn callback, gpointer data)
651 Callback *cb;
653 g_return_if_fail(callback != NULL);
655 cb = g_new(Callback, 1);
657 cb->callback = callback;
658 cb->data = data;
660 g_hash_table_insert(death_callbacks, GINT_TO_POINTER(child), cb);
663 void one_less_window(void)
665 if (--number_of_windows < 1)
666 gtk_main_quit();
669 /****************************************************************
670 * INTERNAL FUNCTIONS *
671 ****************************************************************/
673 static void show_features(void)
675 g_print("\n");
676 g_print(_("Compiled with GTK version %s\n"), GTK_VERSION);
677 g_print(_("Running with GTK version %d.%d.%d\n"),
678 gtk_major_version,
679 gtk_minor_version,
680 gtk_micro_version);
681 g_print("\n-- %s --\n\n", _("features set at compile time"));
682 g_print("%s... %s\n", _("Large File Support"),
683 #ifdef LARGE_FILE_SUPPORT
684 _("Yes")
685 #else
686 _("No")
687 #endif
689 g_print("%s... %s\n", _("Dnotify support"),
690 #ifdef USE_DNOTIFY
691 _("Yes")
692 #else
693 _("No")
694 #endif
696 g_print("%s... %s\n", _("Binary compatibility"),
697 #if defined(HAVE_APSYMBOLS_H) || defined(HAVE_APBUILD_APSYMBOLS_H)
698 _("Yes (can run with older glibc versions)")
699 #else
700 _("No (apsymbols.h not found)")
701 #endif
704 g_print("%s... %s\n", _("Extended attribute support"),
705 xattr_supported(NULL)? _("Yes"): _("No"));
708 static void soap_add(xmlNodePtr body,
709 xmlChar *function,
710 const xmlChar *arg1_name, const xmlChar *arg1_value,
711 const xmlChar *arg2_name, const xmlChar *arg2_value)
713 xmlNodePtr node;
714 xmlNs *rox;
716 rox = xmlSearchNsByHref(body->doc, body, ROX_NS);
718 node = xmlNewChild(body, rox, function, NULL);
720 if (arg1_name)
722 xmlNewTextChild(node, rox, arg1_name, arg1_value);
723 if (arg2_name)
724 xmlNewTextChild(node, rox, arg2_name, arg2_value);
728 /* This is called as a signal handler; simply ensures that
729 * child_died_callback() will get called later.
731 static void child_died(int signum)
733 child_died_flag = TRUE;
734 write(to_wakeup_pipe, "\0", 1); /* Wake up! */
737 static void child_died_callback(void)
739 int status;
740 gint child;
742 child_died_flag = FALSE;
744 /* Find out which children exited and allow them to die */
747 Callback *cb;
749 child = waitpid(-1, &status, WNOHANG);
751 if (child == 0 || child == -1)
752 return;
754 cb = g_hash_table_lookup(death_callbacks,
755 GINT_TO_POINTER(child));
756 if (cb)
758 cb->callback(cb->data);
759 g_hash_table_remove(death_callbacks,
760 GINT_TO_POINTER(child));
763 } while (1);
766 #define BUFLEN 40
767 /* When data is written to_wakeup_pipe, this gets called from the event
768 * loop some time later. Useful for getting out of signal handlers, etc.
770 static void wake_up_cb(gpointer data, gint source, GdkInputCondition condition)
772 char buf[BUFLEN];
774 read(source, buf, BUFLEN);
776 if (child_died_flag)
777 child_died_callback();
778 #ifdef USE_DNOTIFY
779 if (dnotify_wakeup_flag)
780 dnotify_wakeup();
781 #endif
784 static void xrandr_size_change(GdkScreen *screen, gpointer user_data)
786 gui_store_screen_geometry(screen);
788 panel_update_size();
789 pinboard_update_size();
792 static void add_default_panel_and_pinboard(xmlNodePtr body)
794 char *name;
796 if (o_session_panel_or_pin.int_value != SESSION_PANEL_ONLY)
798 name=o_session_pinboard_name.value;
799 if (!name[0])
800 name="Default";
801 soap_add(body, "Pinboard","Name", name, NULL, NULL);
804 if (o_session_panel_or_pin.int_value != SESSION_PINBOARD_ONLY)
806 name = o_session_panel_name.value;
807 if (!name[0])
808 name="Default";
810 soap_add(body, "Panel", "Name", name, NULL, NULL);
814 static GtkWidget *launch_button_new(const char *label, const char *uri)
816 GtkWidget *button;
817 GClosure *closure;
818 const gchar *slash;
819 gchar *tip;
821 button = button_new_mixed(GTK_STOCK_PREFERENCES, label);
822 closure = g_cclosure_new_swap(G_CALLBACK(launch_uri),
823 g_strdup(uri),
824 (GClosureNotify) g_free);
825 g_signal_connect_closure(button, "clicked", closure, FALSE);
827 allow_right_click(button);
829 slash = strrchr(uri, '/');
830 if (!slash)
831 slash = uri - 1;
832 tip = g_strdup_printf(
833 _("Left-click to run %s.\n"
834 "Right-click for a list of versions."),
835 slash + 1);
837 gtk_tooltips_set_tip(tooltips, button, tip, NULL);
839 g_free(tip);
841 return button;
844 static GList *build_launch(Option *option, xmlNode *node, guchar *label)
846 GtkWidget *align;
847 char *uri;
849 g_return_val_if_fail(option == NULL, NULL);
850 g_return_val_if_fail(label != NULL, NULL);
852 uri = xmlGetProp(node, "uri");
854 g_return_val_if_fail(uri != NULL, NULL);
856 align = gtk_alignment_new(0, 0.5, 0, 0);
858 gtk_container_add(GTK_CONTAINER(align),
859 launch_button_new(_(label), uri));
861 g_free(uri);
863 return g_list_append(NULL, align);