1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-26 15:13:27 +01:00

remove superfluous prompt alerts and some visual changes

This commit is contained in:
Jfreegman 2013-09-05 01:34:23 -04:00
parent f7d96b0779
commit 369233ba04
4 changed files with 70 additions and 92 deletions

View File

@ -136,32 +136,27 @@ static void chat_onStatusChange(ToxWindow *self, Tox *m, int num, TOX_USERSTATUS
if (ctx->friendnum != num) if (ctx->friendnum != num)
return; return;
wattron(ctx->history, COLOR_PAIR(CYAN)); char *status_msg = NULL;
wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); int colour = 0;
wattroff(ctx->history, COLOR_PAIR(CYAN));
switch(status) { if (status == TOX_USERSTATUS_BUSY) {
status_msg = "[Busy]";
colour = RED;
}
else if (status == TOX_USERSTATUS_AWAY) {
status_msg = "[Away]";
colour = YELLOW;
}
case TOX_USERSTATUS_NONE: if (status_msg != NULL) {
wprintw(ctx->history, "* Chat partner set status to "); wattron(ctx->history, COLOR_PAIR(CYAN));
wattron(ctx->history, COLOR_PAIR(GREEN)); wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
wprintw(ctx->history, "[Online]\n"); wattroff(ctx->history, COLOR_PAIR(CYAN));
wattroff(ctx->history, COLOR_PAIR(GREEN));
break;
case TOX_USERSTATUS_BUSY: wprintw(ctx->history, "* Chat partner set status to: ");
wprintw(ctx->history, "* Chat partner set status to "); wattron(ctx->history, COLOR_PAIR(colour) | A_BOLD);
wattron(ctx->history, COLOR_PAIR(RED)); wprintw(ctx->history, "%s\n", status_msg);
wprintw(ctx->history, "[Busy]\n"); wattroff(ctx->history, COLOR_PAIR(colour) | A_BOLD);
wattroff(ctx->history, COLOR_PAIR(RED));
break;
case TOX_USERSTATUS_AWAY:
wprintw(ctx->history, "* Chat partner set status to ");
wattron(ctx->history, COLOR_PAIR(YELLOW));
wprintw(ctx->history, "[Away]\n");
wattroff(ctx->history, COLOR_PAIR(YELLOW));
break;
} }
} }
@ -378,26 +373,26 @@ void execute(ToxWindow *self, ChatContext *ctx, Tox *m, char *cmd)
if (!strncmp(status, "online", strlen("online"))) { if (!strncmp(status, "online", strlen("online"))) {
status_kind = TOX_USERSTATUS_NONE; status_kind = TOX_USERSTATUS_NONE;
wprintw(ctx->history, "Status set to "); wprintw(ctx->history, "Status set to: ");
wattron(ctx->history, COLOR_PAIR(GREEN)); wattron(ctx->history, COLOR_PAIR(GREEN) | A_BOLD);
wprintw(ctx->history, "[Online]\n"); wprintw(ctx->history, "[Online]\n");
wattroff(ctx->history, COLOR_PAIR(GREEN)); wattroff(ctx->history, COLOR_PAIR(GREEN) | A_BOLD);
} }
else if (!strncmp(status, "away", strlen("away"))) { else if (!strncmp(status, "away", strlen("away"))) {
status_kind = TOX_USERSTATUS_AWAY; status_kind = TOX_USERSTATUS_AWAY;
wprintw(ctx->history, "Status set to "); wprintw(ctx->history, "Status set to: ");
wattron(ctx->history, COLOR_PAIR(YELLOW)); wattron(ctx->history, COLOR_PAIR(YELLOW) | A_BOLD);
wprintw(ctx->history, "[Away]\n"); wprintw(ctx->history, "[Away]\n");
wattroff(ctx->history, COLOR_PAIR(YELLOW)); wattroff(ctx->history, COLOR_PAIR(YELLOW) | A_BOLD);
} }
else if (!strncmp(status, "busy", strlen("busy"))) { else if (!strncmp(status, "busy", strlen("busy"))) {
status_kind = TOX_USERSTATUS_BUSY; status_kind = TOX_USERSTATUS_BUSY;
wprintw(ctx->history, "Status set to "); wprintw(ctx->history, "Status set to: ");
wattron(ctx->history, COLOR_PAIR(RED)); wattron(ctx->history, COLOR_PAIR(RED) | A_BOLD);
wprintw(ctx->history, "[Busy]\n"); wprintw(ctx->history, "[Busy]\n");
wattroff(ctx->history, COLOR_PAIR(RED)); wattroff(ctx->history, COLOR_PAIR(RED) | A_BOLD);
} }
else { else {

View File

@ -93,7 +93,7 @@ int friendlist_onFriendAdded(Tox *m, int num)
friends[i].active = true; friends[i].active = true;
friends[i].chatwin = -1; friends[i].chatwin = -1;
friends[i].online = false; friends[i].online = false;
friends[i].status = TOX_USERSTATUS_INVALID; friends[i].status = TOX_USERSTATUS_NONE;
if (tox_getname(m, num, friends[i].name) != 0 || friends[i].name[0] == '\0') if (tox_getname(m, num, friends[i].name) != 0 || friends[i].name[0] == '\0')
strcpy((char *) friends[i].name, "unknown"); strcpy((char *) friends[i].name, "unknown");
@ -150,10 +150,9 @@ static void delete_friend(Tox *m, ToxWindow *self, int f_num, wint_t key)
break; break;
} }
if (store_data(m, DATA_FILE))
wprintw(self->window, "\nFailed to store messenger data\n");
num_friends = i; num_friends = i;
store_data(m, DATA_FILE);
select_friend(m, KEY_DOWN); select_friend(m, KEY_DOWN);
} }
@ -212,9 +211,9 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
} }
wprintw(self->window, "["); wprintw(self->window, "[");
wattron(self->window, COLOR_PAIR(colour)); wattron(self->window, COLOR_PAIR(colour) | A_BOLD);
wprintw(self->window, "O"); wprintw(self->window, "O");
wattroff(self->window, COLOR_PAIR(colour)); wattroff(self->window, COLOR_PAIR(colour) | A_BOLD);
wprintw(self->window, "] %s", friends[i].name); wprintw(self->window, "] %s", friends[i].name);
if (friends[i].statusmsg[0]) if (friends[i].statusmsg[0])

