]>
Commit | Line | Data |
---|---|---|
7d02a0b0 GB |
1 | /* |
2 | * Viking - GPS data editor | |
a482007a | 3 | * Copyright (C) 2007, Guilhem Bonnefille <guilhem.bonnefille@gmail.com> |
7d02a0b0 | 4 | * Based on: |
a482007a | 5 | * Copyright (C) 2003-2007, Leandro A. F. Pereira <leandro@linuxmag.com.br> |
7d02a0b0 GB |
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 | ||
02d0c367 | 34 | #ifndef WINDOWS |
3530c91e GB |
35 | static gboolean spawn_command_line_async(const gchar * cmd, |
36 | const gchar * arg) | |
37 | { | |
38 | gchar *cmdline = NULL; | |
39 | gboolean status; | |
40 | ||
41 | cmdline = g_strdup_printf("%s '%s'", cmd, arg); | |
42 | g_debug("Running: %s", cmdline); | |
43 | ||
44 | status = g_spawn_command_line_async(cmdline, NULL); | |
45 | ||
46 | g_free(cmdline); | |
47 | ||
a0f4c917 | 48 | return status; |
3530c91e | 49 | } |
02d0c367 | 50 | #endif |
3530c91e | 51 | |
7d02a0b0 GB |
52 | void open_url(GtkWindow *parent, const gchar * url) |
53 | { | |
54 | #ifdef WINDOWS | |
e0173c37 | 55 | ShellExecute(NULL, NULL, (char *) url, NULL, ".\\", 0); |
7d02a0b0 GB |
56 | #else /* WINDOWS */ |
57 | const gchar *browsers[] = { | |
58 | "xdg-open", "gnome-open", "kfmclient openURL", | |
59 | "sensible-browser", "firefox", "epiphany", | |
60 | "iceweasel", "seamonkey", "galeon", "mozilla", | |
61 | "opera", "konqueror", "netscape", "links -g", | |
53acc93f | 62 | "chromium-browser", "chromium", "chrome", |
d4a06390 | 63 | "safari", "camino", "omniweb", "icab", |
7d02a0b0 GB |
64 | NULL |
65 | }; | |
66 | gint i=0; | |
7d02a0b0 | 67 | |
0654760a | 68 | const gchar *browser = g_getenv("BROWSER"); |
7d02a0b0 GB |
69 | if (browser == NULL || browser[0] == '\0') { |
70 | /* $BROWSER not set -> use first entry */ | |
71 | browser = browsers[i++]; | |
72 | } | |
73 | do { | |
3530c91e | 74 | if (spawn_command_line_async(browser, url)) { |
7d02a0b0 GB |
75 | return; |
76 | } | |
77 | ||
7d02a0b0 GB |
78 | browser = browsers[i++]; |
79 | } while(browser); | |
80 | ||
4c77d5e0 | 81 | a_dialog_error_msg ( parent, _("Could not launch web browser.") ); |
7d02a0b0 GB |
82 | #endif /* WINDOWS */ |
83 | } | |
3530c91e GB |
84 | |
85 | void new_email(GtkWindow *parent, const gchar * address) | |
86 | { | |
87 | gchar *uri = g_strdup_printf("mailto:%s", address); | |
88 | #ifdef WINDOWS | |
89 | ShellExecute(NULL, NULL, (char *) uri, NULL, ".\\", 0); | |
90 | #else /* WINDOWS */ | |
91 | if (!spawn_command_line_async("xdg-email", uri)) | |
92 | a_dialog_error_msg ( parent, _("Could not create new email.") ); | |
93 | #endif /* WINDOWS */ | |
94 | g_free(uri); | |
95 | uri = NULL; | |
96 | } | |
ba4a5e11 GB |
97 | |
98 | gchar *uri_escape(gchar *str) | |
99 | { | |
100 | gchar *esc_str = g_malloc(3*strlen(str)); | |
101 | gchar *dst = esc_str; | |
102 | gchar *src; | |
103 | ||
104 | for (src = str; *src; src++) { | |
105 | if (*src == ' ') | |
106 | *dst++ = '+'; | |
107 | else if (g_ascii_isalnum(*src)) | |
108 | *dst++ = *src; | |
109 | else { | |
7705a76f | 110 | g_sprintf(dst, "%%%02hhX", *src); |
ba4a5e11 GB |
111 | dst += 3; |
112 | } | |
113 | } | |
114 | *dst = '\0'; | |
115 | ||
116 | return(esc_str); | |
117 | } | |
118 | ||
70434be3 GB |
119 | |
120 | GList * str_array_to_glist(gchar* data[]) | |
121 | { | |
122 | GList *gl = NULL; | |
123 | gpointer * p; | |
124 | for (p = (gpointer)data; *p; p++) | |
125 | gl = g_list_prepend(gl, *p); | |
126 | return g_list_reverse(gl); | |
127 | } |