Synchronise vikwindow.c and menu.xml around mode handling
[viking.git] / src / util.c
blob079ccc9c9e61fb4509b3aeeef5b9af6cfd9b9d1c
1 /*
2 * Viking - GPS data editor
3 * Copyright (C) 2007 Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
4 * Based on:
5 * Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@linuxmag.com.br>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, version 2.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
24 #ifdef WINDOWS
25 #include <windows.h>
26 #endif
28 #include <glib/gi18n.h>
30 #include "dialog.h"
32 static gboolean spawn_command_line_async(const gchar * cmd,
33 const gchar * arg)
35 gchar *cmdline = NULL;
36 gboolean status;
38 cmdline = g_strdup_printf("%s '%s'", cmd, arg);
39 g_debug("Running: %s", cmdline);
41 status = g_spawn_command_line_async(cmdline, NULL);
43 g_free(cmdline);
47 void open_url(GtkWindow *parent, const gchar * url)
49 #ifdef WINDOWS
50 ShellExecute(NULL, NULL, (char *) url, NULL, ".\\", 0);
51 #else /* WINDOWS */
52 const gchar *browsers[] = {
53 "xdg-open", "gnome-open", "kfmclient openURL",
54 "sensible-browser", "firefox", "epiphany",
55 "iceweasel", "seamonkey", "galeon", "mozilla",
56 "opera", "konqueror", "netscape", "links -g",
57 NULL
59 gint i=0;
61 const gchar *browser = g_getenv("BROWSER");
62 if (browser == NULL || browser[0] == '\0') {
63 /* $BROWSER not set -> use first entry */
64 browser = browsers[i++];
66 do {
67 if (spawn_command_line_async(browser, url)) {
68 return;
71 browser = browsers[i++];
72 } while(browser);
74 a_dialog_error_msg ( parent, _("Could not launch web browser.") );
75 #endif /* WINDOWS */
78 void new_email(GtkWindow *parent, const gchar * address)
80 gchar *uri = g_strdup_printf("mailto:%s", address);
81 #ifdef WINDOWS
82 ShellExecute(NULL, NULL, (char *) uri, NULL, ".\\", 0);
83 #else /* WINDOWS */
84 if (!spawn_command_line_async("xdg-email", uri))
85 a_dialog_error_msg ( parent, _("Could not create new email.") );
86 #endif /* WINDOWS */
87 g_free(uri);
88 uri = NULL;