diff --git a/tests/python-test.py b/tests/python-test.py index cdebcb9..2293f37 100644 --- a/tests/python-test.py +++ b/tests/python-test.py @@ -258,6 +258,27 @@ def _incoming(barejid, resource, message): prof.incoming_message(barejid, resource, message) +def _completer(op, item): + if not item: + prof.cons_bad_cmd_usage("/python-test") + return + + if op == "add": + _create_win() + prof.win_focus(plugin_win) + prof.completer_add("/python-test", [item]) + prof.win_show(plugin_win, "Added \"" + item + "\" to /python-test completer") + prof.completer_add("/python-test completer remove", [item]) + elif op == "remove": + _create_win() + prof.win_focus(plugin_win) + prof.completer_remove("/python-test", [item]) + prof.win_show(plugin_win, "Removed \"" + item + "\" to /python-test completer") + prof.completer_remove("/python-test completer remove", [item]) + else: + prof.cons_bad_cmd_usage("/python-test") + + def _cmd_pythontest(subcmd=None, arg1=None, arg2=None, arg3=None, arg4=None): if subcmd == "consalert": _consalert() elif subcmd == "consshow": _consshow(arg1) @@ -275,6 +296,7 @@ def _cmd_pythontest(subcmd=None, arg1=None, arg2=None, arg3=None, arg4=None): elif subcmd == "string": _string(arg1, arg2, arg3, arg4) elif subcmd == "int": _int(arg1, arg2, arg3, arg4) elif subcmd == "incoming": _incoming(arg1, arg2, arg3) + elif subcmd == "completer": _completer(arg1, arg2) else: prof.cons_bad_cmd_usage("/python-test") def timed_callback(): @@ -307,7 +329,8 @@ def prof_init(version, status): "/python-test string set ", "/python-test int get ", "/python-test int set ", - "/python-test incoming " + "/python-test incoming ", + "/python-test completer add|remove " ] description = "Python test plugins. All commands focus the plugin window." args = [ @@ -330,7 +353,9 @@ def prof_init(version, status): [ "string set ", "Set a string setting" ], [ "int get ", "Get a integer setting" ], [ "int set ", "Set a integer setting" ], - [ "incoming ", "Show an incoming message." ] + [ "incoming ", "Show an incoming message." ], + [ "completer add ", "Add an autocomplete item to the /c-test command." ], + [ "completer remove ", "Remove an autocomplete item from the /c-test command." ] ] examples = [ "/python-test sendline /about", @@ -359,7 +384,9 @@ def prof_init(version, status): "boolean", "string", "int", - "incoming" ] + "incoming", + "completer" + ] ) prof.completer_add("/python-test get", [ "recipient", "room" ] @@ -376,6 +403,9 @@ def prof_init(version, status): prof.completer_add("/python-test int", [ "get", "set" ] ) + prof.completer_add("/python-test completer", + [ "add", "remove" ] + ) prof.register_timed(timed_callback, 30) @@ -483,3 +513,7 @@ def prof_on_contact_presence(barejid, resource, presence, status, priority): prof.win_show(plugin_win, "fired -> prof_on_contact_presence: " + barejid + "/" + resource + " " + presence + " " + str(priority) + " \"" + status + "\"") else: prof.win_show(plugin_win, "fired -> prof_on_contact_presence: " + barejid + "/" + resource + " " + presence + " " + str(priority)) + +def prof_on_chat_win_focus(barejid): + _create_win() + prof.win_show(plugin_win, "fired -> prof_on_chat_win_focus: " + barejid) diff --git a/tests/test-c-plugin/test-c-plugin.c b/tests/test-c-plugin/test-c-plugin.c index 03df91a..c019df8 100644 --- a/tests/test-c-plugin/test-c-plugin.c +++ b/tests/test-c-plugin/test-c-plugin.c @@ -400,6 +400,37 @@ incomingmsg(char *barejid, char *resource, char *message) prof_incoming_message(barejid, resource, message); } +void +completer(char *op, char *item) +{ + if (item == NULL) { + prof_cons_bad_cmd_usage("/c-test"); + return; + } + + if (strcmp(op, "add") == 0) { + create_win(); + prof_win_focus(plugin_win); + char *ac[] = { item, NULL }; + prof_completer_add("/c-test", ac); + char buf[256]; + sprintf(buf, "Added \"%s\" to /c-test completer", item); + prof_win_show(plugin_win, buf); + prof_completer_add("/c-test completer remove", ac); + } else if (strcmp(op, "remove") == 0) { + create_win(); + prof_win_focus(plugin_win); + char *ac[] = { item, NULL }; + prof_completer_remove("/c-test", ac); + char buf[256]; + sprintf(buf, "Removed \"%s\" from /c-test completer", item); + prof_win_show(plugin_win, buf); + prof_completer_remove("/c-test completer remove", ac); + } else { + prof_cons_bad_cmd_usage("/c-test"); + } +} + void cmd_ctest(char **args) { @@ -419,6 +450,7 @@ cmd_ctest(char **args) else if (strcmp(args[0], "string") == 0) stringsetting(args[1], args[2], args[3], args[4]); else if (strcmp(args[0], "int") == 0) intsetting(args[1], args[2], args[3], args[4]); else if (strcmp(args[0], "incoming") == 0) incomingmsg(args[1], args[2], args[3]); + else if (strcmp(args[0], "completer") == 0) completer(args[1], args[2]); else prof_cons_bad_cmd_usage("/c-test"); } @@ -456,6 +488,7 @@ prof_init(const char * const version, const char * const status) "/c-test int get ", "/c-test int set ", "/c-test incoming ", + "/c-test completer add|remove ", NULL }; const char *description = "C test plugin. All commands focus the plugin window."; @@ -480,6 +513,8 @@ prof_init(const char * const version, const char * const status) { "int get ", "Get a integer setting" }, { "int set ", "Set a integer setting" }, { "incoming ", "Show an incoming message." }, + { "completer add ", "Add an autocomplete item to the /c-test command." }, + { "completer remove ", "Remove an autocomplete item from the /c-test command." }, { NULL, NULL } }; @@ -511,6 +546,7 @@ prof_init(const char * const version, const char * const status) "string", "int", "incoming", + "completer", NULL }; prof_completer_add("/c-test", cmd_ac); @@ -530,6 +566,9 @@ prof_init(const char * const version, const char * const status) char *int_ac[] = { "get", "set", NULL }; prof_completer_add("/c-test int", int_ac); + char *completer_ac[] = { "add", "remove", NULL }; + prof_completer_add("/c-test completer", completer_ac); + prof_register_timed(timed_callback, 30); } @@ -824,3 +863,13 @@ prof_on_contact_presence(const char *const barejid, const char *const resource, } prof_win_show(plugin_win, buf); } + +void +prof_on_chat_win_focus(const char *const barejid) +{ + create_win(); + char *str = "fired -> prof_on_chat_win_focus: "; + char buf[strlen(str) + strlen(barejid) + 1]; + sprintf(buf, "%s%s", str, barejid); + prof_win_show(plugin_win, buf); +}