* don't insist on using xdg-open; use "open" on MacOS or what MU_PLAY_PROGRAM sets

This commit is contained in:
djcb
2012-01-23 00:11:23 +02:00
parent 22aeb33c4c
commit 688d571715
5 changed files with 29 additions and 38 deletions

View File

@ -324,38 +324,42 @@ mu_util_is_local_file (const char* path)
}
gboolean
mu_util_play (const char *path, gboolean allow_local, gboolean allow_remote)
{
#ifndef XDGOPEN
g_warning ("opening files not supported (xdg-open missing)");
return FALSE;
#else
gboolean rv;
GError *err;
const gchar *argv[3];
const gchar *prog;
char *cmdline;
g_return_val_if_fail (path, FALSE);
g_return_val_if_fail (mu_util_is_local_file (path) || allow_remote,
FALSE);
g_return_val_if_fail (!mu_util_is_local_file (path) || allow_local,
FALSE);
argv[0] = XDGOPEN;
argv[1] = path;
argv[2] = NULL;
prog = g_getenv ("MU_PLAY_PROGRAM");
if (!prog) {
#ifdef __APPLE__
prog = "open";
#else
prog = "xdg-open";
#endif /*!__APPLE__*/
}
cmdline = g_strconcat (prog, " ", path, NULL);
err = NULL;
rv = g_spawn_async (NULL, (gchar**)&argv, NULL, 0,
NULL, NULL, NULL, &err);
rv = g_spawn_command_line_async (cmdline, &err);
if (!rv) {
g_warning ("failed to spawn xdg-open: %s",
err->message ? err->message : "error");
g_warning ("failed to spawn %s: %s",
cmdline, err->message ? err->message : "error");
g_error_free (err);
}
g_free (cmdline);
return rv;
#endif /*XDGOPEN*/
}

View File

@ -179,8 +179,10 @@ gboolean mu_util_printerr_encoded (const char *frm, ...) G_GNUC_PRINTF(1,2);
/**
* try to 'play' (ie., open with it's associated program) a
* file. depends on xdg-open to do the actual opening
* Try to 'play' (ie., open with it's associated program) a file. On
* MacOS, the the program 'open' is used for this; on other platforms
* 'xdg-open' to do the actual opening. In addition you can set it to another program
* by setting the MU_PLAY_PROGRAM environment variable
*
* @param path full path of the file to open
* @param allow_local allow local files (ie. with file:// prefix or fs paths)