]> git.street.me.uk Git - andy/viking.git/blame - src/ui_util.c
[QA] Shift Gtk dependent utility functions into separate file.
[andy/viking.git] / src / ui_util.c
CommitLineData
bc34c059
RN
1/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2/*
3 * Viking - GPS data editor
4 * Copyright (C) 2007, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
5 * Copyright (C) 2014, Rob Norris <rw_norris@hotmail.com>
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 */
20 /*
21 * Ideally dependencies should just be on Gtk,
22 * see vikutils for things that further depend on other Viking types
23 * see utils for things only depend on Glib
24 */
25#ifdef HAVE_CONFIG_H
26#include "config.h"
27#endif
28
29#include <glib/gstdio.h>
30#include <glib/gi18n.h>
31#include <glib/gprintf.h>
32
33#include "util.h"
34#include "dialog.h"
35
36#ifdef WINDOWS
37#include <windows.h>
38#endif
39
40/*
41#ifndef WINDOWS
42static gboolean spawn_command_line_async(const gchar * cmd,
43 const gchar * arg)
44{
45 gchar *cmdline = NULL;
46 gboolean status;
47
48 cmdline = g_strdup_printf("%s '%s'", cmd, arg);
49 g_debug("Running: %s", cmdline);
50
51 status = g_spawn_command_line_async(cmdline, NULL);
52
53 g_free(cmdline);
54
55 return status;
56}
57#endif
58*/
59
60// Annoyingly gtk_show_uri() doesn't work so resort to ShellExecute method
61// (non working at least in our Windows build with GTK+2.24.10 on Windows 7)
62
63void open_url(GtkWindow *parent, const gchar * url)
64{
65#ifdef WINDOWS
66 ShellExecute(NULL, NULL, (char *) url, NULL, ".\\", 0);
67#else
68 GError *error = NULL;
69 gtk_show_uri ( gtk_widget_get_screen (GTK_WIDGET(parent)), url, GDK_CURRENT_TIME, &error );
70 if ( error ) {
71 a_dialog_error_msg_extra ( parent, _("Could not launch web browser. %s"), error->message );
72 g_error_free ( error );
73 }
74#endif
75}
76
77void new_email(GtkWindow *parent, const gchar * address)
78{
79 gchar *uri = g_strdup_printf("mailto:%s", address);
80 GError *error = NULL;
81 gtk_show_uri ( gtk_widget_get_screen (GTK_WIDGET(parent)), uri, GDK_CURRENT_TIME, &error );
82 if ( error ) {
83 a_dialog_error_msg_extra ( parent, _("Could not create new email. %s"), error->message );
84 g_error_free ( error );
85 }
86 /*
87#ifdef WINDOWS
88 ShellExecute(NULL, NULL, (char *) uri, NULL, ".\\", 0);
89#else
90 if (!spawn_command_line_async("xdg-email", uri))
91 a_dialog_error_msg ( parent, _("Could not create new email.") );
92#endif
93 */
94 g_free(uri);
95 uri = NULL;
96}