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

made prompt window beep/blink on friend request

This commit is contained in:
Jfreegman 2013-09-06 02:51:10 -04:00
parent ba7d01d3c1
commit 9c7cad0d55
5 changed files with 35 additions and 21 deletions

View File

@ -30,14 +30,6 @@ typedef struct {
WINDOW *linewin;
} ChatContext;
typedef struct {
WINDOW *topline;
uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH];
TOX_USERSTATUS status;
bool is_online;
int max_len; /* set equal to the window's max x coordinate */
} StatusBar;
void print_help(ChatContext *self);
void execute(ToxWindow *self, ChatContext *ctx, Tox *m, char *cmd);

View File

@ -76,8 +76,9 @@ void friendlist_onStatusMessageChange(ToxWindow *self, int num, uint8_t *str, ui
if (len >= TOX_MAX_STATUSMESSAGE_LENGTH || num < 0 || num >= num_friends)
return;
memcpy((char *) &friends[num].statusmsg, (char *) str, len);
friends[num].statusmsg[len] = 0;
/* Ignore default "Online" status message */
if (strncmp(str, "Online", strlen(str)))
memcpy((char *) &friends[num].statusmsg, (char *) str, len);
}
int friendlist_onFriendAdded(Tox *m, int num)

View File

@ -57,6 +57,24 @@ static struct {
{ "note", cmd_note },
};
void prompt_onFriendRequest(ToxWindow *self, uint8_t *key, uint8_t *data, uint16_t length)
{
int n = add_req(key);
wprintw(self->window, "\nFriend request from:\n");
int i;
for (i = 0; i < KEY_SIZE_BYTES; ++i) {
wprintw(self->window, "%02x", key[i] & 0xff);
}
wprintw(self->window, "\n\nWith the message: %s\n\n", data);
wprintw(self->window, "Type \"accept %d\" to accept it.\n", n);
self->blink = true;
beep();
}
// XXX:
int add_req(uint8_t *public_key)
{
@ -565,6 +583,7 @@ ToxWindow new_prompt()
ret.onKey = &prompt_onKey;
ret.onDraw = &prompt_onDraw;
ret.onInit = &prompt_onInit;
ret.onFriendRequest = &prompt_onFriendRequest;
strcpy(ret.name, "prompt");
return ret;
}

View File

@ -59,6 +59,14 @@ struct ToxWindow_ {
WINDOW *window;
};
typedef struct {
WINDOW *topline;
uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH];
TOX_USERSTATUS status;
bool is_online;
int max_len; /* set to the window's max x coordinate */
} StatusBar;
void on_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata);
void on_connectionchange(Tox *m, int friendnumber, uint8_t status, void *userdata);
void on_message(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata);

View File

@ -22,18 +22,8 @@ static Tox *m;
/* CALLBACKS START */
void on_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata)
{
int n = add_req(public_key);
wprintw(prompt->window, "\nFriend request from:\n");
int i;
for (i = 0; i < KEY_SIZE_BYTES; ++i) {
wprintw(prompt->window, "%02x", public_key[i] & 0xff);
}
wprintw(prompt->window, "\nWith the message: %s\n", data);
wprintw(prompt->window, "Type \"accept %d\" to accept it.\n", n);
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].onFriendRequest != NULL)
windows[i].onFriendRequest(&windows[i], public_key, data, length);
@ -49,15 +39,19 @@ void on_connectionchange(Tox *m, int friendnumber, uint8_t status, void *userdat
snprintf(nick, sizeof(nick), "%s", UNKNOWN_NAME);
if (status == 1) {
wattron(prompt->window, COLOR_PAIR(GREEN));
wattron(prompt->window, A_BOLD);
wprintw(prompt->window, "\n%s ", nick);
wattroff(prompt->window, A_BOLD);
wprintw(prompt->window, "has come online\n");
wattroff(prompt->window, COLOR_PAIR(GREEN));
} else {
wattron(prompt->window, COLOR_PAIR(RED));
wattron(prompt->window, A_BOLD);
wprintw(prompt->window, "\n%s ", nick);
wattroff(prompt->window, A_BOLD);
wprintw(prompt->window, "has gone offline\n");
wattroff(prompt->window, COLOR_PAIR(RED));
}
int i;