Implemented /tox disconnect.

master
Håvard Pettersson 10 years ago
parent 4882e83970
commit f7b086d38d

@ -649,6 +649,27 @@ tox_weechat_cmd_tox(void *data, struct t_gui_buffer *buffer,
return WEECHAT_RC_OK;
}
else if (argc == 3 && (weechat_strcasecmp(argv[1], "disconnect") == 0))
{
char *name = argv[2];
struct t_tox_weechat_identity *identity = tox_weechat_identity_name_search(name);
if (!identity)
{
weechat_printf(NULL,
"%s%s: Identity \"%s\" does not exist.",
weechat_prefix("error"),
weechat_plugin->name,
name);
}
else
{
tox_weechat_identity_disconnect(identity);
}
return WEECHAT_RC_OK;
}
return WEECHAT_RC_ERROR;
}
@ -719,16 +740,19 @@ tox_weechat_commands_init()
"list"
" || create <name>"
" || delete <name> -yes|-keepdata"
" || connect <name>",
" list: list all Tox identity\n"
" create: create a new Tox identity\n"
" delete: delete a Tox identity; requires either "
" || connect <name>"
" || disconnect <name>",
" list: list all Tox identity\n"
" create: create a new Tox identity\n"
" delete: delete a Tox identity; requires either "
"-yes to confirm deletion or -keepdata to delete the "
"identity but keep the Tox data file\n"
"connect: connect a Tox identity to the network\n",
" connect: connect a Tox identity to the network\n"
"disconnect: connect a Tox identity to the network\n",
"list"
" || create"
" || delete %(tox_identities) -yes|-keepdata"
" || connect %(tox_identities)",
" || connect %(tox_disconnected_identities)"
" || disconnect %(tox_connected_identities)",
tox_weechat_cmd_tox, NULL);
}

@ -42,6 +42,9 @@ bar_item_away(void *data,
if (!identity)
return NULL;
if (identity->tox == NULL || identity->tox_online == false)
return NULL;
char *status = NULL;;
switch (tox_get_self_user_status(identity->tox))
{
@ -64,6 +67,10 @@ bar_item_input_prompt(void *data,
struct t_hashtable *extra_info)
{
struct t_tox_weechat_identity *identity = tox_weechat_identity_for_buffer(buffer);
if (identity->tox == NULL || identity->tox_online == false)
return NULL;
return tox_weechat_get_self_name_nt(identity->tox);
}
@ -81,14 +88,11 @@ bar_item_buffer_plugin(void *data, struct t_gui_bar_item *item,
const char *identity_name = identity->name;
snprintf(string, sizeof(string),
"%s%s/%s%s%s/%s%s",
"%s%s/%s%s",
plugin_name,
weechat_color("bar_delim"),
weechat_color("bar_fg"),
identity_name,
weechat_color("bar_delim"),
weechat_color("bar_fg"),
identity->tox_online ? "online" : "offline");
identity_name);
return strdup(string);
}

@ -199,6 +199,7 @@ tox_weechat_identity_new(const char *name)
identity->tox_do_timer = NULL;
identity->chats = identity->last_chat = NULL;
identity->friend_requests = identity->last_friend_request = NULL;
identity->tox_online = false;
// set up config
tox_weechat_config_init_identity(identity);
@ -301,6 +302,8 @@ tox_weechat_identity_disconnect(struct t_tox_weechat_identity *identity)
free(path);
}
tox_weechat_identity_set_online_status(identity, false);
// stop Tox timer
weechat_unhook(identity->tox_do_timer);
}
@ -317,6 +320,35 @@ tox_weechat_identity_autoconnect()
}
}
void
tox_weechat_identity_set_online_status(struct t_tox_weechat_identity *identity,
bool online)
{
identity->tox_online = identity->tox && online;
weechat_bar_item_update("input_prompt");
weechat_bar_item_update("away");
struct t_gui_buffer *buffer = identity->buffer ?: NULL;
if (identity->tox_online)
{
weechat_printf(buffer,
"%s%s: identity %s connected",
weechat_prefix("network"),
weechat_plugin->name,
identity->name);
}
else
{
weechat_printf(buffer,
"%s%s: identity %s disconnected",
weechat_prefix("network"),
weechat_plugin->name,
identity->name);
}
}
struct t_tox_weechat_identity *
tox_weechat_identity_name_search(const char *name)
{

@ -70,6 +70,10 @@ tox_weechat_identity_disconnect(struct t_tox_weechat_identity *identity);
void
tox_weechat_identity_autoconnect();
void
tox_weechat_identity_set_online_status(struct t_tox_weechat_identity *identity,
bool online);
struct t_tox_weechat_identity *
tox_weechat_identity_name_search(const char *name);

@ -47,8 +47,7 @@ tox_weechat_do_timer_cb(void *data,
int connected = tox_isconnected(identity->tox);
if (connected ^ identity->tox_online)
{
identity->tox_online = connected;
weechat_bar_item_update("buffer_plugin");
tox_weechat_identity_set_online_status(identity, connected);
}
}

Loading…
Cancel
Save