Fixed connecting/disconnecting.

master
Håvard Pettersson 10 years ago
parent f7b086d38d
commit 7c81c9dcfc

@ -628,43 +628,47 @@ tox_weechat_cmd_tox(void *data, struct t_gui_buffer *buffer,
return WEECHAT_RC_OK;
}
else if (argc == 3 && (weechat_strcasecmp(argv[1], "connect") == 0))
else if (argc >= 3 && (weechat_strcasecmp(argv[1], "connect") == 0))
{
char *name = argv[2];
struct t_tox_weechat_identity *identity = tox_weechat_identity_name_search(name);
if (!identity)
for (int i = 2; i < argc; ++i)
{
weechat_printf(NULL,
"%s%s: Identity \"%s\" does not exist.",
weechat_prefix("error"),
weechat_plugin->name,
name);
}
else
{
tox_weechat_identity_connect(identity);
char *name = argv[i];
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_connect(identity);
}
}
return WEECHAT_RC_OK;
}
else if (argc == 3 && (weechat_strcasecmp(argv[1], "disconnect") == 0))
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)
for (int i = 2; i < argc; ++i)
{
weechat_printf(NULL,
"%s%s: Identity \"%s\" does not exist.",
weechat_prefix("error"),
weechat_plugin->name,
name);
}
else
{
tox_weechat_identity_disconnect(identity);
char *name = argv[i];
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;
@ -740,8 +744,8 @@ tox_weechat_commands_init()
"list"
" || create <name>"
" || delete <name> -yes|-keepdata"
" || connect <name>"
" || disconnect <name>",
" || connect [<name>...]"
" || disconnect [<name>...]",
" list: list all Tox identity\n"
" create: create a new Tox identity\n"
" delete: delete a Tox identity; requires either "
@ -752,7 +756,7 @@ tox_weechat_commands_init()
"list"
" || create"
" || delete %(tox_identities) -yes|-keepdata"
" || connect %(tox_disconnected_identities)"
" || disconnect %(tox_connected_identities)",
" || connect %(tox_disconnected_identities)|%*"
" || disconnect %(tox_connected_identities)|%*",
tox_weechat_cmd_tox, NULL);
}

@ -39,10 +39,7 @@ bar_item_away(void *data,
{
struct t_tox_weechat_identity *identity = tox_weechat_identity_for_buffer(buffer);
if (!identity)
return NULL;
if (identity->tox == NULL || identity->tox_online == false)
if (!identity || !(identity->tox))
return NULL;
char *status = NULL;;
@ -68,7 +65,7 @@ bar_item_input_prompt(void *data,
{
struct t_tox_weechat_identity *identity = tox_weechat_identity_for_buffer(buffer);
if (identity->tox == NULL || identity->tox_online == false)
if (!identity || !(identity->tox))
return NULL;
return tox_weechat_get_self_name_nt(identity->tox);
@ -88,11 +85,14 @@ 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);
identity_name,
weechat_color("bar_delim"),
weechat_color("bar_fg"),
identity->tox_online ? "online" : "offline");
return strdup(string);
}

@ -175,6 +175,14 @@ tox_weechat_bootstrap_tox(Tox *tox, const char *address, uint16_t port, const ch
return result;
}
void
tox_weechat_bootstrap_random_node(Tox *tox)
{
int i = rand() % tox_weechat_bootstrap_count;
tox_weechat_bootstrap_tox(tox, tox_weechat_bootstrap_addresses[i],
tox_weechat_bootstrap_ports[i],
tox_weechat_bootstrap_keys[i]);
}
struct t_tox_weechat_identity *
tox_weechat_identity_new(const char *name)
@ -207,15 +215,6 @@ tox_weechat_identity_new(const char *name)
return identity;
}
void
tox_weechat_bootstrap_random_node(Tox *tox)
{
int i = rand() % tox_weechat_bootstrap_count;
tox_weechat_bootstrap_tox(tox, tox_weechat_bootstrap_addresses[i],
tox_weechat_bootstrap_ports[i],
tox_weechat_bootstrap_keys[i]);
}
void
tox_weechat_identity_connect(struct t_tox_weechat_identity *identity)
{
@ -230,6 +229,12 @@ tox_weechat_identity_connect(struct t_tox_weechat_identity *identity)
tox_weechat_identity_buffer_close_callback, identity);
}
weechat_printf(identity->buffer,
"%s%s: identity %s connecting",
weechat_prefix("network"),
weechat_plugin->name,
identity->name);
// create Tox
identity->tox = tox_new(NULL);
@ -302,10 +307,12 @@ 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);
// have to refresh and hide bar items even if we were already offline
tox_weechat_identity_refresh_online_status(identity);
tox_weechat_identity_set_online_status(identity, false);
}
void
@ -321,31 +328,39 @@ tox_weechat_identity_autoconnect()
}
void
tox_weechat_identity_set_online_status(struct t_tox_weechat_identity *identity,
bool online)
tox_weechat_identity_refresh_online_status(struct t_tox_weechat_identity *identity)
{
identity->tox_online = identity->tox && online;
weechat_bar_item_update("buffer_plugin");
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
void
tox_weechat_identity_set_online_status(struct t_tox_weechat_identity *identity,
bool online)
{
if (identity->tox_online ^ online)
{
weechat_printf(buffer,
"%s%s: identity %s disconnected",
weechat_prefix("network"),
weechat_plugin->name,
identity->name);
identity->tox_online = online;
tox_weechat_identity_refresh_online_status(identity);
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);
}
}
}

@ -70,6 +70,9 @@ tox_weechat_identity_disconnect(struct t_tox_weechat_identity *identity);
void
tox_weechat_identity_autoconnect();
void
tox_weechat_identity_refresh_online_status(struct t_tox_weechat_identity *identity);
void
tox_weechat_identity_set_online_status(struct t_tox_weechat_identity *identity,
bool online);

@ -45,10 +45,7 @@ tox_weechat_do_timer_cb(void *data,
// check connection status
int connected = tox_isconnected(identity->tox);
if (connected ^ identity->tox_online)
{
tox_weechat_identity_set_online_status(identity, connected);
}
tox_weechat_identity_set_online_status(identity, connected);
}
return WEECHAT_RC_OK;

Loading…
Cancel
Save