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