From 64eb11fbafc028db9e32b76b47a31e74b257d2fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Sun, 7 Jun 2020 22:17:55 +0200 Subject: [PATCH 01/22] Add aesgcm to urls grabber MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Mazière --- src/ui/window_list.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/window_list.c b/src/ui/window_list.c index 01b5177f..3972fadb 100644 --- a/src/ui/window_list.c +++ b/src/ui/window_list.c @@ -1156,7 +1156,7 @@ wins_add_urls_ac(const ProfWin *const win, const ProfMessage *const message) GRegex *regex; GMatchInfo *match_info; - regex = g_regex_new("https?://\\S+", 0, 0, NULL); + regex = g_regex_new("(https?|aesgcm)://\\S+", 0, 0, NULL); g_regex_match (regex, message->plain, 0, &match_info); while (g_match_info_matches (match_info)) From 96c877de80f5f208a41ba775c2dd13746a09d7fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Sun, 7 Jun 2020 22:18:43 +0200 Subject: [PATCH 02/22] Refactor cmd_urlopen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Mazière --- src/command/cmd_funcs.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 1c13d12f..03d60dbf 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -8939,27 +8939,27 @@ cmd_slashguard(ProfWin *window, const char *const command, gchar **args) gboolean cmd_urlopen(ProfWin *window, const char *const command, gchar **args) { - if (window->type == WIN_CHAT || - window->type == WIN_MUC || - window->type == WIN_PRIVATE) { - - if (args[0] == NULL) { - cons_bad_cmd_usage(command); - return TRUE; - } - - gchar* cmd = prefs_get_string(PREF_URL_OPEN_CMD); - gchar *argv[] = {cmd, args[0], NULL}; - - if (!call_external(argv, NULL, NULL)) { - cons_show_error("Unable to open url: check the logs for more information."); - } - - g_free(cmd); - } else { + if (window->type != WIN_CHAT && + window->type != WIN_MUC && + window->type != WIN_PRIVATE) { cons_show("urlopen not supported in this window"); + return TRUE; } + if (args[0] == NULL) { + cons_bad_cmd_usage(command); + return TRUE; + } + + gchar* cmd = prefs_get_string(PREF_URL_OPEN_CMD); + gchar *argv[] = {cmd, args[0], NULL}; + + if (!call_external(argv, NULL, NULL)) { + cons_show_error("Unable to open url: check the logs for more information."); + } + + g_free(cmd); + return TRUE; } From 7e652f4ca0f5dd26c841137ac15e23e74f9cc920 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Fri, 12 Jun 2020 09:07:59 +0200 Subject: [PATCH 03/22] Add string and string list preferences with option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Where GKeyFile usually use the pref[locale] format to define locale specific translated data, it is here hijacked to be used as pref[option] in order to specialize a preference according to an option: open.url.cmd[pdf] = pdf-viewer open.url.cmd[jpg] = image-viewer Signed-off-by: Pierre Mazière --- src/config/preferences.c | 86 +++++++++++++++++++++++++++++++++++++++- src/config/preferences.h | 4 ++ 2 files changed, 89 insertions(+), 1 deletion(-) diff --git a/src/config/preferences.c b/src/config/preferences.c index 093d7679..a3a90692 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -79,6 +79,7 @@ static const char* _get_group(preference_t pref); static const char* _get_key(preference_t pref); static gboolean _get_default_boolean(preference_t pref); static char* _get_default_string(preference_t pref); +static char** _get_default_string_list(preference_t pref); static void _prefs_load(void) { @@ -217,7 +218,7 @@ prefs_load(char *config_file) } prefs = g_key_file_new(); - g_key_file_load_from_file(prefs, prefs_loc, G_KEY_FILE_KEEP_COMMENTS, NULL); + g_key_file_load_from_file(prefs, prefs_loc, G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, NULL); _prefs_load(); } @@ -493,6 +494,49 @@ prefs_get_string(preference_t pref) } } +char* +prefs_get_string_with_option(preference_t pref, gchar *option) +{ + const char *group = _get_group(pref); + const char *key = _get_key(pref); + char *def = _get_default_string(pref); + + char *result = g_key_file_get_locale_string(prefs, group, key, option, NULL); + + if (result == NULL) { + if (def) { + return g_strdup(def); + } else { + return NULL; + } + } else { + return result; + } +} + +char** +prefs_get_string_list_with_option(preference_t pref, gchar *option) +{ + const char *group = _get_group(pref); + const char *key = _get_key(pref); + char **def = _get_default_string_list(pref); + + gchar **result = g_key_file_get_locale_string_list(prefs, group, key, option, NULL, NULL); + + if (result == NULL) { + if (def) { + return def; + } else { + g_strfreev(def); + return NULL; + } + } else { + g_strfreev(def); + return result; + } +} + + void prefs_free_string(char *pref) { @@ -513,6 +557,34 @@ prefs_set_string(preference_t pref, char *value) } } +void +prefs_set_string_with_option(preference_t pref, char *option, char *value) +{ + const char *group = _get_group(pref); + const char *key = _get_key(pref); + if (value == NULL) { + g_key_file_remove_key(prefs, group, key, NULL); + } else { + g_key_file_set_locale_string(prefs, group, key, option, value); + } +} + +void +prefs_set_string_list_with_option(preference_t pref, char *option, const gchar* const *values) +{ + const char *group = _get_group(pref); + const char *key = _get_key(pref); + if (values == NULL || *values == NULL){ + g_key_file_set_locale_string_list(prefs, group, key, option, NULL, 0); + } else { + guint num_values = 0; + while(values[num_values]) { + num_values++; + } + g_key_file_set_locale_string_list(prefs, group, key, option, values, num_values); + } +} + char* prefs_get_tls_certpath(void) { @@ -2218,3 +2290,15 @@ _get_default_string(preference_t pref) return NULL; } } + +// the default setting for a string list type preference +// if it is not specified in .profrc +static char** +_get_default_string_list(preference_t pref) +{ + switch (pref) + { + default: + return NULL; + } +} diff --git a/src/config/preferences.h b/src/config/preferences.h index 5a38bfec..4c9b7bd8 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -314,8 +314,12 @@ void prefs_save_win_placement(ProfWinPlacement *placement); gboolean prefs_get_boolean(preference_t pref); void prefs_set_boolean(preference_t pref, gboolean value); char* prefs_get_string(preference_t pref); +char* prefs_get_string_with_option(preference_t pref, gchar *option); +char **prefs_get_string_list_with_option(preference_t pref, gchar *option); void prefs_free_string(char *pref); void prefs_set_string(preference_t pref, char *value); +void prefs_set_string_with_option(preference_t pref, char *option, char *value); +void prefs_set_string_list_with_option(preference_t pref, char *option, const gchar* const *values); char* prefs_get_tls_certpath(void); From c56d530b67d09267eb46cba029217e4b84b32cef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Fri, 12 Jun 2020 09:19:14 +0200 Subject: [PATCH 04/22] Replace /urlopen with /url and adapt /executable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit /urlopen is replaced by /url with the following sub commands: /url open /url save [] Signed-off-by: Pierre Mazière --- src/command/cmd_defs.c | 49 +++++---- src/command/cmd_funcs.c | 212 +++++++++++++++++++++++++++++++++++++-- src/command/cmd_funcs.h | 3 +- src/config/preferences.c | 19 +++- src/config/preferences.h | 1 + 5 files changed, 250 insertions(+), 34 deletions(-) diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 85140430..f5527c26 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2464,40 +2464,49 @@ static struct cmd_t command_defs[] = "/software xmpp.vanaheimr.edda") }, - { "/urlopen", - parse_args, 1, -1, NULL, - CMD_NOSUBFUNCS - CMD_MAINFUNC(cmd_urlopen) - CMD_TAGS( - CMD_TAG_CHAT, - CMD_TAG_GROUPCHAT) - CMD_SYN( - "/urlopen ") - CMD_DESC( - "Open the URL") - CMD_ARGS( - { "", "URL to open."}) - CMD_NOEXAMPLES - }, - { "/executable", - parse_args, 2, 2, &cons_executable_setting, + parse_args, 2, 4, &cons_executable_setting, CMD_NOSUBFUNCS CMD_MAINFUNC(cmd_executable) CMD_TAGS( CMD_TAG_DISCOVERY) CMD_SYN( "/executable avatar ", - "/executable urlopen ") + "/executable urlopen ", + "/executable urlsave ") CMD_DESC( "Configure executable that should be called upon a certain command." "Default is xdg-open.") CMD_ARGS( { "avatar", "Set executable that is run in /avatar open. Use your favourite image viewer." }, - { "urlopen", "Set executable that is run in /urlopen. Use your favourite browser." }) + { "urlopen", "Set executable that is run in /url open for a given file type. It may be your favorite browser or a specific viewer." }, + { "urlsave", "Set executable that is run in /url save for a given protocol. Use your favourite downloader."}) CMD_EXAMPLES( "/executable avatar xdg-open", - "/executable urlopen firefox") + "/executable urlopen html firefox %u", + "/executable urlsave aesgcm omut -d %u %p") + }, + + { "/url", + parse_args, 2, 3, NULL, + CMD_SUBFUNCS( + { "open", cmd_url_open}, + { "save", cmd_url_save }) + CMD_NOMAINFUNC + CMD_TAGS( + CMD_TAG_CHAT, + CMD_TAG_GROUPCHAT) + CMD_SYN( + "/url open ", + "/url save []") + CMD_DESC( + "Deal with URLs") + CMD_ARGS( + { "open", "Open URL with predefined executable." }, + { "save", "Save URL to optional path, default path is current directory"}) + CMD_EXAMPLES( + "/url open https://profanity-im.github.io", + "/url save https://profanity-im.github.io/guide/latest/userguide.html /home/user/Download/") }, }; diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 03d60dbf..4d084aac 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -44,6 +44,8 @@ #include #include #include +#include +#include #include #include #include @@ -8937,28 +8939,210 @@ cmd_slashguard(ProfWin *window, const char *const command, gchar **args) } gboolean -cmd_urlopen(ProfWin *window, const char *const command, gchar **args) +cmd_url_open(ProfWin *window, const char *const command, gchar **args) { if (window->type != WIN_CHAT && window->type != WIN_MUC && window->type != WIN_PRIVATE) { - cons_show("urlopen not supported in this window"); + cons_show("url open not supported in this window"); return TRUE; } - if (args[0] == NULL) { + if (args[1] == NULL) { cons_bad_cmd_usage(command); return TRUE; } - gchar* cmd = prefs_get_string(PREF_URL_OPEN_CMD); - gchar *argv[] = {cmd, args[0], NULL}; + gboolean require_save = false; - if (!call_external(argv, NULL, NULL)) { - cons_show_error("Unable to open url: check the logs for more information."); + char *suffix_cmd = NULL; + char *suffix = NULL; + gchar *fileStart = g_strrstr(args[1], "/"); + if (fileStart == NULL) { + cons_show("URL '%s' is not valid.", args[1]); + return TRUE; } - g_free(cmd); + fileStart++; + if (((char*)(fileStart - 2))[0] == '/' && + ((char*)(fileStart - 3))[0] == ':' + ){ + // If the '/' is last character of the '://' string, there will be no suffix + // Therefore, it is considered that there is no file name in the URL and + // fileStart is set to the end of the URL. + fileStart = args[1] + strlen(args[1]); + } + gchar *suffixStart = g_strrstr(fileStart, "."); + if (suffixStart != NULL) { + suffixStart++; + gchar *suffixEnd = g_strrstr(suffixStart, "#"); + if(suffixEnd == NULL) { + suffix = g_strdup(suffixStart); + } else { + suffix = g_strndup(suffixStart, suffixEnd - suffixStart); + } + } + + char **suffix_cmd_pref = prefs_get_string_list_with_option(PREF_URL_OPEN_CMD, NULL); + if (suffix != NULL) { + gchar *lowercase_suffix = g_ascii_strdown(suffix, -1); + g_strfreev(suffix_cmd_pref); + suffix_cmd_pref = prefs_get_string_list_with_option(PREF_URL_OPEN_CMD, lowercase_suffix); + g_free(lowercase_suffix); + lowercase_suffix = NULL; + g_free(suffix); + suffix = NULL; + } + + if (0 == g_strcmp0(suffix_cmd_pref[0], "true")) { + require_save = true; + } + suffix_cmd = g_strdup(suffix_cmd_pref[1]); + g_strfreev(suffix_cmd_pref); + suffix_cmd_pref = NULL; + + gchar *scheme = g_uri_parse_scheme(args[1]); + if( 0 == g_strcmp0(scheme, "aesgcm")) { + require_save = true; + } + + if (require_save) { + gchar *save_args[] = { "open", args[1], "/tmp/profanity.tmp", NULL}; + cmd_url_save(window, command, save_args); + } + + gchar **argv = g_strsplit(suffix_cmd, " ", 0); + guint num_args = 0; + while (argv[num_args]) { + if (0 == g_strcmp0(argv[num_args], "%u")) { + g_free(argv[num_args]); + if (require_save) { + argv[num_args] = g_strdup("/tmp/profanity.tmp"); + } else { + argv[num_args] = g_strdup(args[1]); + } + break; + } + num_args++; + } + + if (!call_external(argv, NULL, NULL)) { + cons_show_error("Unable to open url: check the logs for more information."); + } + + if (require_save) { + g_unlink("/tmp/profanity.tmp"); + } + + g_strfreev(argv); + g_free(suffix_cmd); + + return TRUE; +} + +gboolean +cmd_url_save(ProfWin *window, const char *const command, gchar **args) +{ + if (window->type != WIN_CHAT && + window->type != WIN_MUC && + window->type != WIN_PRIVATE) { + cons_show("url save not supported in this window"); + return TRUE; + } + + if (args[1] == NULL) { + cons_bad_cmd_usage(command); + return TRUE; + } + + gchar *uri = args[1]; + gchar *target_path = g_strdup(args[2]); + + GFile *file = g_file_new_for_uri(uri); + + gchar *target_dir = NULL; + gchar *base_name = NULL; + + if (target_path == NULL) { + target_dir = g_strdup("./"); + base_name = g_file_get_basename(file); + if (0 == g_strcmp0(base_name, ".")) { + g_free(base_name); + base_name = g_strdup("saved_url_content.html"); + } + target_path = g_strconcat(target_dir, base_name, NULL); + } + + if (g_file_test(target_path, G_FILE_TEST_EXISTS) && + g_file_test(target_path, G_FILE_TEST_IS_DIR) + ) { + target_dir = g_strdup(target_path); + base_name = g_file_get_basename(file); + g_free(target_path); + target_path = g_strconcat(target_dir, "/", base_name, NULL); + } + + g_object_unref(file); + file = NULL; + + if (base_name == NULL) { + base_name = g_path_get_basename(target_path); + target_dir = g_path_get_dirname(target_path); + } + + if (!g_file_test(target_dir, G_FILE_TEST_EXISTS) || + !g_file_test(target_dir, G_FILE_TEST_IS_DIR)) { + cons_show("%s does not exist or is not a directory.", target_dir); + g_free(target_path); + g_free(target_dir); + g_free(base_name); + return TRUE; + } + + gchar *scheme = g_uri_parse_scheme(uri); + if (scheme == NULL) { + cons_show("URL '%s' is not valid.", uri); + g_free(target_path); + g_free(target_dir); + g_free(base_name); + return TRUE; + } + + gchar *scheme_cmd = NULL; + + if (0 == g_strcmp0(scheme, "http") + || 0 == g_strcmp0(scheme, "https") + || 0 == g_strcmp0(scheme, "aesgcm") + ) { + scheme_cmd = prefs_get_string_with_option(PREF_URL_SAVE_CMD, scheme); + } + + g_free(scheme); + scheme = NULL; + + gchar **argv = g_strsplit(scheme_cmd, " ", 0); + g_free(scheme_cmd); + scheme_cmd = NULL; + + guint num_args = 0; + while (argv[num_args]) { + if (0 == g_strcmp0(argv[num_args], "%u")) { + g_free(argv[num_args]); + argv[num_args] = g_strdup(uri); + } else if (0 == g_strcmp0(argv[num_args], "%p")) { + g_free(argv[num_args]); + argv[num_args] = target_path; + } + num_args++; + } + + if (!call_external(argv, NULL, NULL)) { + cons_show_error("Unable to save url: check the logs for more information."); + } + + g_free(target_dir); + g_free(base_name); + g_strfreev(argv); return TRUE; } @@ -8970,8 +9154,16 @@ cmd_executable(ProfWin *window, const char *const command, gchar **args) prefs_set_string(PREF_AVATAR_CMD, args[1]); cons_show("Avatar command set to: %s", args[1]); } else if (g_strcmp0(args[0], "urlopen") == 0) { - prefs_set_string(PREF_URL_OPEN_CMD, args[1]); - cons_show("urlopen command set to: %s", args[1]); + char *str = g_strjoinv(" ", &args[3]); + const gchar* const list[] = {args[2], str, NULL}; + prefs_set_string_list_with_option(PREF_URL_OPEN_CMD, args[1], list); + cons_show("`url open` command set to: %s for %s files", str, args[1]); + g_free(str); + } else if (g_strcmp0(args[0], "urlsave") == 0) { + char *str = g_strjoinv(" ", &args[2]); + prefs_set_string_with_option(PREF_URL_SAVE_CMD, args[1], str); + cons_show("`url save` command set to: %s for scheme %s", str, args[1]); + g_free(str); } else { cons_bad_cmd_usage(command); } diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h index d0d37efa..4cb47113 100644 --- a/src/command/cmd_funcs.h +++ b/src/command/cmd_funcs.h @@ -233,7 +233,8 @@ gboolean cmd_correction(ProfWin *window, const char *const command, gchar **args gboolean cmd_correct(ProfWin *window, const char *const command, gchar **args); gboolean cmd_slashguard(ProfWin *window, const char *const command, gchar **args); gboolean cmd_serversoftware(ProfWin *window, const char *const command, gchar **args); -gboolean cmd_urlopen(ProfWin *window, const char *const command, gchar **args); +gboolean cmd_url_open(ProfWin *window, const char *const command, gchar **args); +gboolean cmd_url_save(ProfWin *window, const char *const command, gchar **args); gboolean cmd_executable(ProfWin *window, const char *const command, gchar **args); #endif diff --git a/src/config/preferences.c b/src/config/preferences.c index a3a90692..7187460a 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -64,6 +64,7 @@ #define PREF_GROUP_OMEMO "omemo" #define PREF_GROUP_MUC "muc" #define PREF_GROUP_PLUGINS "plugins" +#define PREF_GROUP_EXECUTABLES "executables" #define INPBLOCK_DEFAULT 1000 @@ -1855,9 +1856,11 @@ _get_group(preference_t pref) case PREF_GRLOG: case PREF_LOG_ROTATE: case PREF_LOG_SHARED: + return PREF_GROUP_LOGGING; case PREF_AVATAR_CMD: case PREF_URL_OPEN_CMD: - return PREF_GROUP_LOGGING; + case PREF_URL_SAVE_CMD: + return PREF_GROUP_EXECUTABLES; case PREF_AUTOAWAY_CHECK: case PREF_AUTOAWAY_MODE: case PREF_AUTOAWAY_MESSAGE: @@ -2147,7 +2150,9 @@ _get_key(preference_t pref) case PREF_MAM: return "mam"; case PREF_URL_OPEN_CMD: - return "urlopen.cmd"; + return "url.open.cmd"; + case PREF_URL_SAVE_CMD: + return "url.save.cmd"; default: return NULL; } @@ -2284,8 +2289,9 @@ _get_default_string(preference_t pref) case PREF_COLOR_NICK: return "false"; case PREF_AVATAR_CMD: - case PREF_URL_OPEN_CMD: return "xdg-open"; + case PREF_URL_SAVE_CMD: + return "curl -o %p %u"; default: return NULL; } @@ -2296,8 +2302,15 @@ _get_default_string(preference_t pref) static char** _get_default_string_list(preference_t pref) { + char **str_array = NULL; + switch (pref) { + case PREF_URL_OPEN_CMD: + str_array = g_malloc0(3); + str_array[0] = g_strdup("false"); + str_array[1] = g_strdup("xdg-open %u"); + return str_array; default: return NULL; } diff --git a/src/config/preferences.h b/src/config/preferences.h index 4c9b7bd8..1823097a 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -172,6 +172,7 @@ typedef enum { PREF_SLASH_GUARD, PREF_MAM, PREF_URL_OPEN_CMD, + PREF_URL_SAVE_CMD, } preference_t; typedef struct prof_alias_t { From bcea9c863bc226caf969ce1aaa8479e98b577f70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Fri, 12 Jun 2020 09:19:33 +0200 Subject: [PATCH 05/22] Add /url autocompletion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Mazière --- src/command/cmd_ac.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 09de573c..e64da7ce 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -123,7 +123,7 @@ static char* _avatar_autocomplete(ProfWin *window, const char *const input, gboo static char* _correction_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _correct_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _software_autocomplete(ProfWin *window, const char *const input, gboolean previous); -static char* _urlopen_autocomplete(ProfWin *window, const char *const input, gboolean previous); +static char* _url_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _executable_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _script_autocomplete_func(const char *const prefix, gboolean previous, void *context); @@ -259,6 +259,7 @@ static Autocomplete logging_group_ac; static Autocomplete color_ac; static Autocomplete correction_ac; static Autocomplete avatar_ac; +static Autocomplete url_ac; static Autocomplete executable_ac; void @@ -1007,9 +1008,14 @@ cmd_ac_init(void) autocomplete_add(avatar_ac, "get"); autocomplete_add(avatar_ac, "open"); + url_ac = autocomplete_new(); + autocomplete_add(url_ac, "open"); + autocomplete_add(url_ac, "save"); + executable_ac = autocomplete_new(); autocomplete_add(executable_ac, "avatar"); autocomplete_add(executable_ac, "urlopen"); + autocomplete_add(executable_ac, "urlsave"); } void @@ -1328,6 +1334,7 @@ cmd_ac_reset(ProfWin *window) autocomplete_reset(color_ac); autocomplete_reset(correction_ac); autocomplete_reset(avatar_ac); + autocomplete_reset(url_ac); autocomplete_reset(executable_ac); autocomplete_reset(script_ac); @@ -1489,6 +1496,7 @@ cmd_ac_uninit(void) autocomplete_free(color_ac); autocomplete_free(correction_ac); autocomplete_free(avatar_ac); + autocomplete_free(url_ac); autocomplete_free(executable_ac); } @@ -1749,7 +1757,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ g_hash_table_insert(ac_funcs, "/correction", _correction_autocomplete); g_hash_table_insert(ac_funcs, "/correct", _correct_autocomplete); g_hash_table_insert(ac_funcs, "/software", _software_autocomplete); - g_hash_table_insert(ac_funcs, "/urlopen", _urlopen_autocomplete); + g_hash_table_insert(ac_funcs, "/url", _url_autocomplete); g_hash_table_insert(ac_funcs, "/executable", _executable_autocomplete); int len = strlen(input); @@ -4036,14 +4044,24 @@ _software_autocomplete(ProfWin *window, const char *const input, gboolean previo } static char* -_urlopen_autocomplete(ProfWin *window, const char *const input, gboolean previous) +_url_autocomplete(ProfWin *window, const char *const input, gboolean previous) { char *result = NULL; + result = autocomplete_param_with_ac(input, "/url", url_ac, TRUE, previous); + if (result) { + return result; + } + if (window->type == WIN_CHAT || window->type == WIN_MUC || window->type == WIN_PRIVATE) { - result = autocomplete_param_with_func(input, "/urlopen", wins_get_url, previous, window); + result = autocomplete_param_with_func(input, "/url open", wins_get_url, previous, window); + if (result) { + return result; + } + + result = autocomplete_param_with_func(input, "/url save", wins_get_url, previous, window); } return result; From f9961677aaa8d2713a80127f95a3770b33af4cef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Fri, 12 Jun 2020 09:35:55 +0200 Subject: [PATCH 06/22] Display default value for /url associated commands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The display of commands associated with specific file types and protocols will need to be implemented later, but this requires to use private data of the GKeyFile structure, which can be a maintainability issue on the long term. Signed-off-by: Pierre Mazière --- src/ui/console.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 8b6693e4..be137d7b 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -2067,12 +2067,16 @@ void cons_executable_setting(void) { char *avatar = prefs_get_string(PREF_AVATAR_CMD); - cons_show("Avatar command (/executable avatar) : %s", avatar); - prefs_free_string(avatar); + cons_show("'/avatar' command (/executable avatar) : %s", avatar); + g_free(avatar); - char *exec = prefs_get_string(PREF_URL_OPEN_CMD); - cons_show("urlopen command (/executable urlopen) : %s", exec); - prefs_free_string(exec); + char **urlopen = prefs_get_string_list_with_option(PREF_URL_OPEN_CMD, ""); + cons_show("Default '/url open' command (/executable urlopen) : %s", urlopen[1]); + g_strfreev(urlopen); + + char *urlsave = prefs_get_string(PREF_URL_SAVE_CMD); + cons_show("Default '/url save' command (/executable urlsave) : %s", urlsave); + g_free(urlsave); } void From 233494d01edb5aadbe6fdda24f353e807c6680b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Mon, 15 Jun 2020 11:31:44 +0200 Subject: [PATCH 07/22] Display a message acknowledging file saving success MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Mazière --- src/command/cmd_funcs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 4d084aac..b7a6dec3 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -9138,6 +9138,8 @@ cmd_url_save(ProfWin *window, const char *const command, gchar **args) if (!call_external(argv, NULL, NULL)) { cons_show_error("Unable to save url: check the logs for more information."); + } else { + cons_show("URL '%s' has been saved into '%s'.", uri, target_path); } g_free(target_dir); From b580b9ef119045f142fa4baa9689a1c5ce8864ef Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 1 Jul 2020 14:42:35 +0200 Subject: [PATCH 08/22] prefs_free_string() doesnt need to check if pref is NULL g_free(NULL); is noop. --- src/config/preferences.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/config/preferences.c b/src/config/preferences.c index 7187460a..9d3b8e30 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -537,13 +537,10 @@ prefs_get_string_list_with_option(preference_t pref, gchar *option) } } - void prefs_free_string(char *pref) { - if (pref) { - g_free(pref); - } + g_free(pref); } void From 2b5160a35130b2575f1a322f44bc366b6e9dac0f Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 1 Jul 2020 14:50:07 +0200 Subject: [PATCH 09/22] console.c: Use prefs_free_string() f9961677aaa8d2713a80127f95a3770b33af4cef replaces prefs_free_string() with g_free(). Both is correct but lets still use this. --- src/ui/console.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/console.c b/src/ui/console.c index be137d7b..587f7e48 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -2068,7 +2068,7 @@ cons_executable_setting(void) { char *avatar = prefs_get_string(PREF_AVATAR_CMD); cons_show("'/avatar' command (/executable avatar) : %s", avatar); - g_free(avatar); + prefs_free_string(avatar); char **urlopen = prefs_get_string_list_with_option(PREF_URL_OPEN_CMD, ""); cons_show("Default '/url open' command (/executable urlopen) : %s", urlopen[1]); From ec7e635e752bdfef851fd177596c1d73d97afb42 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 1 Jul 2020 15:29:57 +0200 Subject: [PATCH 10/22] Move url/avatar commands from logging to exectuables section c56d530b67d09267eb46cba029217e4b84b32cef by peetah moves: urlopen.cmd from the 'logging' to a new 'executables' section in profrc avatar.cmd from the 'logging' to a new 'executables' section in profrc We need to adapt this so that users don't have to set the setting again themselves. --- src/config/preferences.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/config/preferences.c b/src/config/preferences.c index 9d3b8e30..721ead46 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -161,6 +161,20 @@ static void _prefs_load(void) } } + // 0.9.0 introduced /urlopen. It was saved under "logging" section. Now we have a new "executables" section. + if (g_key_file_has_key(prefs, PREF_GROUP_LOGGING, "urlopen.cmd", NULL)) { + char *value = g_key_file_get_string(prefs, PREF_GROUP_LOGGING, "urlopen.cmd", NULL); + g_key_file_set_string(prefs, PREF_GROUP_EXECUTABLES, "url.open.cmd", value); + g_key_file_remove_key(prefs, PREF_GROUP_LOGGING, "urlopen.cmd", NULL); + } + + // 0.9.0 introduced configurable /avatar. It was saved under "logging" section. Now we have a new "executables" section. + if (g_key_file_has_key(prefs, PREF_GROUP_LOGGING, "avatar.cmd", NULL)) { + char *value = g_key_file_get_string(prefs, PREF_GROUP_LOGGING, "avatar.cmd", NULL); + g_key_file_set_string(prefs, PREF_GROUP_EXECUTABLES, "avatar.cmd", value); + g_key_file_remove_key(prefs, PREF_GROUP_LOGGING, "avatar.cmd", NULL); + } + _save_prefs(); boolean_choice_ac = autocomplete_new(); From 8be1e44cea64ca8bebfea38fb37641ea6bae60b7 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 1 Jul 2020 15:40:16 +0200 Subject: [PATCH 11/22] Adjust `/executable` test to be more precise --- src/ui/console.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/console.c b/src/ui/console.c index 587f7e48..759d6af3 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -2067,7 +2067,7 @@ void cons_executable_setting(void) { char *avatar = prefs_get_string(PREF_AVATAR_CMD); - cons_show("'/avatar' command (/executable avatar) : %s", avatar); + cons_show("Default '/avatar open' command (/executable avatar) : %s", avatar); prefs_free_string(avatar); char **urlopen = prefs_get_string_list_with_option(PREF_URL_OPEN_CMD, ""); From 780ee74177d00eabb152ee85d2b4a24cba48df9b Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 1 Jul 2020 16:10:27 +0200 Subject: [PATCH 12/22] cmd_executable(): Check arg lengths --- src/command/cmd_funcs.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index b7a6dec3..ed20d09d 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -9156,12 +9156,22 @@ cmd_executable(ProfWin *window, const char *const command, gchar **args) prefs_set_string(PREF_AVATAR_CMD, args[1]); cons_show("Avatar command set to: %s", args[1]); } else if (g_strcmp0(args[0], "urlopen") == 0) { + if (g_strv_length(args) < 4) { + cons_bad_cmd_usage(command); + return TRUE; + } + char *str = g_strjoinv(" ", &args[3]); const gchar* const list[] = {args[2], str, NULL}; prefs_set_string_list_with_option(PREF_URL_OPEN_CMD, args[1], list); cons_show("`url open` command set to: %s for %s files", str, args[1]); g_free(str); } else if (g_strcmp0(args[0], "urlsave") == 0) { + if (g_strv_length(args) < 3) { + cons_bad_cmd_usage(command); + return TRUE; + } + char *str = g_strjoinv(" ", &args[2]); prefs_set_string_with_option(PREF_URL_SAVE_CMD, args[1], str); cons_show("`url save` command set to: %s for scheme %s", str, args[1]); From 2fc5a2ee548c397ac635a6e007515150d4ed6aef Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 1 Jul 2020 17:00:11 +0200 Subject: [PATCH 13/22] cmd_url_*(): remove NULLing when not needed --- src/command/cmd_funcs.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index ed20d09d..de7eb55c 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -8955,8 +8955,6 @@ cmd_url_open(ProfWin *window, const char *const command, gchar **args) gboolean require_save = false; - char *suffix_cmd = NULL; - char *suffix = NULL; gchar *fileStart = g_strrstr(args[1], "/"); if (fileStart == NULL) { cons_show("URL '%s' is not valid.", args[1]); @@ -8972,6 +8970,8 @@ cmd_url_open(ProfWin *window, const char *const command, gchar **args) // fileStart is set to the end of the URL. fileStart = args[1] + strlen(args[1]); } + + gchar *suffix = NULL; gchar *suffixStart = g_strrstr(fileStart, "."); if (suffixStart != NULL) { suffixStart++; @@ -8989,17 +8989,15 @@ cmd_url_open(ProfWin *window, const char *const command, gchar **args) g_strfreev(suffix_cmd_pref); suffix_cmd_pref = prefs_get_string_list_with_option(PREF_URL_OPEN_CMD, lowercase_suffix); g_free(lowercase_suffix); - lowercase_suffix = NULL; g_free(suffix); - suffix = NULL; } if (0 == g_strcmp0(suffix_cmd_pref[0], "true")) { require_save = true; } - suffix_cmd = g_strdup(suffix_cmd_pref[1]); + + gchar *suffix_cmd = g_strdup(suffix_cmd_pref[1]); g_strfreev(suffix_cmd_pref); - suffix_cmd_pref = NULL; gchar *scheme = g_uri_parse_scheme(args[1]); if( 0 == g_strcmp0(scheme, "aesgcm")) { @@ -9118,11 +9116,9 @@ cmd_url_save(ProfWin *window, const char *const command, gchar **args) } g_free(scheme); - scheme = NULL; gchar **argv = g_strsplit(scheme_cmd, " ", 0); g_free(scheme_cmd); - scheme_cmd = NULL; guint num_args = 0; while (argv[num_args]) { From e96678e6a50ecf52babde398b4d6d0ced3c15f7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Wed, 1 Jul 2020 23:26:09 +0200 Subject: [PATCH 14/22] fix examples for /executable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Mazière --- src/command/cmd_defs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index f5527c26..7b4068ff 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2483,8 +2483,8 @@ static struct cmd_t command_defs[] = { "urlsave", "Set executable that is run in /url save for a given protocol. Use your favourite downloader."}) CMD_EXAMPLES( "/executable avatar xdg-open", - "/executable urlopen html firefox %u", - "/executable urlsave aesgcm omut -d %u %p") + "/executable urlopen html false \"firefox %u\"", + "/executable urlsave aesgcm \"omut -d %u %p\"") }, { "/url", From 274e69532061d1680b8c738d00a2fefe28734673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Wed, 1 Jul 2020 23:53:07 +0200 Subject: [PATCH 15/22] use '*' to set a default executable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Mazière --- src/command/cmd_defs.c | 8 ++++---- src/config/preferences.c | 37 +++++++++++++++++++++++++------------ 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 7b4068ff..e6fdf202 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2472,15 +2472,15 @@ static struct cmd_t command_defs[] = CMD_TAG_DISCOVERY) CMD_SYN( "/executable avatar ", - "/executable urlopen ", - "/executable urlsave ") + "/executable urlopen (|*) ", + "/executable urlsave (|*) ") CMD_DESC( "Configure executable that should be called upon a certain command." "Default is xdg-open.") CMD_ARGS( { "avatar", "Set executable that is run in /avatar open. Use your favourite image viewer." }, - { "urlopen", "Set executable that is run in /url open for a given file type. It may be your favorite browser or a specific viewer." }, - { "urlsave", "Set executable that is run in /url save for a given protocol. Use your favourite downloader."}) + { "urlopen", "Set executable that is run in /url open for a given file type. It may be your favorite browser or a specific viewer. Use * to set default command for undefined file type." }, + { "urlsave", "Set executable that is run in /url save for a given protocol. Use your favourite downloader. Use * to set default command for undefined protocol."}) CMD_EXAMPLES( "/executable avatar xdg-open", "/executable urlopen html false \"firefox %u\"", diff --git a/src/config/preferences.c b/src/config/preferences.c index 721ead46..088e91f8 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -537,18 +537,23 @@ prefs_get_string_list_with_option(preference_t pref, gchar *option) char **def = _get_default_string_list(pref); gchar **result = g_key_file_get_locale_string_list(prefs, group, key, option, NULL, NULL); - - if (result == NULL) { - if (def) { - return def; - } else { - g_strfreev(def); - return NULL; - } - } else { + if (result) { g_strfreev(def); return result; } + + result = g_key_file_get_string_list(prefs, group, key, NULL, NULL); + if (result) { + g_strfreev(def); + return result; + } + + if (def) { + return def; + } else { + g_strfreev(def); + return NULL; + } } void @@ -587,13 +592,21 @@ prefs_set_string_list_with_option(preference_t pref, char *option, const gchar* const char *group = _get_group(pref); const char *key = _get_key(pref); if (values == NULL || *values == NULL){ - g_key_file_set_locale_string_list(prefs, group, key, option, NULL, 0); + if (g_strcmp0(option, "*") == 0) { + g_key_file_set_string_list(prefs, group, key, NULL, 0); + } else { + g_key_file_set_locale_string_list(prefs, group, key, option, NULL, 0); + } } else { guint num_values = 0; while(values[num_values]) { - num_values++; + num_values++; + } + if (g_strcmp0(option, "*") == 0) { + g_key_file_set_string_list(prefs, group, key, values, num_values); + } else { + g_key_file_set_locale_string_list(prefs, group, key, option, values, num_values); } - g_key_file_set_locale_string_list(prefs, group, key, option, values, num_values); } } From b45384902dd52850f7691a7480ee3c60fcea4b45 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Thu, 2 Jul 2020 10:10:53 +0200 Subject: [PATCH 16/22] cmd_url_open(): fix memleak --- src/command/cmd_funcs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index de7eb55c..5f6d8e60 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -9003,6 +9003,7 @@ cmd_url_open(ProfWin *window, const char *const command, gchar **args) if( 0 == g_strcmp0(scheme, "aesgcm")) { require_save = true; } + g_free(scheme); if (require_save) { gchar *save_args[] = { "open", args[1], "/tmp/profanity.tmp", NULL}; From 1e2a288d80fe0200f1d44d5106f7cc5bfd77718b Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Thu, 2 Jul 2020 10:22:18 +0200 Subject: [PATCH 17/22] Use correct format when transforming old urlopen.cmd Additionally to ec7e635e752bdfef851fd177596c1d73d97afb42. In the earlier commit I just setted the test value ignoring the real format. Now we correctly transform: ``` [logging] urlopen.cmd=xdg-open ``` into: ``` [executables] url.open.cmd=false;xdg-open %u; ``` --- src/config/preferences.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/config/preferences.c b/src/config/preferences.c index 088e91f8..fa81b353 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -163,9 +163,16 @@ static void _prefs_load(void) // 0.9.0 introduced /urlopen. It was saved under "logging" section. Now we have a new "executables" section. if (g_key_file_has_key(prefs, PREF_GROUP_LOGGING, "urlopen.cmd", NULL)) { - char *value = g_key_file_get_string(prefs, PREF_GROUP_LOGGING, "urlopen.cmd", NULL); - g_key_file_set_string(prefs, PREF_GROUP_EXECUTABLES, "url.open.cmd", value); + char *val = g_key_file_get_string(prefs, PREF_GROUP_LOGGING, "urlopen.cmd", NULL); + + GString *value = g_string_new("false;"); + value = g_string_append(value, val); + value = g_string_append(value, " %u;"); + + g_key_file_set_string(prefs, PREF_GROUP_EXECUTABLES, "url.open.cmd", value->str); g_key_file_remove_key(prefs, PREF_GROUP_LOGGING, "urlopen.cmd", NULL); + + g_string_free(value, TRUE); } // 0.9.0 introduced configurable /avatar. It was saved under "logging" section. Now we have a new "executables" section. From 59f5b81b85e0af183489bc95414a57ba82005c0e Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Thu, 2 Jul 2020 10:32:00 +0200 Subject: [PATCH 18/22] cmd_url_*(): use gchar instead of char --- src/command/cmd_funcs.c | 6 +++--- src/config/preferences.c | 2 +- src/config/preferences.h | 2 +- src/ui/console.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 5f6d8e60..2395c622 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -8983,7 +8983,7 @@ cmd_url_open(ProfWin *window, const char *const command, gchar **args) } } - char **suffix_cmd_pref = prefs_get_string_list_with_option(PREF_URL_OPEN_CMD, NULL); + gchar **suffix_cmd_pref = prefs_get_string_list_with_option(PREF_URL_OPEN_CMD, NULL); if (suffix != NULL) { gchar *lowercase_suffix = g_ascii_strdown(suffix, -1); g_strfreev(suffix_cmd_pref); @@ -9158,7 +9158,7 @@ cmd_executable(ProfWin *window, const char *const command, gchar **args) return TRUE; } - char *str = g_strjoinv(" ", &args[3]); + gchar *str = g_strjoinv(" ", &args[3]); const gchar* const list[] = {args[2], str, NULL}; prefs_set_string_list_with_option(PREF_URL_OPEN_CMD, args[1], list); cons_show("`url open` command set to: %s for %s files", str, args[1]); @@ -9169,7 +9169,7 @@ cmd_executable(ProfWin *window, const char *const command, gchar **args) return TRUE; } - char *str = g_strjoinv(" ", &args[2]); + gchar *str = g_strjoinv(" ", &args[2]); prefs_set_string_with_option(PREF_URL_SAVE_CMD, args[1], str); cons_show("`url save` command set to: %s for scheme %s", str, args[1]); g_free(str); diff --git a/src/config/preferences.c b/src/config/preferences.c index fa81b353..bab53000 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -536,7 +536,7 @@ prefs_get_string_with_option(preference_t pref, gchar *option) } } -char** +gchar** prefs_get_string_list_with_option(preference_t pref, gchar *option) { const char *group = _get_group(pref); diff --git a/src/config/preferences.h b/src/config/preferences.h index 1823097a..0bd10d44 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -316,7 +316,7 @@ gboolean prefs_get_boolean(preference_t pref); void prefs_set_boolean(preference_t pref, gboolean value); char* prefs_get_string(preference_t pref); char* prefs_get_string_with_option(preference_t pref, gchar *option); -char **prefs_get_string_list_with_option(preference_t pref, gchar *option); +gchar **prefs_get_string_list_with_option(preference_t pref, gchar *option); void prefs_free_string(char *pref); void prefs_set_string(preference_t pref, char *value); void prefs_set_string_with_option(preference_t pref, char *option, char *value); diff --git a/src/ui/console.c b/src/ui/console.c index 759d6af3..f86dbfec 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -2070,7 +2070,7 @@ cons_executable_setting(void) cons_show("Default '/avatar open' command (/executable avatar) : %s", avatar); prefs_free_string(avatar); - char **urlopen = prefs_get_string_list_with_option(PREF_URL_OPEN_CMD, ""); + gchar **urlopen = prefs_get_string_list_with_option(PREF_URL_OPEN_CMD, ""); cons_show("Default '/url open' command (/executable urlopen) : %s", urlopen[1]); g_strfreev(urlopen); From 7de83217c4d7bfdb70b77f2baeb8f12d4147d873 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Thu, 2 Jul 2020 10:58:54 +0200 Subject: [PATCH 19/22] executable: Use DEF instead of * as default So far: ``` /executable urlsave html "test %u" results in url.save.cmd[html]=test %u /executable urlsave * "test %u" results in nothing. ``` Probably due to limitation in .ini file format. --- src/command/cmd_defs.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index e6fdf202..c36ff712 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2472,17 +2472,18 @@ static struct cmd_t command_defs[] = CMD_TAG_DISCOVERY) CMD_SYN( "/executable avatar ", - "/executable urlopen (|*) ", - "/executable urlsave (|*) ") + "/executable urlopen (|DEF ", + "/executable urlsave (|DEF) ") CMD_DESC( "Configure executable that should be called upon a certain command." "Default is xdg-open.") CMD_ARGS( { "avatar", "Set executable that is run in /avatar open. Use your favourite image viewer." }, - { "urlopen", "Set executable that is run in /url open for a given file type. It may be your favorite browser or a specific viewer. Use * to set default command for undefined file type." }, - { "urlsave", "Set executable that is run in /url save for a given protocol. Use your favourite downloader. Use * to set default command for undefined protocol."}) + { "urlopen", "Set executable that is run in /url open for a given file type. It may be your favorite browser or a specific viewer. Use DEF to set default command for undefined file type." }, + { "urlsave", "Set executable that is run in /url save for a given protocol. Use your favourite downloader. Use DEF to set default command for undefined protocol."}) CMD_EXAMPLES( "/executable avatar xdg-open", + "/executable urlopen DEF false \"xdg-open %u\"", "/executable urlopen html false \"firefox %u\"", "/executable urlsave aesgcm \"omut -d %u %p\"") }, From 6ada720e182f48a929d0f1b169f02b49a65d60ec Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Thu, 2 Jul 2020 10:59:45 +0200 Subject: [PATCH 20/22] executable: actually take the user set default if a certain scheme is not found --- src/config/preferences.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/config/preferences.c b/src/config/preferences.c index bab53000..7fff766d 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -526,14 +526,19 @@ prefs_get_string_with_option(preference_t pref, gchar *option) char *result = g_key_file_get_locale_string(prefs, group, key, option, NULL); if (result == NULL) { - if (def) { - return g_strdup(def); - } else { - return NULL; + // check for user set default + result = g_key_file_get_locale_string(prefs, group, key, "DEF", NULL); + if (result == NULL) { + if (def) { + // use hardcoded profanity default + return g_strdup(def); + } else { + return NULL; + } } - } else { - return result; } + + return result; } gchar** From 322caf877ee9f3bb70cbf226303c283e97a4139b Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Thu, 2 Jul 2020 11:14:27 +0200 Subject: [PATCH 21/22] Transform url.open.cmd to new default scheme Additionally to: 7de83217c4d7bfdb70b77f2baeb8f12d4147d873 1e2a288d80fe0200f1d44d5106f7cc5bfd77718b --- src/config/preferences.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/preferences.c b/src/config/preferences.c index 7fff766d..84f0302f 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -169,7 +169,7 @@ static void _prefs_load(void) value = g_string_append(value, val); value = g_string_append(value, " %u;"); - g_key_file_set_string(prefs, PREF_GROUP_EXECUTABLES, "url.open.cmd", value->str); + g_key_file_set_locale_string(prefs, PREF_GROUP_EXECUTABLES, "url.open.cmd", "DEF", value->str); g_key_file_remove_key(prefs, PREF_GROUP_LOGGING, "urlopen.cmd", NULL); g_string_free(value, TRUE); From 86cd33405e7f67647ce2c171e19bab4120201140 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Thu, 2 Jul 2020 11:18:37 +0200 Subject: [PATCH 22/22] Add note that /executable needs more work --- src/ui/console.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ui/console.c b/src/ui/console.c index f86dbfec..47267e1c 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -2070,6 +2070,8 @@ cons_executable_setting(void) cons_show("Default '/avatar open' command (/executable avatar) : %s", avatar); prefs_free_string(avatar); + //TODO: there needs to be a way to get all the "locales"/schemes so we can + //display the defualt openers for all filetypes gchar **urlopen = prefs_get_string_list_with_option(PREF_URL_OPEN_CMD, ""); cons_show("Default '/url open' command (/executable urlopen) : %s", urlopen[1]); g_strfreev(urlopen);