2 * Viking - GPS data editor
3 * Copyright (C) 2007, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
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
21 * Ideally dependencies should just be on Glib, Gtk,
22 * see vikutils for things that further depend on other Viking types
28 #include <glib/gstdio.h>
29 #include <glib/gi18n.h>
30 #include <glib/gprintf.h>
41 static gboolean spawn_command_line_async(const gchar * cmd,
44 gchar *cmdline = NULL;
47 cmdline = g_strdup_printf("%s '%s'", cmd, arg);
48 g_debug("Running: %s", cmdline);
50 status = g_spawn_command_line_async(cmdline, NULL);
59 void open_url(GtkWindow *parent, const gchar * url)
62 gtk_show_uri ( gtk_widget_get_screen (GTK_WIDGET(parent)), url, GDK_CURRENT_TIME, &error );
64 a_dialog_error_msg_extra ( parent, _("Could not launch web browser. %s"), error->message );
65 g_error_free ( error );
69 void new_email(GtkWindow *parent, const gchar * address)
71 gchar *uri = g_strdup_printf("mailto:%s", address);
73 gtk_show_uri ( gtk_widget_get_screen (GTK_WIDGET(parent)), uri, GDK_CURRENT_TIME, &error );
75 a_dialog_error_msg_extra ( parent, _("Could not create new email. %s"), error->message );
76 g_error_free ( error );
80 ShellExecute(NULL, NULL, (char *) uri, NULL, ".\\", 0);
82 if (!spawn_command_line_async("xdg-email", uri))
83 a_dialog_error_msg ( parent, _("Could not create new email.") );
89 gchar *uri_escape(gchar *str)
91 gchar *esc_str = g_malloc(3*strlen(str));
95 for (src = str; *src; src++) {
98 else if (g_ascii_isalnum(*src))
101 g_sprintf(dst, "%%%02hhX", *src);
111 GList * str_array_to_glist(gchar* data[])
115 for (p = (gpointer)data; *p; p++)
116 gl = g_list_prepend(gl, *p);
117 return g_list_reverse(gl);
121 * split_string_from_file_on_equals:
123 * @buf: the input string
124 * @key: newly allocated string that is before the '='
125 * @val: newly allocated string after the '='
127 * Designed for file line processing, so it ignores strings beginning with special
128 * characters, such as '#'; returns false in such situations.
129 * Also returns false if no equals character is found
131 * e.g. if buf = "GPS.parameter=42"
132 * key = "GPS.parameter"
135 gboolean split_string_from_file_on_equals ( const gchar *buf, gchar **key, gchar **val )
137 // comments, special characters in viking file format
138 if ( buf == NULL || buf[0] == '\0' || buf[0] == '~' || buf[0] == '=' || buf[0] == '#' )
141 if ( ! strchr ( buf, '=' ) )
144 gchar **strv = g_strsplit ( buf, "=", 2 );
147 gchar *str = strv[gi];
150 *key = g_strdup ( str );
152 *val = g_strdup ( str );
159 // Remove newline from val and also any other whitespace
160 *key = g_strstrip ( *key );
161 *val = g_strstrip ( *val );