From 1f6a0b1e7dd72af3571c46b71d2e7a3fa36ed2a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Pettersson?= Date: Fri, 19 Sep 2014 18:41:28 +0200 Subject: [PATCH] Implemented /tox delete command. --- src/tox-weechat-commands.c | 21 ++++++++++++++++----- src/tox-weechat-identities.c | 16 +++++++++++++--- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/tox-weechat-commands.c b/src/tox-weechat-commands.c index 57f5478..704bf61 100644 --- a/src/tox-weechat-commands.c +++ b/src/tox-weechat-commands.c @@ -592,18 +592,29 @@ tox_weechat_cmd_tox(void *data, struct t_gui_buffer *buffer, struct t_tox_weechat_identity *identity; if ((identity = tox_weechat_identity_name_search(name))) { - if (strcmp(flag, "-keepdata") == 0) + if (argc == 4 && strcmp(flag, "-keepdata") == 0) + { tox_weechat_identity_delete(identity, false); - else if (strcmp(flag, "-yes") == 0) + } + else if (argc == 4 && strcmp(flag, "-yes") == 0) + { tox_weechat_identity_delete(identity, true); + } else + { weechat_printf(NULL, "%s%s: You must confirm deletion with either " "\"-keepdata\" or \"-yes\" (see /help tox)", weechat_prefix("error"), weechat_plugin->name); + return WEECHAT_RC_OK; + } - return WEECHAT_RC_OK; + weechat_printf(NULL, + "%s%s: Identity \"%s\" has been deleted.", + weechat_prefix("error"), + weechat_plugin->name, + name); } else { @@ -612,9 +623,9 @@ tox_weechat_cmd_tox(void *data, struct t_gui_buffer *buffer, weechat_prefix("error"), weechat_plugin->name, identity->name); - - return WEECHAT_RC_OK; } + + return WEECHAT_RC_OK; } else if (argc == 3 && (weechat_strcasecmp(argv[1], "connect") == 0)) diff --git a/src/tox-weechat-identities.c b/src/tox-weechat-identities.c index d375edb..2843cb5 100644 --- a/src/tox-weechat-identities.c +++ b/src/tox-weechat-identities.c @@ -222,9 +222,12 @@ tox_weechat_identity_connect(struct t_tox_weechat_identity *identity) return; // create main buffer - identity->buffer = weechat_buffer_new(identity->name, - NULL, NULL, - tox_weechat_identity_buffer_close_callback, identity); + if (identity->buffer == NULL) + { + identity->buffer = weechat_buffer_new(identity->name, + NULL, NULL, + tox_weechat_identity_buffer_close_callback, identity); + } // create Tox identity->tox = tox_new(NULL); @@ -372,6 +375,13 @@ tox_weechat_identity_free(struct t_tox_weechat_identity *identity) // disconnect tox_weechat_identity_disconnect(identity); + // close buffer + if (identity->buffer) + { + weechat_buffer_set_pointer(identity->buffer, "close_callback", NULL); + weechat_buffer_close(identity->buffer); + } + // remove from list if (identity == tox_weechat_last_identity) tox_weechat_last_identity = identity->prev_identity;