]> git.street.me.uk Git - andy/viking.git/blame - src/util.c
Create the geonames search as an VikXmlSearchTool
[andy/viking.git] / src / util.c
CommitLineData
7d02a0b0
GB
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>
6 *
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.
10 *
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.
15 *
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
19 */
4c77d5e0
GB
20#ifdef HAVE_CONFIG_H
21#include "config.h"
22#endif
23
e0173c37
MA
24#ifdef WINDOWS
25#include <windows.h>
26#endif
27
4c77d5e0 28#include <glib/gi18n.h>
c612e922 29#include <glib/gprintf.h>
7d02a0b0
GB
30
31#include "dialog.h"
32
3530c91e
GB
33static gboolean spawn_command_line_async(const gchar * cmd,
34 const gchar * arg)
35{
36 gchar *cmdline = NULL;
37 gboolean status;
38
39 cmdline = g_strdup_printf("%s '%s'", cmd, arg);
40 g_debug("Running: %s", cmdline);
41
42 status = g_spawn_command_line_async(cmdline, NULL);
43
44 g_free(cmdline);
45
a0f4c917 46 return status;
3530c91e
GB
47}
48
7d02a0b0
GB
49void open_url(GtkWindow *parent, const gchar * url)
50{
51#ifdef WINDOWS
e0173c37 52 ShellExecute(NULL, NULL, (char *) url, NULL, ".\\", 0);
7d02a0b0
GB
53#else /* WINDOWS */
54 const gchar *browsers[] = {
55 "xdg-open", "gnome-open", "kfmclient openURL",
56 "sensible-browser", "firefox", "epiphany",
57 "iceweasel", "seamonkey", "galeon", "mozilla",
58 "opera", "konqueror", "netscape", "links -g",
59 NULL
60 };
61 gint i=0;
7d02a0b0 62
0654760a 63 const gchar *browser = g_getenv("BROWSER");
7d02a0b0
GB
64 if (browser == NULL || browser[0] == '\0') {
65 /* $BROWSER not set -> use first entry */
66 browser = browsers[i++];
67 }
68 do {
3530c91e 69 if (spawn_command_line_async(browser, url)) {
7d02a0b0
GB
70 return;
71 }
72
7d02a0b0
GB
73 browser = browsers[i++];
74 } while(browser);
75
4c77d5e0 76 a_dialog_error_msg ( parent, _("Could not launch web browser.") );
7d02a0b0
GB
77#endif /* WINDOWS */
78}
3530c91e
GB
79
80void new_email(GtkWindow *parent, const gchar * address)
81{
82 gchar *uri = g_strdup_printf("mailto:%s", address);
83#ifdef WINDOWS
84 ShellExecute(NULL, NULL, (char *) uri, NULL, ".\\", 0);
85#else /* WINDOWS */
86 if (!spawn_command_line_async("xdg-email", uri))
87 a_dialog_error_msg ( parent, _("Could not create new email.") );
88#endif /* WINDOWS */
89 g_free(uri);
90 uri = NULL;
91}
ba4a5e11
GB
92
93gchar *uri_escape(gchar *str)
94{
95 gchar *esc_str = g_malloc(3*strlen(str));
96 gchar *dst = esc_str;
97 gchar *src;
98
99 for (src = str; *src; src++) {
100 if (*src == ' ')
101 *dst++ = '+';
102 else if (g_ascii_isalnum(*src))
103 *dst++ = *src;
104 else {
105 g_sprintf(dst, "%%%02X", *src);
106 dst += 3;
107 }
108 }
109 *dst = '\0';
110
111 return(esc_str);
112}
113