diff --git a/src/mu-util.c b/src/mu-util.c index 9fae4ad2..a61c6553 100644 --- a/src/mu-util.c +++ b/src/mu-util.c @@ -303,7 +303,23 @@ mu_util_create_writeable_fd (const char* path, mode_t mode, gboolean -mu_util_play (const char *path) +mu_util_is_local_file (const char* path) +{ + /* if it starts with file:// it's a local file (for the + * purposes of this function -- if it's on a remote FS it's + * still considered local) */ + if (g_ascii_strncasecmp ("file://", path, strlen("file://")) == 0) + return TRUE; + + if (access (path, R_OK) == 0) + return TRUE; + + return FALSE; +} + + +gboolean +mu_util_play (const char *path, gboolean allow_local, gboolean allow_remote) { #ifndef XDGOPEN g_warning ("opening files not supported (xdg-open missing)"); @@ -314,8 +330,10 @@ mu_util_play (const char *path) const gchar *argv[3]; g_return_val_if_fail (path, FALSE); - g_return_val_if_fail (access (path, R_OK) == 0, 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; diff --git a/src/mu-util.h b/src/mu-util.h index 1978bb80..195d978f 100644 --- a/src/mu-util.h +++ b/src/mu-util.h @@ -120,15 +120,29 @@ int mu_util_create_writeable_fd (const char* path, mode_t mode, G_GNUC_WARN_UNUSED_RESULT; -/** + +/** + * check if file is local, ie. on the local file system. this means + * that it's either having a file URI, *or* that it's an existing file + * + * @param path a path + * + * @return TRUE if the file is local, FALSE otherwise + */ +gboolean mu_util_is_local_file (const char* path); + +/** * try to 'play' (ie., open with it's associated program) a * file. depends on xdg-open to do the actual opening * * @param path full path of the file to open + * @param allow_local allow local files (ie. with file:// prefix or fs paths) + * @param allow_remote allow URIs (ie., http, mailto) * * @return TRUE if it succeeded, FALSE otherwise */ -gboolean mu_util_play (const char *path); +gboolean mu_util_play (const char *path, + gboolean allow_local, gboolean allow_remote); /**