1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 2011-2020 gEDA Contributors (see ChangeLog for details)
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 #ifdef HAVE_SYS_WAIT_H
33 #if defined (OS_WIN32)
35 /*! \brief Launch application to show URI on Windows.
36 * \par Function Description
37 * On native Windows, the ShellExecute Windows API function provides a
38 * reliable way to open a URI in a default application.
40 * This function is called by x_show_uri().
42 * \param uri URI to launch viewer for.
43 * \param error Location to return error information.
44 * \return TRUE on success, FALSE on failure.
47 show_uri__win32 (const gchar
*uri
, GError
**error
)
50 /* On Windows, we need to use ShellExecute because allegedly GIO
51 * doesn't cope very well with Windows. :-( */
59 (int) ShellExecute (NULL
, /* window handle */
62 NULL
, /* No parameters (not launching application) */
63 NULL
, /* Inherit working directory */
64 SW_SHOWNORMAL
); /* Default application display mode */
70 msg
= g_strdup (_("The operating system is out of memory or resources."));
73 FormatMessage ((FORMAT_MESSAGE_ALLOCATE_BUFFER
|
74 FORMAT_MESSAGE_FROM_SYSTEM
|
75 FORMAT_MESSAGE_IGNORE_INSERTS
),
78 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
82 msg
= g_strdup ((gchar
*) buf
);
85 /* \bug We should specify a domain and error code. */
86 g_set_error (error
, 0, 0, "%s", msg
);
92 /*! \brief Launch default application for a URI.
93 * \par Function Description
94 * Launches the default application associated with \a uri on the host
97 * Depending on the way gEDA was configured, this may occur by one of
98 * the following three methods:
100 * -# Calling gtk_show_uri() to use the GIO library (default on Linux)
101 * -# Calling the ShellExecute() Windows API call (default on Windows)
102 * -# Running an appropriate external tool.
104 * \param w_current Current #GschemToplevel structure.
105 * \param uri URI to launch viewer for.
106 * \param error Location to return error information.
107 * \return TRUE on success, FALSE on failure.
110 x_show_uri (GschemToplevel
*w_current
, const gchar
*uri
,
113 # if defined (SHOW_URI_GIO)
116 g_assert (w_current
);
119 screen
= gtk_window_get_screen (GTK_WINDOW (w_current
->main_window
));
120 return gtk_show_uri (screen
, uri
, GDK_CURRENT_TIME
, error
);
122 # elif defined (OS_WIN32) && !defined (OS_CYGWIN)
123 return show_uri__win32 (uri
, error
);
126 gboolean spawn_status
;
132 argv
[0] = SHOW_URI_COMMAND
;
133 argv
[1] = (gchar
*) uri
;
134 argv
[2] = NULL
; /* Null-terminated */
136 spawn_status
= g_spawn_sync (NULL
, /* Inherit working directory */
138 NULL
, /* Inherit environment */
139 G_SPAWN_SEARCH_PATH
, /* Flags */
140 NULL
, /* No child setup function */
141 NULL
, /* No child setup function data */
142 NULL
, /* Don't need stdout */
143 NULL
, /* Don't need stderr */
147 if (!spawn_status
) return FALSE
;
149 if (exit_status
!= 0) {
150 g_set_error (error
, G_SPAWN_ERROR
, G_SPAWN_ERROR_FAILED
,
151 _("%s failed to launch URI"), argv
[0]);