Implemented /tox disconnect.

This commit is contained in:
Håvard Pettersson 2014-09-19 19:15:19 +02:00
parent 4882e83970
commit f7b086d38d
5 changed files with 76 additions and 13 deletions

View File

@ -649,6 +649,27 @@ tox_weechat_cmd_tox(void *data, struct t_gui_buffer *buffer,
return WEECHAT_RC_OK; 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; return WEECHAT_RC_ERROR;
} }
@ -719,16 +740,19 @@ tox_weechat_commands_init()
"list" "list"
" || create <name>" " || create <name>"
" || delete <name> -yes|-keepdata" " || delete <name> -yes|-keepdata"
" || connect <name>", " || connect <name>"
" list: list all Tox identity\n" " || disconnect <name>",
" create: create a new Tox identity\n" " list: list all Tox identity\n"
" delete: delete a Tox identity; requires either " " create: create a new Tox identity\n"
" delete: delete a Tox identity; requires either "
"-yes to confirm deletion or -keepdata to delete the " "-yes to confirm deletion or -keepdata to delete the "
"identity but keep the Tox data file\n" "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" "list"
" || create" " || create"
" || delete %(tox_identities) -yes|-keepdata" " || delete %(tox_identities) -yes|-keepdata"
" || connect %(tox_identities)", " || connect %(tox_disconnected_identities)"
" || disconnect %(tox_connected_identities)",
tox_weechat_cmd_tox, NULL); tox_weechat_cmd_tox, NULL);
} }

View File

@ -42,6 +42,9 @@ bar_item_away(void *data,
if (!identity) if (!identity)
return NULL; return NULL;
if (identity->tox == NULL || identity->tox_online == false)
return NULL;
char *status = NULL;; char *status = NULL;;
switch (tox_get_self_user_status(identity->tox)) 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_hashtable *extra_info)
{ {
struct t_tox_weechat_identity *identity = tox_weechat_identity_for_buffer(buffer); 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); 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; const char *identity_name = identity->name;
snprintf(string, sizeof(string), snprintf(string, sizeof(string),
"%s%s/%s%s%s/%s%s", "%s%s/%s%s",
plugin_name, plugin_name,
weechat_color("bar_delim"), weechat_color("bar_delim"),
weechat_color("bar_fg"), weechat_color("bar_fg"),
identity_name, identity_name);
weechat_color("bar_delim"),
weechat_color("bar_fg"),
identity->tox_online ? "online" : "offline");
return strdup(string); return strdup(string);
} }

View File

@ -199,6 +199,7 @@ tox_weechat_identity_new(const char *name)
identity->tox_do_timer = NULL; identity->tox_do_timer = NULL;
identity->chats = identity->last_chat = NULL; identity->chats = identity->last_chat = NULL;
identity->friend_requests = identity->last_friend_request = NULL; identity->friend_requests = identity->last_friend_request = NULL;
identity->tox_online = false;
// set up config // set up config
tox_weechat_config_init_identity(identity); tox_weechat_config_init_identity(identity);
@ -301,6 +302,8 @@ tox_weechat_identity_disconnect(struct t_tox_weechat_identity *identity)
free(path); free(path);
} }
tox_weechat_identity_set_online_status(identity, false);
// stop Tox timer // stop Tox timer
weechat_unhook(identity->tox_do_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 * struct t_tox_weechat_identity *
tox_weechat_identity_name_search(const char *name) tox_weechat_identity_name_search(const char *name)
{ {

View File

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

View File

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