about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-07-10 01:07:41 +0100
committerJames Booth <boothj5@gmail.com>2016-07-10 01:07:41 +0100
commit448bef247b076683862e45aee78f06e29938ffc6 (patch)
treec0b85a06cf1588d07553b83a918b35e610b478f8 /src
parent44862fe84233f82d997c458b2eb162af9ae6cf0b (diff)
downloadprofani-tty-448bef247b076683862e45aee78f06e29938ffc6.tar.gz
Add /plugin reload command
Diffstat (limited to 'src')
-rw-r--r--src/command/cmd_ac.c25
-rw-r--r--src/command/cmd_defs.c7
-rw-r--r--src/command/cmd_funcs.c13
-rw-r--r--src/plugins/plugins.c11
-rw-r--r--src/plugins/plugins.h1
5 files changed, 55 insertions, 2 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c
index 565ce336..09383edf 100644
--- a/src/command/cmd_ac.c
+++ b/src/command/cmd_ac.c
@@ -186,6 +186,7 @@ static Autocomplete autoping_ac;
 static Autocomplete plugins_ac;
 static Autocomplete plugins_load_ac;
 static Autocomplete plugins_unload_ac;
+static Autocomplete plugins_reload_ac;
 static Autocomplete sendfile_ac;
 static Autocomplete blocked_ac;
 static Autocomplete tray_ac;
@@ -486,6 +487,7 @@ cmd_ac_init(void)
     theme_load_ac = NULL;
     plugins_load_ac = NULL;
     plugins_unload_ac = NULL;
+    plugins_reload_ac = NULL;
 
     who_roster_ac = autocomplete_new();
     autocomplete_add(who_roster_ac, "chat");
@@ -705,6 +707,7 @@ cmd_ac_init(void)
     plugins_ac = autocomplete_new();
     autocomplete_add(plugins_ac, "load");
     autocomplete_add(plugins_ac, "unload");
+    autocomplete_add(plugins_ac, "reload");
 
     sendfile_ac = autocomplete_new();
 
@@ -924,6 +927,10 @@ cmd_ac_reset(ProfWin *window)
         autocomplete_free(plugins_unload_ac);
         plugins_unload_ac = NULL;
     }
+    if (plugins_reload_ac) {
+        autocomplete_free(plugins_reload_ac);
+        plugins_reload_ac = NULL;
+    }
     autocomplete_reset(account_ac);
     autocomplete_reset(account_set_ac);
     autocomplete_reset(account_clear_ac);
@@ -1103,6 +1110,7 @@ cmd_ac_uninit(void)
     autocomplete_free(plugins_ac);
     autocomplete_free(plugins_load_ac);
     autocomplete_free(plugins_unload_ac);
+    autocomplete_free(plugins_reload_ac);
     autocomplete_free(sendfile_ac);
     autocomplete_free(blocked_ac);
     autocomplete_free(tray_ac);
@@ -1899,6 +1907,23 @@ _plugins_autocomplete(ProfWin *window, const char *const input)
         }
     }
 
+    if (strncmp(input, "/plugins reload ", 16) == 0) {
+        if (plugins_reload_ac == NULL) {
+            plugins_reload_ac = autocomplete_new();
+            GList *plugins = plugins_loaded_list();
+            GList *curr = plugins;
+            while (curr) {
+                autocomplete_add(plugins_reload_ac, curr->data);
+                curr = g_list_next(curr);
+            }
+            g_list_free(plugins);
+        }
+        result = autocomplete_param_with_ac(input, "/plugins reload", plugins_reload_ac, TRUE);
+        if (result) {
+            return result;
+        }
+    }
+
     if (strncmp(input, "/plugins unload ", 16) == 0) {
         if (plugins_unload_ac == NULL) {
             plugins_unload_ac = autocomplete_new();
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index 02f5ee93..bc8a1057 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -1980,15 +1980,18 @@ static struct cmd_t command_defs[] =
         CMD_SYN(
             "/plugins",
             "/plugins unload <plugin>",
-            "/plugins load <plugin>")
+            "/plugins load <plugin>",
+            "/plugins reload <plugin>")
         CMD_DESC(
             "Manage plugins. Passing no arguments lists currently loaded plugins.")
         CMD_ARGS(
             { "load <plugin>",       "Load a plugin." },
+            { "reload <plugin>",     "Reload a plugin." },
             { "unload <plugin>",     "Unload a plugin." })
         CMD_EXAMPLES(
             "/plugin load browser.py",
-            "/plugin unload say.py")
+            "/plugin unload say.py",
+            "/plugin reload wikipedia.py")
     },
 
     { "/prefs",
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 540773d7..f5646a51 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -6051,6 +6051,19 @@ cmd_plugins(ProfWin *window, const char *const command, gchar **args)
         }
 
         return TRUE;
+    } else if (g_strcmp0(args[0], "reload") == 0) {
+        if (args[1] == NULL) {
+            cons_bad_cmd_usage(command);
+            return TRUE;
+        }
+        gboolean res = plugins_reload(args[1]);
+        if (res) {
+            cons_show("Reloaded plugin: %s", args[1]);
+        } else {
+            cons_show("Failed to reload plugin: %s", args[1]);
+        }
+
+        return TRUE;
     } else {
         GList *plugins = plugins_loaded_list();
         if (plugins == NULL) {
diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c
index ea8e7d6a..46fa482f 100644
--- a/src/plugins/plugins.c
+++ b/src/plugins/plugins.c
@@ -187,6 +187,17 @@ plugins_unload(const char *const name)
     return TRUE;
 }
 
+gboolean
+plugins_reload(const char *const name)
+{
+    gboolean res = plugins_unload(name);
+    if (res) {
+        res = plugins_load(name);
+    }
+
+    return res;
+}
+
 static gchar*
 _get_plugins_dir(void)
 {
diff --git a/src/plugins/plugins.h b/src/plugins/plugins.h
index feddcbfe..45be1fc6 100644
--- a/src/plugins/plugins.h
+++ b/src/plugins/plugins.h
@@ -107,6 +107,7 @@ void plugins_shutdown(void);
 
 gboolean plugins_load(const char *const name);
 gboolean plugins_unload(const char *const name);
+gboolean plugins_reload(const char *const name);
 
 void plugins_on_start(void);
 void plugins_on_shutdown(void);