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

Merge remote-tracking branch 'upstream/master'

This commit is contained in:
mannol 2014-03-11 00:58:18 +01:00
commit a80da2b58f
9 changed files with 100 additions and 41 deletions

View File

@ -314,7 +314,9 @@ static void chat_onFileData(ToxWindow *self, Tox *m, int num, uint8_t filenum, u
wattron(ctx->history, COLOR_PAIR(RED));
wprintw(ctx->history, "* Error writing to file.\n");
wattroff(ctx->history, COLOR_PAIR(RED));
tox_file_send_control(m, num, 1, filenum, TOX_FILECONTROL_KILL, 0, 0);
chat_close_file_receiver(num, filenum);
}
}

View File

@ -99,7 +99,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])
{
if (num_active_windows() >= MAX_WINDOWS_NUM) {
if (get_num_active_windows() >= MAX_WINDOWS_NUM) {
wattron(window, COLOR_PAIR(RED));
wprintw(window, " * Warning: Too many windows are open.\n");
wattron(window, COLOR_PAIR(RED));

View File

@ -45,6 +45,8 @@ static int num_friends = 0;
ToxicFriend friends[MAX_FRIENDS_NUM];
static int friendlist_index[MAX_FRIENDS_NUM] = {0};
static PendingDel pendingdelete;
#define S_WEIGHT 100
static int index_name_cmp(const void *n1, const void *n2)
@ -78,7 +80,7 @@ static void friendlist_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *str,
return;
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));
} else {
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
@ -179,7 +181,7 @@ static void friendlist_onFileSendRequest(ToxWindow *self, Tox *m, int num, uint8
return;
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));
} else {
tox_file_send_control(m, num, 1, filenum, TOX_FILECONTROL_KILL, 0, 0);
@ -204,7 +206,7 @@ static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int num, uint8_t *
return;
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));
} else {
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
@ -231,7 +233,7 @@ static void select_friend(ToxWindow *self, Tox *m, wint_t key)
}
}
static void delete_friend(Tox *m, ToxWindow *self, int f_num, wint_t key)
static void delete_friend(Tox *m, int f_num)
{
tox_del_friend(m, f_num);
memset(&friends[f_num], 0, sizeof(ToxicFriend));
@ -254,6 +256,49 @@ static void delete_friend(Tox *m, ToxWindow *self, int f_num, wint_t key)
store_data(m, DATA_FILE);
}
/* activates delete friend popup */
static void del_friend_activate(ToxWindow *self, Tox *m, int f_num)
{
int x2, y2;
getmaxyx(self->window, y2, x2);
self->popup = newwin(3, 22 + TOXIC_MAX_NAME_LENGTH, 8, 8);
pendingdelete.active = true;
pendingdelete.num = f_num;
}
/* deactivates delete friend popup and deletes friend if instructed */
static void del_friend_deactivate(ToxWindow *self, Tox *m, wint_t key)
{
if (key == 'y')
delete_friend(m, pendingdelete.num);
memset(&pendingdelete, 0, sizeof(PendingDel));
delwin(self->popup);
self->popup = NULL;
clear();
refresh();
}
static void draw_popup(ToxWindow *self, Tox *m)
{
if (self->popup == NULL)
return;
wattron(self->popup, A_BOLD);
box(self->popup, ACS_VLINE, ACS_HLINE);
wattroff(self->popup, A_BOLD);
wmove(self->popup, 1, 1);
wprintw(self->popup, "Delete contact ");
wattron(self->popup, A_BOLD);
wprintw(self->popup, "%s", friends[pendingdelete.num].name);
wattroff(self->popup, A_BOLD);
wprintw(self->popup, "? y/n");
wrefresh(self->popup);
}
static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key)
{
if (num_friends == 0)
@ -261,11 +306,19 @@ static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key)
int f = friendlist_index[num_selected];
/* lock screen and force decision on deletion popup */
if (pendingdelete.active) {
if (key == 'y' || key == 'n')
del_friend_deactivate(self, m, key);
return;
}
if (key == '\n') {
/* Jump to chat window if already open */
if (friends[f].chatwin != -1) {
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));
set_active_window(friends[f].chatwin);
} else {
@ -277,7 +330,7 @@ static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key)
alert_window(prompt, WINDOW_ALERT_1, true);
}
} else if (key == KEY_DC) {
delete_friend(m, self, f, key);
del_friend_activate(self, m, f);
} else {
select_friend(self, m, key);
}
@ -307,7 +360,7 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
wattroff(self->window, COLOR_PAIR(CYAN));
wattron(self->window, A_BOLD);
wprintw(self->window, " Friends: %d/%d \n\n", tox_get_num_online_friends(m), num_friends);
wprintw(self->window, " Online: %d/%d \n\n", tox_get_num_online_friends(m), num_friends);
wattroff(self->window, A_BOLD);
if ((y2 - FLIST_OFST) <= 0) /* don't allow division by zero */
@ -402,6 +455,7 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
self->x = x2;
wrefresh(self->window);
draw_popup(self, m);
}
void disable_chatwin(int f_num)

View File

@ -42,6 +42,11 @@ typedef struct {
struct FileReceiver file_receiver;
} ToxicFriend;
typedef struct {
int num;
bool active;
} PendingDel;
ToxWindow new_friendlist(void);
void disable_chatwin(int f_num);
int get_friendnum(uint8_t *name);

