mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-26 15:53:26 +01:00
small optimization
This commit is contained in:
parent
d712d6c898
commit
33e16fe870
@ -296,7 +296,9 @@ static void chat_onFileData(ToxWindow *self, Tox *m, int num, uint8_t filenum, u
|
|||||||
wattron(ctx->history, COLOR_PAIR(RED));
|
wattron(ctx->history, COLOR_PAIR(RED));
|
||||||
wprintw(ctx->history, "* Error writing to file.\n");
|
wprintw(ctx->history, "* Error writing to file.\n");
|
||||||
wattroff(ctx->history, COLOR_PAIR(RED));
|
wattroff(ctx->history, COLOR_PAIR(RED));
|
||||||
|
|
||||||
tox_file_send_control(m, num, 1, filenum, TOX_FILECONTROL_KILL, 0, 0);
|
tox_file_send_control(m, num, 1, filenum, TOX_FILECONTROL_KILL, 0, 0);
|
||||||
|
chat_close_file_receiver(num, filenum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ void cmd_groupinvite(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*a
|
|||||||
|
|
||||||
void cmd_join_group(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
void cmd_join_group(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||||
{
|
{
|
||||||
if (num_active_windows() >= MAX_WINDOWS_NUM) {
|
if (get_num_active_windows() >= MAX_WINDOWS_NUM) {
|
||||||
wattron(window, COLOR_PAIR(RED));
|
wattron(window, COLOR_PAIR(RED));
|
||||||
wprintw(window, " * Warning: Too many windows are open.\n");
|
wprintw(window, " * Warning: Too many windows are open.\n");
|
||||||
wattron(window, COLOR_PAIR(RED));
|
wattron(window, COLOR_PAIR(RED));
|
||||||
|
@ -77,7 +77,7 @@ static void friendlist_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *str,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (friends[num].chatwin == -1) {
|
if (friends[num].chatwin == -1) {
|
||||||
if (num_active_windows() < MAX_WINDOWS_NUM) {
|
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
|
||||||
friends[num].chatwin = add_window(m, new_chat(m, friends[num].num));
|
friends[num].chatwin = add_window(m, new_chat(m, friends[num].num));
|
||||||
} else {
|
} else {
|
||||||
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||||
@ -178,7 +178,7 @@ static void friendlist_onFileSendRequest(ToxWindow *self, Tox *m, int num, uint8
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (friends[num].chatwin == -1) {
|
if (friends[num].chatwin == -1) {
|
||||||
if (num_active_windows() < MAX_WINDOWS_NUM) {
|
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
|
||||||
friends[num].chatwin = add_window(m, new_chat(m, friends[num].num));
|
friends[num].chatwin = add_window(m, new_chat(m, friends[num].num));
|
||||||
} else {
|
} else {
|
||||||
tox_file_send_control(m, num, 1, filenum, TOX_FILECONTROL_KILL, 0, 0);
|
tox_file_send_control(m, num, 1, filenum, TOX_FILECONTROL_KILL, 0, 0);
|
||||||
@ -203,7 +203,7 @@ static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int num, uint8_t *
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (friends[num].chatwin == -1) {
|
if (friends[num].chatwin == -1) {
|
||||||
if (num_active_windows() < MAX_WINDOWS_NUM) {
|
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
|
||||||
friends[num].chatwin = add_window(m, new_chat(m, friends[num].num));
|
friends[num].chatwin = add_window(m, new_chat(m, friends[num].num));
|
||||||
} else {
|
} else {
|
||||||
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||||
@ -264,7 +264,7 @@ static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key)
|
|||||||
/* Jump to chat window if already open */
|
/* Jump to chat window if already open */
|
||||||
if (friends[f].chatwin != -1) {
|
if (friends[f].chatwin != -1) {
|
||||||
set_active_window(friends[f].chatwin);
|
set_active_window(friends[f].chatwin);
|
||||||
} else if (num_active_windows() < MAX_WINDOWS_NUM) {
|
} else if (get_num_active_windows() < MAX_WINDOWS_NUM) {
|
||||||
friends[f].chatwin = add_window(m, new_chat(m, friends[f].num));
|
friends[f].chatwin = add_window(m, new_chat(m, friends[f].num));
|
||||||
set_active_window(friends[f].chatwin);
|
set_active_window(friends[f].chatwin);
|
||||||
} else {
|
} else {
|
||||||
|
@ -197,7 +197,7 @@ void cmd_connect(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)
|
|||||||
|
|
||||||
void cmd_groupchat(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
void cmd_groupchat(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||||
{
|
{
|
||||||
if (num_active_windows() >= MAX_WINDOWS_NUM) {
|
if (get_num_active_windows() >= MAX_WINDOWS_NUM) {
|
||||||
wattron(window, COLOR_PAIR(RED));
|
wattron(window, COLOR_PAIR(RED));
|
||||||
wprintw(window, " * Warning: Too many windows are open.\n");
|
wprintw(window, " * Warning: Too many windows are open.\n");
|
||||||
wattron(window, COLOR_PAIR(RED));
|
wattron(window, COLOR_PAIR(RED));
|
||||||
|
@ -234,7 +234,7 @@ void draw_active_window(Tox *m);
|
|||||||
int add_window(Tox *m, ToxWindow w);
|
int add_window(Tox *m, ToxWindow w);
|
||||||
void del_window(ToxWindow *w);
|
void del_window(ToxWindow *w);
|
||||||
void set_active_window(int ch);
|
void set_active_window(int ch);
|
||||||
int num_active_windows(void);
|
int get_num_active_windows(void);
|
||||||
|
|
||||||
/* cleans up all chat and groupchat windows (should only be called on shutdown) */
|
/* cleans up all chat and groupchat windows (should only be called on shutdown) */
|
||||||
void kill_all_windows(void);
|
void kill_all_windows(void);
|
||||||
|
@ -39,12 +39,14 @@ static ToxWindow *active_window;
|
|||||||
|
|
||||||
extern ToxWindow *prompt;
|
extern ToxWindow *prompt;
|
||||||
|
|
||||||
|
static int num_active_windows;
|
||||||
|
|
||||||
/* CALLBACKS START */
|
/* CALLBACKS START */
|
||||||
void on_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata)
|
void on_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
for (i = 0; i < num_active_windows; ++i) {
|
||||||
if (windows[i].onFriendRequest != NULL)
|
if (windows[i].onFriendRequest != NULL)
|
||||||
windows[i].onFriendRequest(&windows[i], public_key, data, length);
|
windows[i].onFriendRequest(&windows[i], public_key, data, length);
|
||||||
}
|
}
|
||||||
@ -54,7 +56,7 @@ void on_connectionchange(Tox *m, int friendnumber, uint8_t status, void *userdat
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
for (i = 0; i < num_active_windows; ++i) {
|
||||||
if (windows[i].onConnectionChange != NULL)
|
if (windows[i].onConnectionChange != NULL)
|
||||||
windows[i].onConnectionChange(&windows[i], m, friendnumber, status);
|
windows[i].onConnectionChange(&windows[i], m, friendnumber, status);
|
||||||
}
|
}
|
||||||
@ -64,7 +66,7 @@ void on_typing_change(Tox *m, int friendnumber, int is_typing, void *userdata)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
for (i = 0; i < num_active_windows; ++i) {
|
||||||
if (windows[i].onTypingChange != NULL)
|
if (windows[i].onTypingChange != NULL)
|
||||||
windows[i].onTypingChange(&windows[i], m, friendnumber, is_typing);
|
windows[i].onTypingChange(&windows[i], m, friendnumber, is_typing);
|
||||||
}
|
}
|
||||||
@ -74,7 +76,7 @@ void on_message(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
for (i = 0; i < num_active_windows; ++i) {
|
||||||
if (windows[i].onMessage != NULL)
|
if (windows[i].onMessage != NULL)
|
||||||
windows[i].onMessage(&windows[i], m, friendnumber, string, length);
|
windows[i].onMessage(&windows[i], m, friendnumber, string, length);
|
||||||
}
|
}
|
||||||
@ -84,7 +86,7 @@ void on_action(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
for (i = 0; i < num_active_windows; ++i) {
|
||||||
if (windows[i].onAction != NULL)
|
if (windows[i].onAction != NULL)
|
||||||
windows[i].onAction(&windows[i], m, friendnumber, string, length);
|
windows[i].onAction(&windows[i], m, friendnumber, string, length);
|
||||||
}
|
}
|
||||||
@ -97,7 +99,7 @@ void on_nickchange(Tox *m, int friendnumber, uint8_t *string, uint16_t length, v
|
|||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
for (i = 0; i < num_active_windows; ++i) {
|
||||||
if (windows[i].onNickChange != NULL)
|
if (windows[i].onNickChange != NULL)
|
||||||
windows[i].onNickChange(&windows[i], m, friendnumber, string, length);
|
windows[i].onNickChange(&windows[i], m, friendnumber, string, length);
|
||||||
}
|
}
|
||||||
@ -110,7 +112,7 @@ void on_statusmessagechange(Tox *m, int friendnumber, uint8_t *string, uint16_t
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
for (i = 0; i < num_active_windows; ++i) {
|
||||||
if (windows[i].onStatusMessageChange != NULL)
|
if (windows[i].onStatusMessageChange != NULL)
|
||||||
windows[i].onStatusMessageChange(&windows[i], friendnumber, string, length);
|
windows[i].onStatusMessageChange(&windows[i], friendnumber, string, length);
|
||||||
}
|
}
|
||||||
@ -120,7 +122,7 @@ void on_statuschange(Tox *m, int friendnumber, TOX_USERSTATUS status, void *user
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
for (i = 0; i < num_active_windows; ++i) {
|
||||||
if (windows[i].onStatusChange != NULL)
|
if (windows[i].onStatusChange != NULL)
|
||||||
windows[i].onStatusChange(&windows[i], m, friendnumber, status);
|
windows[i].onStatusChange(&windows[i], m, friendnumber, status);
|
||||||
}
|
}
|
||||||
@ -130,7 +132,7 @@ void on_friendadded(Tox *m, int friendnumber, bool sort)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
for (i = 0; i < num_active_windows; ++i) {
|
||||||
if (windows[i].onFriendAdded != NULL)
|
if (windows[i].onFriendAdded != NULL)
|
||||||
windows[i].onFriendAdded(&windows[i], m, friendnumber, sort);
|
windows[i].onFriendAdded(&windows[i], m, friendnumber, sort);
|
||||||
}
|
}
|
||||||
@ -144,7 +146,7 @@ void on_groupmessage(Tox *m, int groupnumber, int peernumber, uint8_t *message,
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
for (i = 0; i < num_active_windows; ++i) {
|
||||||
if (windows[i].onGroupMessage != NULL)
|
if (windows[i].onGroupMessage != NULL)
|
||||||
windows[i].onGroupMessage(&windows[i], m, groupnumber, peernumber, message, length);
|
windows[i].onGroupMessage(&windows[i], m, groupnumber, peernumber, message, length);
|
||||||
}
|
}
|
||||||
@ -155,7 +157,7 @@ void on_groupaction(Tox *m, int groupnumber, int peernumber, uint8_t *action, ui
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
for (i = 0; i < num_active_windows; ++i) {
|
||||||
if (windows[i].onGroupAction != NULL)
|
if (windows[i].onGroupAction != NULL)
|
||||||
windows[i].onGroupAction(&windows[i], m, groupnumber, peernumber, action, length);
|
windows[i].onGroupAction(&windows[i], m, groupnumber, peernumber, action, length);
|
||||||
}
|
}
|
||||||
@ -165,7 +167,7 @@ void on_groupinvite(Tox *m, int friendnumber, uint8_t *group_pub_key, void *user
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
for (i = 0; i < num_active_windows; ++i) {
|
||||||
if (windows[i].onGroupInvite != NULL)
|
if (windows[i].onGroupInvite != NULL)
|
||||||
windows[i].onGroupInvite(&windows[i], m, friendnumber, group_pub_key);
|
windows[i].onGroupInvite(&windows[i], m, friendnumber, group_pub_key);
|
||||||
}
|
}
|
||||||
@ -175,7 +177,7 @@ void on_group_namelistchange(Tox *m, int groupnumber, int peernumber, uint8_t ch
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
for (i = 0; i < num_active_windows; ++i) {
|
||||||
if (windows[i].onGroupNamelistChange != NULL)
|
if (windows[i].onGroupNamelistChange != NULL)
|
||||||
windows[i].onGroupNamelistChange(&windows[i], m, groupnumber, peernumber, change);
|
windows[i].onGroupNamelistChange(&windows[i], m, groupnumber, peernumber, change);
|
||||||
}
|
}
|
||||||
@ -186,7 +188,7 @@ void on_file_sendrequest(Tox *m, int friendnumber, uint8_t filenumber, uint64_t
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
for (i = 0; i < num_active_windows; ++i) {
|
||||||
if (windows[i].onFileSendRequest != NULL)
|
if (windows[i].onFileSendRequest != NULL)
|
||||||
windows[i].onFileSendRequest(&windows[i], m, friendnumber, filenumber, filesize,
|
windows[i].onFileSendRequest(&windows[i], m, friendnumber, filenumber, filesize,
|
||||||
filename, filename_length);
|
filename, filename_length);
|
||||||
@ -198,7 +200,7 @@ void on_file_control (Tox *m, int friendnumber, uint8_t receive_send, uint8_t fi
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
for (i = 0; i < num_active_windows; ++i) {
|
||||||
if (windows[i].onFileControl != NULL)
|
if (windows[i].onFileControl != NULL)
|
||||||
windows[i].onFileControl(&windows[i], m, friendnumber, receive_send, filenumber,
|
windows[i].onFileControl(&windows[i], m, friendnumber, receive_send, filenumber,
|
||||||
control_type, data, length);
|
control_type, data, length);
|
||||||
@ -210,7 +212,7 @@ void on_file_data(Tox *m, int friendnumber, uint8_t filenumber, uint8_t *data, u
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
for (i = 0; i < num_active_windows; ++i) {
|
||||||
if (windows[i].onFileData != NULL)
|
if (windows[i].onFileData != NULL)
|
||||||
windows[i].onFileData(&windows[i], m, friendnumber, filenumber, data, length);
|
windows[i].onFileData(&windows[i], m, friendnumber, filenumber, data, length);
|
||||||
}
|
}
|
||||||
@ -240,6 +242,8 @@ int add_window(Tox *m, ToxWindow w)
|
|||||||
windows[i] = w;
|
windows[i] = w;
|
||||||
w.onInit(&w, m);
|
w.onInit(&w, m);
|
||||||
|
|
||||||
|
++num_active_windows;
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,6 +260,7 @@ void del_window(ToxWindow *w)
|
|||||||
|
|
||||||
clear();
|
clear();
|
||||||
refresh();
|
refresh();
|
||||||
|
--num_active_windows;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Shows next window when tab or back-tab is pressed */
|
/* Shows next window when tab or back-tab is pressed */
|
||||||
@ -398,17 +403,9 @@ void draw_active_window(Tox *m)
|
|||||||
a->onKey(a, m, ch);
|
a->onKey(a, m, ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
int num_active_windows(void)
|
int get_num_active_windows(void)
|
||||||
{
|
{
|
||||||
int count = 0;
|
return num_active_windows;
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
|
||||||
if (windows[i].active)
|
|
||||||
++count;
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* destroys all chat and groupchat windows (should only be called on shutdown) */
|
/* destroys all chat and groupchat windows (should only be called on shutdown) */
|
||||||
|
Loading…
Reference in New Issue
Block a user