diff options
author | Philip Flohr <philip.flohr@student.kit.edu> | 2018-05-07 20:29:34 +0200 |
---|---|---|
committer | Dmitry Podgorny <pasis.ua@gmail.com> | 2018-09-06 19:28:02 +0300 |
commit | cd86f5bc288872ae8050c6f56515d4b8a5c77475 (patch) | |
tree | 7bfbea8d5cb4ca3037acb5e9a42a3c5367db627c /src | |
parent | e4ddced4203235c8393369ba3f0a62de1f5e980e (diff) | |
download | profani-tty-cd86f5bc288872ae8050c6f56515d4b8a5c77475.tar.gz |
added the possibility to uninstall a plugin
Diffstat (limited to 'src')
-rw-r--r-- | src/command/cmd_defs.c | 4 | ||||
-rw-r--r-- | src/command/cmd_funcs.c | 17 | ||||
-rw-r--r-- | src/command/cmd_funcs.h | 1 | ||||
-rw-r--r-- | src/plugins/plugins.c | 15 | ||||
-rw-r--r-- | src/plugins/plugins.h | 2 |
5 files changed, 39 insertions, 0 deletions
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index a523c939..54df4903 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2084,6 +2084,7 @@ static struct cmd_t command_defs[] = CMD_SUBFUNCS( { "sourcepath", cmd_plugins_sourcepath }, { "install", cmd_plugins_install }, + { "uninstall", cmd_plugins_uninstall }, { "load", cmd_plugins_load }, { "unload", cmd_plugins_unload }, { "reload", cmd_plugins_reload }, @@ -2095,6 +2096,7 @@ static struct cmd_t command_defs[] = "/plugins sourcepath set <path>", "/plugins sourcepath clear", "/plugins install [<path>]", + "/plugins uninstall [<plugin>]", "/plugins unload [<plugin>]", "/plugins load [<plugin>]", "/plugins reload [<plugin>]", @@ -2105,6 +2107,7 @@ static struct cmd_t command_defs[] = { "sourcepath set <path>", "Set the default path to install plugins from, will be used if no arg is passed to /plugins install." }, { "sourcepath clear", "Clear the default plugins source path." }, { "install [<path>]", "Install a plugin, or all plugins found in a directory (recursive). Passing no argument will use the sourcepath if one is set." }, + { "uninstall [<plugin>]", "Uninstall a plugin." }, { "load [<plugin>]", "Load a plugin that already exists in the plugin directory, passing no argument loads all found plugins." }, { "unload [<plugin>]", "Unload a loaded plugin, passing no argument will unload all plugins." }, { "reload [<plugin>]", "Reload a plugin, passing no argument will reload all plugins." }, @@ -2113,6 +2116,7 @@ static struct cmd_t command_defs[] = "/plugins sourcepath set /home/meee/projects/profanity-plugins", "/plugins install", "/plugins install /home/steveharris/Downloads/metal.py", + "/plugins uninstall browser.py", "/plugins load browser.py", "/plugins unload say.py", "/plugins reload wikipedia.py") diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index a955e2f8..6aae8fb2 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -6664,6 +6664,23 @@ cmd_plugins_install(ProfWin *window, const char *const command, gchar **args) } gboolean +cmd_plugins_uninstall(ProfWin *window, const char *const command, gchar **args) +{ + if (args[1] == NULL) { + return FALSE; + } + + gboolean res = plugins_uninstall(args[1]); + if (res) { + cons_show("Uninstalled plugin: %s", args[1]); + } else { + cons_show("Failed to uninstall plugin: %s", args[1]); + } + + return TRUE; +} + +gboolean cmd_plugins_load(ProfWin *window, const char *const command, gchar **args) { if (args[1] == NULL) { diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h index 0bbf338e..a00fce5d 100644 --- a/src/command/cmd_funcs.h +++ b/src/command/cmd_funcs.h @@ -162,6 +162,7 @@ gboolean cmd_console(ProfWin *window, const char *const command, gchar **args); gboolean cmd_plugins(ProfWin *window, const char *const command, gchar **args); gboolean cmd_plugins_sourcepath(ProfWin *window, const char *const command, gchar **args); gboolean cmd_plugins_install(ProfWin *window, const char *const command, gchar **args); +gboolean cmd_plugins_uninstall(ProfWin *window, const char *const command, gchar **args); gboolean cmd_plugins_load(ProfWin *window, const char *const command, gchar **args); gboolean cmd_plugins_unload(ProfWin *window, const char *const command, gchar **args); gboolean cmd_plugins_reload(ProfWin *window, const char *const command, gchar **args); diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c index 8c1bc2cf..5b60b398 100644 --- a/src/plugins/plugins.c +++ b/src/plugins/plugins.c @@ -34,6 +34,7 @@ #include <string.h> #include <stdlib.h> +#include <gio/gio.h> #include "log.h" #include "config.h" @@ -169,6 +170,20 @@ plugins_install_all(const char *const path) } gboolean +plugins_uninstall(const char *const plugin_name) +{ + plugins_unload(plugin_name); + char *plugins_dir = files_get_data_path(DIR_PLUGINS); + GString *target_path = g_string_new(plugins_dir); + free(plugins_dir); + g_string_append(target_path, "/"); + g_string_append(target_path, plugin_name); + GFile *file = g_file_new_for_path(target_path->str); + GError *error = NULL; + return g_file_delete(file, NULL, &error); +} + +gboolean plugins_install(const char *const plugin_name, const char *const filename, GString *error_message) { char *plugins_dir = files_get_data_path(DIR_PLUGINS); diff --git a/src/plugins/plugins.h b/src/plugins/plugins.h index c787ee93..56f2e042 100644 --- a/src/plugins/plugins.h +++ b/src/plugins/plugins.h @@ -115,6 +115,8 @@ void plugins_shutdown(void); void plugins_free_install_result(PluginsInstallResult *result); gboolean plugins_install(const char *const plugin_name, const char *const filename, GString * error_message); +gboolean plugins_uninstall(const char *const plugin_name); +gboolean plugins_update(const char *const plugin_name, const char *const filename, GString * error_message); PluginsInstallResult* plugins_install_all(const char *const path); gboolean plugins_load(const char *const name); GSList* plugins_load_all(void); |