diff options
author | Michael Vetter <jubalh@iodoru.org> | 2020-05-20 14:14:49 +0200 |
---|---|---|
committer | Michael Vetter <jubalh@iodoru.org> | 2020-05-20 14:14:49 +0200 |
commit | 7b541d0a6d196499712f4e7c9854aa294ac16167 (patch) | |
tree | 3f87ef6e933d4a6df49c0fd4e8a319618ef46444 | |
parent | 21cc53bdfdb70bc375bf6b4c46593889b9702489 (diff) | |
download | profani-tty-7b541d0a6d196499712f4e7c9854aa294ac16167.tar.gz |
Add /executable command
This is used to set the openers for various commands. So far for /avatar and /urlopen.
-rw-r--r-- | src/command/cmd_ac.c | 22 | ||||
-rw-r--r-- | src/command/cmd_defs.c | 27 | ||||
-rw-r--r-- | src/command/cmd_funcs.c | 16 | ||||
-rw-r--r-- | src/command/cmd_funcs.h | 1 | ||||
-rw-r--r-- | src/ui/console.c | 12 | ||||
-rw-r--r-- | src/ui/ui.h | 2 |
6 files changed, 68 insertions, 12 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 6883774a..e0d5f577 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -124,6 +124,7 @@ static char* _correction_autocomplete(ProfWin *window, const char *const input, 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* _executable_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _script_autocomplete_func(const char *const prefix, gboolean previous, void *context); @@ -256,6 +257,7 @@ static Autocomplete logging_group_ac; static Autocomplete color_ac; static Autocomplete correction_ac; static Autocomplete avatar_ac; +static Autocomplete executable_ac; void cmd_ac_init(void) @@ -988,8 +990,11 @@ cmd_ac_init(void) avatar_ac = autocomplete_new(); autocomplete_add(avatar_ac, "get"); - autocomplete_add(avatar_ac, "cmd"); autocomplete_add(avatar_ac, "open"); + + executable_ac = autocomplete_new(); + autocomplete_add(executable_ac, "avatar"); + autocomplete_add(executable_ac, "urlopen"); } void @@ -1306,6 +1311,7 @@ cmd_ac_reset(ProfWin *window) autocomplete_reset(color_ac); autocomplete_reset(correction_ac); autocomplete_reset(avatar_ac); + autocomplete_reset(executable_ac); autocomplete_reset(script_ac); if (script_show_ac) { @@ -1464,6 +1470,7 @@ cmd_ac_uninit(void) autocomplete_free(color_ac); autocomplete_free(correction_ac); autocomplete_free(avatar_ac); + autocomplete_free(executable_ac); } static void @@ -1724,6 +1731,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ 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, "/executable", _executable_autocomplete); int len = strlen(input); char parsed[len+1]; @@ -3930,3 +3938,15 @@ _urlopen_autocomplete(ProfWin *window, const char *const input, gboolean previou return result; } +static char* +_executable_autocomplete(ProfWin *window, const char *const input, gboolean previous) +{ + char *result = NULL; + + result = autocomplete_param_with_ac(input, "/executable", executable_ac, TRUE, previous); + if (result) { + return result; + } + + return NULL; +} diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 398badc0..3cf019b5 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2340,26 +2340,23 @@ static struct cmd_t command_defs[] = }, { "/avatar", - parse_args, 2, 2, &cons_avatar_setting, + parse_args, 2, 2, NULL, CMD_NOSUBFUNCS CMD_MAINFUNC(cmd_avatar) CMD_TAGS( CMD_TAG_CHAT) CMD_SYN( "/avatar get <barejid>", - "/avatar open <barejid>", - "/avatar cmd <command>") + "/avatar open <barejid>") CMD_DESC( "Download avatar (XEP-0084) for a certain contact. " "If nothing happens after using this command the user either doesn't have an avatar set at all " "or doesn't use XEP-0084 to publish it.") CMD_ARGS( { "get <barejid>", "Download the avatar. barejid is the JID to download avatar from."}, - { "cmd <command>", "Set a command to execute with 'avatar open'. Use your favourite image viewer here."}, { "open <barejid>", "Download avatar and open it with command."}) CMD_EXAMPLES( "/avatar get thor@valhalla.edda", - "/avatar cmd xdg-open", "/avatar open freyja@vanaheimr.edda") }, @@ -2466,6 +2463,26 @@ static struct cmd_t command_defs[] = { "<url>", "URL to open."}) CMD_NOEXAMPLES }, + + { "/executable", + parse_args, 2, 2, &cons_executable_setting, + CMD_NOSUBFUNCS + CMD_MAINFUNC(cmd_executable) + CMD_TAGS( + CMD_TAG_DISCOVERY) + CMD_SYN( + "/executable avatar <cmd>", + "/executable urlopen <cmd>") + 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." }) + CMD_EXAMPLES( + "/executable avatar xdg-open", + "/executable urlopen firefox") + }, }; static GHashTable *search_index; diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index f91a901c..580494e2 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -8878,3 +8878,19 @@ cmd_urlopen(ProfWin *window, const char *const command, gchar **args) return TRUE; } + +gboolean +cmd_executable(ProfWin *window, const char *const command, gchar **args) +{ + if (g_strcmp0(args[0], "avatar") == 0) { + 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]); + } else { + cons_bad_cmd_usage(command); + } + + return TRUE; +} diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h index a8739974..b87cc22f 100644 --- a/src/command/cmd_funcs.h +++ b/src/command/cmd_funcs.h @@ -233,5 +233,6 @@ 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_executable(ProfWin *window, const char *const command, gchar **args); #endif diff --git a/src/ui/console.c b/src/ui/console.c index 58b33204..d2158862 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -2051,13 +2051,15 @@ cons_correction_setting(void) } void -cons_avatar_setting(void) +cons_executable_setting(void) { - char *pref = prefs_get_string(PREF_AVATAR_CMD); + char *avatar = prefs_get_string(PREF_AVATAR_CMD); + cons_show("Avatar command (/executable avatar) : %s", avatar); + prefs_free_string(avatar); - cons_show("Avatar command (/avatar cmd) : %s", pref); - - prefs_free_string(pref); + char *exec = prefs_get_string(PREF_URL_OPEN_CMD); + cons_show("urlopen command (/executable urlopen) : %s", exec); + prefs_free_string(exec); } void diff --git a/src/ui/ui.h b/src/ui/ui.h index a4878106..6e8083da 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -319,7 +319,7 @@ void cons_winpos_setting(void); void cons_color_setting(void); void cons_os_setting(void); void cons_correction_setting(void); -void cons_avatar_setting(void); +void cons_executable_setting(void); void cons_slashguard_setting(void); void cons_show_contact_online(PContact contact, Resource *resource, GDateTime *last_activity); void cons_show_contact_offline(PContact contact, char *resource, char *status); |