View File

@ -314,7 +314,8 @@ void cmd_nick(ToxWindow *self, Tox *m, int argc, char **argv)
} }
nick = argv[1]; nick = argv[1];
nick[strlen(++nick)-1] = L'\0'; if (nick[0] == '\"')
nick[strlen(++nick)-1] = L'\0';
tox_setname(m, (uint8_t *) nick, strlen(nick) + 1); tox_setname(m, (uint8_t *) nick, strlen(nick) + 1);
wprintw(self->window, "Nickname set to: %s\n", nick); wprintw(self->window, "Nickname set to: %s\n", nick);
@ -358,19 +359,31 @@ void cmd_status(ToxWindow *self, Tox *m, int argc, char **argv)
if (!strncmp(status, "online", strlen("online"))) { if (!strncmp(status, "online", strlen("online"))) {
status_kind = TOX_USERSTATUS_NONE; status_kind = TOX_USERSTATUS_NONE;
status_text = "Online"; wprintw(self->window, "Status set to: ");
} else if (!strncmp(status, "away", strlen("away"))) { wattron(self->window, COLOR_PAIR(GREEN) | A_BOLD);
status_kind = TOX_USERSTATUS_AWAY; wprintw(self->window, "[Online]\n");
status_text = "Away"; wattroff(self->window, COLOR_PAIR(GREEN) | A_BOLD);
} else if (!strncmp(status, "busy", strlen("busy"))) {
status_kind = TOX_USERSTATUS_BUSY;
status_text = "Busy";
} else {
wprintw(self->window, "Invalid status.\n");
return;
} }
wprintw(self->window, "Status set to: %s\n", status_text); else if (!strncmp(status, "away", strlen("away"))) {
status_kind = TOX_USERSTATUS_AWAY;
wprintw(self->window, "Status set to: ");
wattron(self->window, COLOR_PAIR(YELLOW) | A_BOLD);
wprintw(self->window, "[Away]\n");
wattroff(self->window, COLOR_PAIR(YELLOW) | A_BOLD);
}
else if (!strncmp(status, "busy", strlen("busy"))) {
status_kind = TOX_USERSTATUS_BUSY;
wprintw(self->window, "Status set to: ");
wattron(self->window, COLOR_PAIR(RED) | A_BOLD);
wprintw(self->window, "[Busy]\n");
wattroff(self->window, COLOR_PAIR(RED) | A_BOLD);
}
else
wprintw(self->window, "Invalid status.\n");
tox_set_userstatus(m, status_kind); tox_set_userstatus(m, status_kind);
if (msg != NULL) { if (msg != NULL) {

View File

@ -32,7 +32,7 @@ void on_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userd
} }
wprintw(prompt->window, "\nWith the message: %s\n", data); wprintw(prompt->window, "\nWith the message: %s\n", data);
wprintw(prompt->window, "\nUse \"accept %d\" to accept it.\n", n); wprintw(prompt->window, "Type \"accept %d\" to accept it.\n", n);
for (i = 0; i < MAX_WINDOWS_NUM; ++i) { for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].onFriendRequest != NULL) if (windows[i].onFriendRequest != NULL)
@ -48,10 +48,18 @@ void on_connectionchange(Tox *m, int friendnumber, uint8_t status, void *userdat
if (!nick[0]) if (!nick[0])
snprintf(nick, sizeof(nick), "%s", UNKNOWN_NAME); snprintf(nick, sizeof(nick), "%s", UNKNOWN_NAME);
if (status == 1) if (status == 1) {
wprintw(prompt->window, "\n%s has come online\n", nick, friendnumber); wattron(prompt->window, A_BOLD);
else wprintw(prompt->window, "\n%s ", nick);
wprintw(prompt->window, "\n%s went offline\n", nick, friendnumber); wattroff(prompt->window, A_BOLD);
wprintw(prompt->window, "has come online\n");
} else {
wattron(prompt->window, A_BOLD);
wprintw(prompt->window, "\n%s ", nick);
wattroff(prompt->window, A_BOLD);
wprintw(prompt->window, "has gone offline\n");
}
int i; int i;
@ -93,17 +101,6 @@ void on_nickchange(Tox *m, int friendnumber, uint8_t *string, uint16_t length, v
void on_statusmessagechange(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata) void on_statusmessagechange(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata)
{ {
/* Don't show default "Online" status message */
if (strncmp(string, "Online", strlen(string))) {
uint8_t nick[TOX_MAX_NAME_LENGTH] = {0};
tox_getname(m, friendnumber, (uint8_t *) &nick);
if (!nick[0])
snprintf(nick, sizeof(nick), "%s", UNKNOWN_NAME);
wprintw(prompt->window, "\n%s set note to: %s\n", nick, string);
}
int i; int i;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) { for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
@ -114,32 +111,6 @@ void on_statusmessagechange(Tox *m, int friendnumber, uint8_t *string, uint16_t
void on_statuschange(Tox *m, int friendnumber, TOX_USERSTATUS status, void *userdata) void on_statuschange(Tox *m, int friendnumber, TOX_USERSTATUS status, void *userdata)
{ {
uint8_t nick[TOX_MAX_NAME_LENGTH] = {0};
tox_getname(m, friendnumber, (uint8_t *) &nick);
if (!nick[0])
snprintf(nick, sizeof(nick), "%s", UNKNOWN_NAME);
switch(status) {
case TOX_USERSTATUS_NONE:
/* Disabled because it spams a second messages when user comes online */
break;
case TOX_USERSTATUS_BUSY:
wprintw(prompt->window, "\n%s set status to ", nick);
wattron(prompt->window, COLOR_PAIR(RED));
wprintw(prompt->window, "[Busy]\n");
wattroff(prompt->window, COLOR_PAIR(RED));
break;
case TOX_USERSTATUS_AWAY:
wprintw(prompt->window, "\n%s set status to ", nick);
wattron(prompt->window, COLOR_PAIR(YELLOW));
wprintw(prompt->window, "[Away]\n");
wattroff(prompt->window, COLOR_PAIR(YELLOW));
break;
}
int i; int i;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) { for (i = 0; i < MAX_WINDOWS_NUM; ++i) {