mirror of https://github.com/djcb/mu.git
parent
172ff25bb6
commit
0fe8f9a613
|
@ -26,6 +26,7 @@ lib_mu_utils=static_library('mu-utils', [
|
||||||
'mu-utils.cc'],
|
'mu-utils.cc'],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
glib_dep,
|
glib_dep,
|
||||||
|
gio_dep,
|
||||||
config_h_dep,
|
config_h_dep,
|
||||||
readline_dep
|
readline_dep
|
||||||
],
|
],
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
|
|
||||||
#include <glib-object.h>
|
#include <glib-object.h>
|
||||||
#include <glib/gstdio.h>
|
#include <glib/gstdio.h>
|
||||||
|
#include <gio/gio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <langinfo.h>
|
#include <langinfo.h>
|
||||||
|
@ -206,22 +207,6 @@ mu_util_create_dir_maybe (const gchar *path, mode_t mode, gboolean nowarn)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
|
||||||
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
|
gboolean
|
||||||
mu_util_supports (MuFeature feature)
|
mu_util_supports (MuFeature feature)
|
||||||
{
|
{
|
||||||
|
@ -267,18 +252,24 @@ maybe_setsid (G_GNUC_UNUSED gpointer user_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
mu_util_play (const char *path, gboolean allow_local, gboolean allow_remote,
|
mu_util_play (const char *path, GError **err)
|
||||||
GError **err)
|
|
||||||
{
|
{
|
||||||
gboolean rv;
|
GFile *gf;
|
||||||
|
gboolean rv, is_native;
|
||||||
const gchar *argv[3];
|
const gchar *argv[3];
|
||||||
const char *prog;
|
const char *prog;
|
||||||
|
|
||||||
g_return_val_if_fail (path, FALSE);
|
g_return_val_if_fail (path, FALSE);
|
||||||
g_return_val_if_fail (mu_util_is_local_file (path) || allow_remote,
|
|
||||||
FALSE);
|
gf = g_file_new_for_path(path);
|
||||||
g_return_val_if_fail (!mu_util_is_local_file (path) || allow_local,
|
is_native = g_file_is_native(gf);
|
||||||
FALSE);
|
g_object_unref(gf);
|
||||||
|
|
||||||
|
if (!is_native) {
|
||||||
|
mu_util_g_set_error (err, MU_ERROR_FILE_CANNOT_EXECUTE,
|
||||||
|
"'%s' is not a native file", path);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
prog = g_getenv ("MU_PLAY_PROGRAM");
|
prog = g_getenv ("MU_PLAY_PROGRAM");
|
||||||
if (!prog) {
|
if (!prog) {
|
||||||
|
|
|
@ -85,17 +85,6 @@ gboolean mu_util_check_dir (const gchar* path, gboolean readable,
|
||||||
gboolean writeable)
|
gboolean writeable)
|
||||||
G_GNUC_WARN_UNUSED_RESULT;
|
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);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* is the current locale utf-8 compatible?
|
* is the current locale utf-8 compatible?
|
||||||
*
|
*
|
||||||
|
@ -103,8 +92,6 @@ gboolean mu_util_is_local_file (const char* path);
|
||||||
*/
|
*/
|
||||||
gboolean mu_util_locale_is_utf8 (void) G_GNUC_CONST;
|
gboolean mu_util_locale_is_utf8 (void) G_GNUC_CONST;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get a 'summary' of the string, ie. the first /n/ lines of the
|
* get a 'summary' of the string, ie. the first /n/ lines of the
|
||||||
* strings, with all newlines removed, replaced by single spaces
|
* strings, with all newlines removed, replaced by single spaces
|
||||||
|
@ -141,20 +128,19 @@ gboolean mu_util_print_encoded (const char *frm, ...) G_GNUC_PRINTF(1,2);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try to 'play' (ie., open with it's associated program) a file. On
|
* Try to 'play' (ie., open with it's associated program) a file. On MacOS, the
|
||||||
* MacOS, the the program 'open' is used for this; on other platforms
|
* the program 'open' is used for this; on other platforms 'xdg-open' to do the
|
||||||
* 'xdg-open' to do the actual opening. In addition you can set it to another program
|
* actual opening. In addition you can set it to another program by setting the
|
||||||
* by setting the MU_PLAY_PROGRAM environment variable
|
* MU_PLAY_PROGRAM environment variable
|
||||||
|
*
|
||||||
|
* This requires a 'native' file, see g_file_is_native()
|
||||||
*
|
*
|
||||||
* @param path full path of the file to open
|
* @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)
|
|
||||||
* @param err receives error information, if any
|
* @param err receives error information, if any
|
||||||
*
|
*
|
||||||
* @return TRUE if it succeeded, FALSE otherwise
|
* @return TRUE if it succeeded, FALSE otherwise
|
||||||
*/
|
*/
|
||||||
gboolean mu_util_play (const char *path, gboolean allow_local,
|
gboolean mu_util_play (const char *path, GError **err);
|
||||||
gboolean allow_remote, GError **err);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether program prog exists in PATH
|
* Check whether program prog exists in PATH
|
||||||
|
|
|
@ -43,7 +43,7 @@ save_part(const Message::Part& part, size_t idx, const MuConfig* opts)
|
||||||
|
|
||||||
if (opts->play) {
|
if (opts->play) {
|
||||||
GError *err{};
|
GError *err{};
|
||||||
if (auto res{mu_util_play(path.c_str(), TRUE, FALSE, &err)};
|
if (auto res{mu_util_play(path.c_str(), &err)};
|
||||||
res != MU_OK)
|
res != MU_OK)
|
||||||
return Err(Error::Code::Play, &err, "playing '%s' failed",
|
return Err(Error::Code::Play, &err, "playing '%s' failed",
|
||||||
path.c_str());
|
path.c_str());
|
||||||
|
|
Loading…
Reference in New Issue