summaryrefslogtreecommitdiff
path: root/testing/toxic/friendlist.c
diff options
context:
space:
mode:
Diffstat (limited to 'testing/toxic/friendlist.c')
-rw-r--r--testing/toxic/friendlist.c40
1 files changed, 27 insertions, 13 deletions
diff --git a/testing/toxic/friendlist.c b/testing/toxic/friendlist.c
index b4b619a2..2d060ae0 100644
--- a/testing/toxic/friendlist.c
+++ b/testing/toxic/friendlist.c
@@ -12,12 +12,11 @@
12 12
13#include "windows.h" 13#include "windows.h"
14 14
15extern char WINDOW_STATUS[TOXWINDOWS_MAX_NUM];
15extern int add_window(ToxWindow w); 16extern int add_window(ToxWindow w);
16extern int focus_window(int num); 17extern int focus_window(int num);
17extern ToxWindow new_chat(int friendnum); 18extern ToxWindow new_chat(int friendnum);
18 19
19#define MAX_FRIENDS_NUM 100
20
21typedef struct { 20typedef struct {
22 uint8_t name[MAX_NAME_LENGTH]; 21 uint8_t name[MAX_NAME_LENGTH];
23 uint8_t status[MAX_USERSTATUS_LENGTH]; 22 uint8_t status[MAX_USERSTATUS_LENGTH];
@@ -86,14 +85,11 @@ int friendlist_onFriendAdded(int num) {
86 getname(num, friends[num_friends].name); 85 getname(num, friends[num_friends].name);
87 strcpy((char*) friends[num_friends].name, "unknown"); 86 strcpy((char*) friends[num_friends].name, "unknown");
88 strcpy((char*) friends[num_friends].status, "unknown"); 87 strcpy((char*) friends[num_friends].status, "unknown");
89 friends[num_friends].chatwin = -1; 88 friends[num_friends++].chatwin = -1;
90
91 num_friends++;
92 return 0; 89 return 0;
93} 90}
94 91
95static void friendlist_onKey(ToxWindow* self, int key) { 92static void friendlist_onKey(ToxWindow* self, int key) {
96
97 if(key == KEY_UP) { 93 if(key == KEY_UP) {
98 if(num_selected != 0) 94 if(num_selected != 0)
99 num_selected--; 95 num_selected--;
@@ -103,12 +99,26 @@ static void friendlist_onKey(ToxWindow* self, int key) {
103 num_selected = (num_selected+1) % num_friends; 99 num_selected = (num_selected+1) % num_friends;
104 } 100 }
105 else if(key == '\n') { 101 else if(key == '\n') {
106 102 /* Jump to chat window if already open */
107 if(friends[num_selected].chatwin != -1) 103 if (friends[num_selected].chatwin != -1) {
108 return; 104 int i;
109 105 for (i = N_DEFAULT_WINS; i < MAX_WINDOW_SLOTS; i++) {
110 friends[num_selected].chatwin = add_window(new_chat(num_selected)); 106 if (WINDOW_STATUS[i] == num_selected) {
111 focus_window(friends[num_selected].chatwin); 107 focus_window(i);
108 break;
109 }
110 }
111 }else {
112 friends[num_selected].chatwin = add_window(new_chat(num_selected));
113 focus_window(friends[num_selected].chatwin);
114 int i;
115 for (i = N_DEFAULT_WINS; i < MAX_WINDOW_SLOTS; i++) { // Find open slot
116 if (WINDOW_STATUS[i] == -1) {
117 WINDOW_STATUS[i] = num_selected;
118 break;
119 }
120 }
121 }
112 } 122 }
113} 123}
114 124
@@ -145,6 +155,10 @@ static void friendlist_onDraw(ToxWindow* self) {
145 wrefresh(self->window); 155 wrefresh(self->window);
146} 156}
147 157
158void disable_chatwin(int f_num) {
159 friends[f_num].chatwin = -1;
160}
161
148static void friendlist_onInit(ToxWindow* self) { 162static void friendlist_onInit(ToxWindow* self) {
149 163
150} 164}
@@ -164,4 +178,4 @@ ToxWindow new_friendlist() {
164 strcpy(ret.title, "[friends]"); 178 strcpy(ret.title, "[friends]");
165 179
166 return ret; 180 return ret;
167} 181} \ No newline at end of file