From c5b9677fc0edf5921826faa12332980a41c29808 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Sun, 1 Sep 2013 22:11:47 -0400 Subject: [PATCH 1/5] properly implemented statuses --- src/friendlist.c | 47 +++++++++++++++++++++++++++++++++++------------ src/prompt.c | 6 +++--- src/windows.c | 3 +-- 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/friendlist.c b/src/friendlist.c index ab49b05..cb51cbb 100644 --- a/src/friendlist.c +++ b/src/friendlist.c @@ -24,7 +24,7 @@ typedef struct { uint8_t status[TOX_MAX_STATUSMESSAGE_LENGTH]; int num; int chatwin; - bool active; + bool active; } friend_t; static friend_t friends[MAX_FRIENDS_NUM]; @@ -72,9 +72,8 @@ int friendlist_onFriendAdded(Tox *m, int num) friends[i].num = num; friends[i].active = true; friends[i].chatwin = -1; - tox_getname(m, num, friends[i].name); + //tox_getname(m, num, friends[i].name); strcpy((char *) friends[i].name, "unknown"); - strcpy((char *) friends[i].status, "Offline"); if (i == num_friends) ++num_friends; @@ -173,19 +172,43 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m) for (i = 0; i < num_friends; ++i) { if (friends[i].active) { - if (i == num_selected) - wattron(self->window, COLOR_PAIR(3)); - - wprintw(self->window, " > "); + bool is_online = tox_friendstatus(m, i) == TOX_FRIEND_ONLINE; + TOX_USERSTATUS status = tox_get_userstatus(m, i); if (i == num_selected) - wattroff(self->window, COLOR_PAIR(3)); + wprintw(self->window, " > "); + else + wprintw(self->window, " "); - attron(A_BOLD); - wprintw(self->window, "%s ", friends[i].name); - attroff(A_BOLD); + if (is_online) { + int colour; - wprintw(self->window, "(%s)\n", friends[i].status); + switch(status) { + case TOX_USERSTATUS_NONE: + colour = 1; + break; + + case TOX_USERSTATUS_AWAY: + colour = 5; + break; + + case TOX_USERSTATUS_BUSY: + case TOX_USERSTATUS_INVALID: + default: + colour = 3; + break; + } + + wattron(self->window, COLOR_PAIR(colour)); + attron(A_BOLD); + wprintw(self->window, "%s \n", friends[i].name); + attroff(A_BOLD); + wattroff(self->window, COLOR_PAIR(colour)); + } else { + attron(A_BOLD); + wprintw(self->window, "%s \n", friends[i].name); + attroff(A_BOLD); + } } } diff --git a/src/prompt.c b/src/prompt.c index 5fb4334..521f624 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -294,13 +294,13 @@ void cmd_status(ToxWindow *self, Tox *m, char **args) if (!strncmp(status, "online", strlen("online"))) { status_kind = TOX_USERSTATUS_NONE; - status_text = "ONLINE"; + status_text = "Online"; } else if (!strncmp(status, "away", strlen("away"))) { status_kind = TOX_USERSTATUS_AWAY; - status_text = "AWAY"; + status_text = "Away"; } else if (!strncmp(status, "busy", strlen("busy"))) { status_kind = TOX_USERSTATUS_BUSY; - status_text = "BUSY"; + status_text = "Busy"; } else { wprintw(self->window, "Invalid status.\n"); return; diff --git a/src/windows.c b/src/windows.c index 4fcb653..83d60df 100644 --- a/src/windows.c +++ b/src/windows.c @@ -84,9 +84,8 @@ void on_friendadded(Tox *m, int friendnumber) { friendlist_onFriendAdded(m, friendnumber); - if (store_data(m, DATA_FILE)) { + if (store_data(m, DATA_FILE)) wprintw(prompt->window, "\nCould not store Tox data\n"); - } } /* CALLBACKS END */ From 73d6fba055869063b0a105188776561758b523d7 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Mon, 2 Sep 2013 00:18:20 -0400 Subject: [PATCH 2/5] display status messages in friends list --- src/chat.c | 6 +++--- src/friendlist.c | 20 ++++++++++---------- src/friendlist.h | 2 ++ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/chat.c b/src/chat.c index 7ec3631..75f68a3 100644 --- a/src/chat.c +++ b/src/chat.c @@ -322,17 +322,17 @@ void execute(ToxWindow *self, ChatContext *ctx, Tox *m, char *cmd) if (!strncmp(status, "online", strlen("online"))) { status_kind = TOX_USERSTATUS_NONE; - status_text = "ONLINE"; + status_text = "Online"; } else if (!strncmp(status, "away", strlen("away"))) { status_kind = TOX_USERSTATUS_AWAY; - status_text = "AWAY"; + status_text = "Away"; } else if (!strncmp(status, "busy", strlen("busy"))) { status_kind = TOX_USERSTATUS_BUSY; - status_text = "BUSY"; + status_text = "Busy"; } else { diff --git a/src/friendlist.c b/src/friendlist.c index cb51cbb..6d48b0f 100644 --- a/src/friendlist.c +++ b/src/friendlist.c @@ -21,7 +21,7 @@ extern int store_data(Tox *m, char *path); typedef struct { uint8_t name[TOX_MAX_NAME_LENGTH]; - uint8_t status[TOX_MAX_STATUSMESSAGE_LENGTH]; + uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH]; int num; int chatwin; bool active; @@ -56,8 +56,8 @@ void friendlist_onStatusChange(ToxWindow *self, int num, uint8_t *str, uint16_t if (len >= TOX_MAX_STATUSMESSAGE_LENGTH || num >= num_friends) return; - memcpy((char *) &friends[num].status, (char *) str, len); - friends[num].status[len] = 0; + memcpy((char *) &friends[num].statusmsg, (char *) str, len); + friends[num].statusmsg[len] = 0; } int friendlist_onFriendAdded(Tox *m, int num) @@ -74,6 +74,7 @@ int friendlist_onFriendAdded(Tox *m, int num) friends[i].chatwin = -1; //tox_getname(m, num, friends[i].name); strcpy((char *) friends[i].name, "unknown"); + strcpy((char *) friends[i].statusmsg, NOSTATUSMSG); if (i == num_friends) ++num_friends; @@ -173,7 +174,6 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m) for (i = 0; i < num_friends; ++i) { if (friends[i].active) { bool is_online = tox_friendstatus(m, i) == TOX_FRIEND_ONLINE; - TOX_USERSTATUS status = tox_get_userstatus(m, i); if (i == num_selected) wprintw(self->window, " > "); @@ -181,6 +181,7 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m) wprintw(self->window, " "); if (is_online) { + TOX_USERSTATUS status = tox_get_userstatus(m, i); int colour; switch(status) { @@ -200,14 +201,13 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m) } wattron(self->window, COLOR_PAIR(colour)); - attron(A_BOLD); - wprintw(self->window, "%s \n", friends[i].name); - attroff(A_BOLD); + wprintw(self->window, "%s ", friends[i].name); wattroff(self->window, COLOR_PAIR(colour)); + + if (strncmp(friends[i].statusmsg, NOSTATUSMSG, strlen(NOSTATUSMSG))) + wprintw(self->window, "(%s)\n", friends[i].statusmsg); } else { - attron(A_BOLD); - wprintw(self->window, "%s \n", friends[i].name); - attroff(A_BOLD); + wprintw(self->window, "%s (Offline)\n", friends[i].name); } } } diff --git a/src/friendlist.h b/src/friendlist.h index 26c9106..6b21bac 100644 --- a/src/friendlist.h +++ b/src/friendlist.h @@ -4,6 +4,8 @@ #include "toxic_windows.h" #include "chat.h" +#define NOSTATUSMSG "NOSTATUSMSG" /* Friends' default status message */ + ToxWindow new_friendlist(); int friendlist_onFriendAdded(Tox *m, int num); void disable_chatwin(int f_num); From 713f2347bc4a464876aa233c0418d2b3298c1030 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Mon, 2 Sep 2013 01:14:51 -0400 Subject: [PATCH 3/5] add statusmsg command to chat windows --- src/chat.c | 10 +++++++++- src/prompt.c | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/chat.c b/src/chat.c index 75f68a3..db98c58 100644 --- a/src/chat.c +++ b/src/chat.c @@ -353,6 +353,13 @@ void execute(ToxWindow *self, ChatContext *ctx, Tox *m, char *cmd) } } + else if (!strncmp(cmd, "/statusmsg ", strlen("/statusmsg "))) { + char *msg = strchr(cmd, ' '); + msg++; + wprintw(ctx->history, "Status message set to: %s\n", msg); + tox_set_statusmessage(m, ( uint8_t *) msg, strlen(msg) + 1); + } + else if (!strncmp(cmd, "/nick ", strlen("/nick "))) { char *nick; nick = strchr(cmd, ' '); @@ -416,12 +423,13 @@ void print_help(ChatContext *self) wattroff(self->history, A_BOLD); wprintw(self->history, " /status : Set your status\n"); + wprintw(self->history, " /statusmsg : Set your status message\n"); wprintw(self->history, " /nick : Set your nickname\n"); wprintw(self->history, " /me : Do an action\n"); wprintw(self->history, " /myid : Print your ID\n"); wprintw(self->history, " /clear : Clear the screen\n"); wprintw(self->history, " /close : Close the current chat window\n"); - wprintw(self->history, " /quit or /exit : Exit program\n"); + wprintw(self->history, " /quit or /exit : Exit Toxic\n"); wprintw(self->history, " /help : Print this message again\n\n"); wattroff(self->history, COLOR_PAIR(2)); diff --git a/src/prompt.c b/src/prompt.c index 521f624..97dcd9b 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -228,7 +228,7 @@ void cmd_help(ToxWindow *self, Tox *m, char **args) wprintw(self->window, " mynick : Print your current nickname\n"); wprintw(self->window, " accept : Accept friend request\n"); wprintw(self->window, " myid : Print your ID\n"); - wprintw(self->window, " quit/exit : Exit program\n"); + wprintw(self->window, " quit/exit : Exit Toxic\n"); wprintw(self->window, " help : Print this message again\n"); wprintw(self->window, " clear : Clear this window\n"); From ed683504243313df432f97d2757f30eb61469056 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Mon, 2 Sep 2013 05:15:29 -0400 Subject: [PATCH 4/5] format fixes --- src/chat.c | 11 +++-------- src/friendlist.c | 9 +++++---- src/prompt.c | 8 ++++---- src/windows.c | 4 ++-- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/chat.c b/src/chat.c index db98c58..b885197 100644 --- a/src/chat.c +++ b/src/chat.c @@ -104,9 +104,7 @@ static void chat_onNickChange(ToxWindow *self, int num, uint8_t *nick, uint16_t nick[len - 1] = '\0'; snprintf(self->title, sizeof(self->title), "[%s (%d)]", nick, num); - wattron(ctx->history, COLOR_PAIR(3)); wprintw(ctx->history, "* Your partner changed nick to '%s'\n", nick); - wattroff(ctx->history, COLOR_PAIR(3)); } static void chat_onStatusChange(ToxWindow *self, int num, uint8_t *status, uint16_t len) @@ -123,10 +121,7 @@ static void chat_onStatusChange(ToxWindow *self, int num, uint8_t *status, uint1 status[len - 1] = '\0'; - wattron(ctx->history, COLOR_PAIR(3)); - wprintw(ctx->history, "* Your partner changed status to '%s'\n", status); - wattroff(ctx->history, COLOR_PAIR(3)); - + wprintw(ctx->history, "* Your partner changed status message to '%s'\n", status); } /* check that the string has one non-space character */ @@ -344,12 +339,12 @@ void execute(ToxWindow *self, ChatContext *ctx, Tox *m, char *cmd) if (msg == NULL) { tox_set_userstatus(m, status_kind); - wprintw(ctx->history, "Status set to: %s\n", status_text); + wprintw(ctx->history, "Status message set to: %s\n", status_text); } else { msg++; tox_set_userstatus(m, status_kind); tox_set_statusmessage(m, ( uint8_t *) msg, strlen(msg) + 1); - wprintw(ctx->history, "Status set to: %s, %s\n", status_text, msg); + wprintw(ctx->history, "Status message set to: %s, %s\n", status_text, msg); } } diff --git a/src/friendlist.c b/src/friendlist.c index 6d48b0f..817513d 100644 --- a/src/friendlist.c +++ b/src/friendlist.c @@ -173,7 +173,7 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m) for (i = 0; i < num_friends; ++i) { if (friends[i].active) { - bool is_online = tox_friendstatus(m, i) == TOX_FRIEND_ONLINE; + bool is_online = tox_friendstatus(m, friends[i].num) == TOX_FRIEND_ONLINE; if (i == num_selected) wprintw(self->window, " > "); @@ -181,8 +181,8 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m) wprintw(self->window, " "); if (is_online) { - TOX_USERSTATUS status = tox_get_userstatus(m, i); - int colour; + TOX_USERSTATUS status = tox_get_userstatus(m, friends[i].num); + int colour = 3; switch(status) { case TOX_USERSTATUS_NONE: @@ -206,8 +206,9 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m) if (strncmp(friends[i].statusmsg, NOSTATUSMSG, strlen(NOSTATUSMSG))) wprintw(self->window, "(%s)\n", friends[i].statusmsg); + } else { - wprintw(self->window, "%s (Offline)\n", friends[i].name); + wprintw(self->window, "(Offline)\n"); } } } diff --git a/src/prompt.c b/src/prompt.c index 97dcd9b..ef0b2d6 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -223,7 +223,7 @@ void cmd_help(ToxWindow *self, Tox *m, char **args) wprintw(self->window, " connect : Connect to DHT server\n"); wprintw(self->window, " add : Add friend\n"); wprintw(self->window, " status : Set your status\n"); - wprintw(self->window, " statusmsg : Set your status\n"); + wprintw(self->window, " statusmsg : Set your status message\n"); wprintw(self->window, " nick : Set your nickname\n"); wprintw(self->window, " mynick : Print your current nickname\n"); wprintw(self->window, " accept : Accept friend request\n"); @@ -310,11 +310,11 @@ void cmd_status(ToxWindow *self, Tox *m, char **args) if (msg == NULL) { tox_set_userstatus(m, status_kind); - wprintw(self->window, "Status set to: %s\n", status_text); + wprintw(self->window, "Status message set to: %s\n", status_text); } else { tox_set_userstatus(m, status_kind); tox_set_statusmessage(m, (uint8_t *) msg, strlen(msg) + 1); - wprintw(self->window, "Status set to: %s, %s\n", status_text, msg); + wprintw(self->window, "Status message set to: %s, %s\n", status_text, msg); } } @@ -322,7 +322,7 @@ void cmd_statusmsg(ToxWindow *self, Tox *m, char **args) { char *msg = args[1]; tox_set_statusmessage(m, (uint8_t *) msg, strlen(msg) + 1); - wprintw(self->window, "Status set to: %s\n", msg); + wprintw(self->window, "Status message set to: %s\n", msg); } static void execute(ToxWindow *self, Tox *m, char *u_cmd) diff --git a/src/windows.c b/src/windows.c index 83d60df..2ae9806 100644 --- a/src/windows.c +++ b/src/windows.c @@ -60,7 +60,7 @@ void on_action(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void void on_nickchange(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata) { - wprintw(prompt->window, "\n(nickchange) %d: %s\n", friendnumber, string); + wprintw(prompt->window, "\n(nick change) %d: %s\n", friendnumber, string); int i; for (i = 0; i < MAX_WINDOWS_NUM; ++i) { @@ -71,7 +71,7 @@ void on_nickchange(Tox *m, int friendnumber, uint8_t *string, uint16_t length, v void on_statuschange(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata) { - wprintw(prompt->window, "\n(statuschange) %d: %s\n", friendnumber, string); + wprintw(prompt->window, "\n(message change) %d: %s\n", friendnumber, string); int i; for (i = 0; i < MAX_WINDOWS_NUM; ++i) { From dbe84898b9d802ffec7c764de2bd7e0eeffab4a4 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Mon, 2 Sep 2013 05:16:54 -0400 Subject: [PATCH 5/5] oops oops oops --- src/friendlist.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/friendlist.c b/src/friendlist.c index 817513d..c4dd3cf 100644 --- a/src/friendlist.c +++ b/src/friendlist.c @@ -182,7 +182,7 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m) if (is_online) { TOX_USERSTATUS status = tox_get_userstatus(m, friends[i].num); - int colour = 3; + int colour; switch(status) { case TOX_USERSTATUS_NONE: @@ -208,7 +208,7 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m) wprintw(self->window, "(%s)\n", friends[i].statusmsg); } else { - wprintw(self->window, "(Offline)\n"); + wprintw(self->window, "%s (Offline)\n", friends[i].name); } } }