From fc868d21170e4884506d401afd68f9890e99af18 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 26 Mar 2016 01:48:57 +0000 Subject: [PATCH] Added string settings to C and Python examples --- tests/python-test.py | 41 ++++++++++++++++++++++-- tests/test-c-plugin/test-c-plugin.c | 49 +++++++++++++++++++++++++++-- 2 files changed, 85 insertions(+), 5 deletions(-) diff --git a/tests/python-test.py b/tests/python-test.py index 41c52bf..58f57e5 100644 --- a/tests/python-test.py +++ b/tests/python-test.py @@ -204,6 +204,33 @@ def _boolean(op, group, key, value_str): prof.settings_set_boolean(group, key, value) prof.win_show(plugin_win, "Set [" + group + "] " + key + " to " + str(value)) +def _string(op, group, key, value): + if op != "get" and op != "set": + prof.cons_bad_cmd_usage("/python-test") + return + + if group == None or key == None: + prof.cons_bad_cmd_usage("/python-test") + return + + if op == "set" and not value: + prof.cons_bad_cmd_usage("/python-test") + return + + if op == "get": + _create_win() + prof.win_focus(plugin_win) + res = prof.settings_get_string(group, key, None) + if res: + prof.win_show(plugin_win, "String setting: " + res) + else: + prof.win_show(plugin_win, "String setting: None") + elif op == "set": + _create_win() + prof.win_focus(plugin_win) + prof.settings_set_string(group, key, value) + prof.win_show(plugin_win, "Set [" + group + "] " + key + " to " + value) + def _cmd_pythontest(subcmd=None, arg1=None, arg2=None, arg3=None, arg4=None): if subcmd == "consalert": _consalert() elif subcmd == "consshow": _consshow(arg1) @@ -218,6 +245,7 @@ def _cmd_pythontest(subcmd=None, arg1=None, arg2=None, arg3=None, arg4=None): elif subcmd == "count": _count() elif subcmd == "ping": _ping(arg1) elif subcmd == "boolean": _boolean(arg1, arg2, arg3, arg4) + elif subcmd == "string": _string(arg1, arg2, arg3, arg4) else: prof.cons_bad_cmd_usage("/python-test") def timed_callback(): @@ -245,7 +273,9 @@ def prof_init(version, status): "/python-test count", "/python-test ping ", "/python-test boolean get ", - "/python-test boolean set " + "/python-test boolean set ", + "/python-test string get ", + "/python-test string set " ] description = "Python test plugins. All commands focus the plugin window." args = [ @@ -263,7 +293,9 @@ def prof_init(version, status): [ "count", "Show the counter, incremented every 5 seconds by a worker thread" ], [ "ping ", "Send an XMPP ping to the specified Jabber ID" ], [ "boolean get ", "Get a boolean setting" ], - [ "boolean set ", "Set a boolean setting" ] + [ "boolean set ", "Set a boolean setting" ], + [ "string get ", "Get a string setting" ], + [ "string set ", "Set a string setting" ] ] examples = [ "/python-test sendline /about", @@ -276,7 +308,7 @@ def prof_init(version, status): prof.register_command("/python-test", 1, 5, synopsis, description, args, examples, _cmd_pythontest) prof.register_ac("/python-test", - [ "consalert", "consshow", "consshow_t", "constest", "winshow", "winshow_t", "notify", "sendline", "get", "log", "count", "ping", "boolean" ] + [ "consalert", "consshow", "consshow_t", "constest", "winshow", "winshow_t", "notify", "sendline", "get", "log", "count", "ping", "boolean", "string" ] ) prof.register_ac("/python-test get", [ "recipient", "room" ] @@ -287,6 +319,9 @@ def prof_init(version, status): prof.register_ac("/python-test boolean", [ "get", "set" ] ) + prof.register_ac("/python-test string", + [ "get", "set" ] + ) prof.register_timed(timed_callback, 30) diff --git a/tests/test-c-plugin/test-c-plugin.c b/tests/test-c-plugin/test-c-plugin.c index 8118362..c48671f 100644 --- a/tests/test-c-plugin/test-c-plugin.c +++ b/tests/test-c-plugin/test-c-plugin.c @@ -321,8 +321,45 @@ booleansetting(char *op, char *group, char *key, char *value_str) char buf[5 + strlen(group) + 2 + strlen(key) + 4 + strlen(value_str)]; sprintf(buf, "Set [%s] %s to %s", group, key, value_str); prof_win_show(plugin_win, buf); - } else { + } +} + +void +stringsetting(char *op, char *group, char *key, char *value) +{ + if (op == NULL || group == NULL || key == NULL) { prof_cons_bad_cmd_usage("/c-test"); + return; + } + + if ((strcmp(op, "get") != 0) && (strcmp(op, "set") != 0)) { + prof_cons_bad_cmd_usage("/c-test"); + return; + } + + if ((strcmp(op, "set") == 0) && (value == NULL)) { + prof_cons_bad_cmd_usage("/c-test"); + return; + } + + if (strcmp(op, "get") == 0) { + create_win(); + prof_win_focus(plugin_win); + char *res = prof_settings_get_string(group, key, NULL); + if (res) { + char buf[16 + strlen(res)]; + sprintf(buf, "String setting: %s", res); + prof_win_show(plugin_win, buf); + } else { + prof_win_show(plugin_win, "String setting: NULL"); + } + } else if (strcmp(op, "set") == 0) { + create_win(); + prof_win_focus(plugin_win); + prof_settings_set_string(group, key, value); + char buf[5 + strlen(group) + 2 + strlen(key) + 4 + strlen(value)]; + sprintf(buf, "Set [%s] %s to %s", group, key, value); + prof_win_show(plugin_win, buf); } } @@ -342,6 +379,7 @@ cmd_ctest(char **args) else if (strcmp(args[0], "count") == 0) docount(); else if (strcmp(args[0], "ping") == 0) doping(args[1]); else if (strcmp(args[0], "boolean") == 0) booleansetting(args[1], args[2], args[3], args[4]); + else if (strcmp(args[0], "string") == 0) stringsetting(args[1], args[2], args[3], args[4]); else prof_cons_bad_cmd_usage("/c-test"); } @@ -374,6 +412,8 @@ prof_init(const char * const version, const char * const status) "/c-test ping ", "/c-test boolean get ", "/c-test boolean set ", + "/c-test string get ", + "/c-test string set ", NULL }; const char *description = "C test plugin. All commands focus the plugin window."; @@ -393,6 +433,8 @@ prof_init(const char * const version, const char * const status) { "ping ", "Send an XMPP ping to the specified Jabber ID" }, { "boolean get ", "Get a boolean setting" }, { "boolean set ", "Set a boolean setting" }, + { "string get ", "Get a string setting" }, + { "string set ", "Set a string setting" }, { NULL, NULL } }; @@ -407,7 +449,7 @@ prof_init(const char * const version, const char * const status) prof_register_command("/c-test", 1, 5, synopsis, description, args, examples, cmd_ctest); - char *cmd_ac[] = { "consalert", "consshow", "consshow_t", "constest", "winshow", "winshow_t", "notify", "sendline", "get", "log", "count", "ping", "boolean", NULL }; + char *cmd_ac[] = { "consalert", "consshow", "consshow_t", "constest", "winshow", "winshow_t", "notify", "sendline", "get", "log", "count", "ping", "boolean", "string", NULL }; prof_register_ac("/c-test", cmd_ac); char *get_ac[] = { "recipient", "room", NULL }; @@ -419,6 +461,9 @@ prof_init(const char * const version, const char * const status) char *boolean_ac[] = { "get", "set", NULL }; prof_register_ac("/c-test boolean", boolean_ac); + char *string_ac[] = { "get", "set", NULL }; + prof_register_ac("/c-test string", string_ac); + prof_register_timed(timed_callback, 30); }