Implemented /tox delete command.

This commit is contained in:
Håvard Pettersson 2014-09-19 18:41:28 +02:00
parent 2f057a380f
commit 1f6a0b1e7d
2 changed files with 29 additions and 8 deletions

View File

@ -592,18 +592,29 @@ tox_weechat_cmd_tox(void *data, struct t_gui_buffer *buffer,
struct t_tox_weechat_identity *identity; struct t_tox_weechat_identity *identity;
if ((identity = tox_weechat_identity_name_search(name))) 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); 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); tox_weechat_identity_delete(identity, true);
}
else else
{
weechat_printf(NULL, weechat_printf(NULL,
"%s%s: You must confirm deletion with either " "%s%s: You must confirm deletion with either "
"\"-keepdata\" or \"-yes\" (see /help tox)", "\"-keepdata\" or \"-yes\" (see /help tox)",
weechat_prefix("error"), weechat_prefix("error"),
weechat_plugin->name); 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 else
{ {
@ -612,9 +623,9 @@ tox_weechat_cmd_tox(void *data, struct t_gui_buffer *buffer,
weechat_prefix("error"), weechat_prefix("error"),
weechat_plugin->name, weechat_plugin->name,
identity->name); identity->name);
return WEECHAT_RC_OK;
} }
return WEECHAT_RC_OK;
} }
else if (argc == 3 && (weechat_strcasecmp(argv[1], "connect") == 0)) else if (argc == 3 && (weechat_strcasecmp(argv[1], "connect") == 0))

View File

@ -222,9 +222,12 @@ tox_weechat_identity_connect(struct t_tox_weechat_identity *identity)
return; return;
// create main buffer // create main buffer
identity->buffer = weechat_buffer_new(identity->name, if (identity->buffer == NULL)
NULL, NULL, {
tox_weechat_identity_buffer_close_callback, identity); identity->buffer = weechat_buffer_new(identity->name,
NULL, NULL,
tox_weechat_identity_buffer_close_callback, identity);
}
// create Tox // create Tox
identity->tox = tox_new(NULL); identity->tox = tox_new(NULL);
@ -372,6 +375,13 @@ tox_weechat_identity_free(struct t_tox_weechat_identity *identity)
// disconnect // disconnect
tox_weechat_identity_disconnect(identity); 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 // remove from list
if (identity == tox_weechat_last_identity) if (identity == tox_weechat_last_identity)
tox_weechat_last_identity = identity->prev_identity; tox_weechat_last_identity = identity->prev_identity;