1
0
mirror of https://github.com/Tha14/toxic.git synced 2025-07-01 16:16:46 +02:00

Merge pull request #36 from JFreegman/master

Client specific max name length / status messages now dynamically resize
This commit is contained in:
JFreegman
2013-09-13 17:15:06 -07:00
6 changed files with 86 additions and 46 deletions

View File

@ -57,28 +57,28 @@ static struct {
/* Updates own nick in prompt statusbar */
void prompt_update_nick(ToxWindow *prompt, uint8_t *nick)
{
StatusBar *statusbar = (StatusBar *) prompt->s;
StatusBar *statusbar = (StatusBar *) prompt->stb;
snprintf(statusbar->nick, sizeof(statusbar->nick), "%s", nick);
}
/* Updates own statusmessage in prompt statusbar */
void prompt_update_statusmessage(ToxWindow *prompt, uint8_t *statusmsg)
{
StatusBar *statusbar = (StatusBar *) prompt->s;
StatusBar *statusbar = (StatusBar *) prompt->stb;
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
}
/* Updates own status in prompt statusbar */
void prompt_update_status(ToxWindow *prompt, TOX_USERSTATUS status)
{
StatusBar *statusbar = (StatusBar *) prompt->s;
StatusBar *statusbar = (StatusBar *) prompt->stb;
statusbar->status = status;
}
/* Updates own connection status in prompt statusbar */
void prompt_update_connectionstatus(ToxWindow *prompt, bool is_connected)
{
StatusBar *statusbar = (StatusBar *) prompt->s;
StatusBar *statusbar = (StatusBar *) prompt->stb;
statusbar->is_online = is_connected;
}
@ -385,10 +385,20 @@ void cmd_nick(ToxWindow *self, Tox *m, int argc, char **argv)
return;
}
if (nick[0] == '\"')
nick[strlen(++nick)-1] = L'\0';
int len = strlen(nick);
tox_setname(m, nick, strlen(nick) + 1);
if (nick[0] == '\"') {
++nick;
len -= 2;
nick[len] = L'\0';
}
if (len > TOXIC_MAX_NAME_LENGTH) {
nick[TOXIC_MAX_NAME_LENGTH] = L'\0';
len = TOXIC_MAX_NAME_LENGTH;
}
tox_setname(m, nick, len+1);
prompt_update_nick(self, nick);
store_data(m, DATA_FILE);
@ -604,7 +614,7 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
--y;
}
StatusBar *statusbar = (StatusBar *) self->s;
StatusBar *statusbar = (StatusBar *) self->stb;
werase(statusbar->topline);
@ -668,7 +678,7 @@ void prompt_init_statusbar(ToxWindow *self, Tox *m)
getmaxyx(self->window, y, x);
/* Init statusbar info */
StatusBar *statusbar = (StatusBar *) self->s;
StatusBar *statusbar = (StatusBar *) self->stb;
statusbar->status = TOX_USERSTATUS_NONE;
statusbar->is_online = false;
@ -695,10 +705,10 @@ ToxWindow new_prompt()
ret.onFriendRequest = &prompt_onFriendRequest;
strcpy(ret.name, "prompt");
StatusBar *s = calloc(1, sizeof(StatusBar));
StatusBar *stb = calloc(1, sizeof(StatusBar));
if (s != NULL)
ret.s = s;
if (stb != NULL)
ret.stb = stb;
else {
endwin();
fprintf(stderr, "calloc() failed. Aborting...\n");