View File

@ -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])
{
if (num_active_windows() >= MAX_WINDOWS_NUM) {
if (get_num_active_windows() >= MAX_WINDOWS_NUM) {
wattron(window, COLOR_PAIR(RED));
wprintw(window, " * Warning: Too many windows are open.\n");
wattron(window, COLOR_PAIR(RED));

View File

@ -74,8 +74,8 @@ void print_time(WINDOW *window)
wattroff(window,COLOR_PAIR(BLUE));
}
/* Returns true if the string is empty, false otherwise */
bool string_is_empty(char *string)
/* Returns 1 if the string is empty, 0 otherwise */
int string_is_empty(char *string)
{
return string[0] == '\0';
}
@ -109,7 +109,7 @@ int wcs_to_mbs_buf(uint8_t *buf, const wchar_t *string, size_t n)
return len;
}
/* convert wide characters to multibyte string: string returned must be free'd */
/* convert wide characters to multibyte string: string returned must be freed */
uint8_t *wcs_to_mbs(wchar_t *string)
{
uint8_t *ret = NULL;

View File

@ -32,8 +32,8 @@ struct tm *get_time(void);
/* Prints the time to given window */
void print_time(WINDOW *window);
/* Returns true if the string is empty, false otherwise */
bool string_is_empty(char *string);
/* Returns 1 if the string is empty, 0 otherwise */
int string_is_empty(char *string);
/* convert a multibyte string to a wide character string (must provide buffer) */
int char_to_wcs_buf(wchar_t *buf, const uint8_t *string, size_t n);

View File

@ -143,6 +143,7 @@ struct ToxWindow {
PromptBuf *promptbuf;
StatusBar *stb;
WINDOW *popup;
WINDOW *window;
};
@ -253,7 +254,7 @@ void draw_active_window(Tox *m);
int add_window(Tox *m, ToxWindow w);
void del_window(ToxWindow *w);
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) */
void kill_all_windows(void);

View File

@ -39,12 +39,14 @@ static ToxWindow *active_window;
extern ToxWindow *prompt;
static int num_active_windows;
/* CALLBACKS START */
void on_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata)
{
int i;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
for (i = 0; i < num_active_windows; ++i) {
if (windows[i].onFriendRequest != NULL)
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;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
for (i = 0; i < num_active_windows; ++i) {
if (windows[i].onConnectionChange != NULL)
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;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
for (i = 0; i < num_active_windows; ++i) {
if (windows[i].onTypingChange != NULL)
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;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
for (i = 0; i < num_active_windows; ++i) {
if (windows[i].onMessage != NULL)
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;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
for (i = 0; i < num_active_windows; ++i) {
if (windows[i].onAction != NULL)
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;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
for (i = 0; i < num_active_windows; ++i) {
if (windows[i].onNickChange != NULL)
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;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
for (i = 0; i < num_active_windows; ++i) {
if (windows[i].onStatusMessageChange != NULL)
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;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
for (i = 0; i < num_active_windows; ++i) {
if (windows[i].onStatusChange != NULL)
windows[i].onStatusChange(&windows[i], m, friendnumber, status);
}
@ -130,7 +132,7 @@ void on_friendadded(Tox *m, int friendnumber, bool sort)
{
int i;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
for (i = 0; i < num_active_windows; ++i) {
if (windows[i].onFriendAdded != NULL)
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;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
for (i = 0; i < num_active_windows; ++i) {
if (windows[i].onGroupMessage != NULL)
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;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
for (i = 0; i < num_active_windows; ++i) {
if (windows[i].onGroupAction != NULL)
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;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
for (i = 0; i < num_active_windows; ++i) {
if (windows[i].onGroupInvite != NULL)
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;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
for (i = 0; i < num_active_windows; ++i) {
if (windows[i].onGroupNamelistChange != NULL)
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;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
for (i = 0; i < num_active_windows; ++i) {
if (windows[i].onFileSendRequest != NULL)
windows[i].onFileSendRequest(&windows[i], m, friendnumber, filenumber, filesize,
filename, filename_length);
@ -198,7 +200,7 @@ void on_file_control (Tox *m, int friendnumber, uint8_t receive_send, uint8_t fi
{
int i;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
for (i = 0; i < num_active_windows; ++i) {
if (windows[i].onFileControl != NULL)
windows[i].onFileControl(&windows[i], m, friendnumber, receive_send, filenumber,
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;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
for (i = 0; i < num_active_windows; ++i) {
if (windows[i].onFileData != NULL)
windows[i].onFileData(&windows[i], m, friendnumber, filenumber, data, length);
}
@ -240,6 +242,8 @@ int add_window(Tox *m, ToxWindow w)
windows[i] = w;
w.onInit(&w, m);
++num_active_windows;
return i;
}
@ -256,6 +260,7 @@ void del_window(ToxWindow *w)
clear();
refresh();
--num_active_windows;
}
/* 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);
}
int num_active_windows(void)
int get_num_active_windows(void)
{
int count = 0;
int i;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].active)
++count;
}
return count;
return num_active_windows;
}
/* destroys all chat and groupchat windows (should only be called on shutdown) */