diff options
Diffstat (limited to 'testing/toxic')
-rw-r--r-- | testing/toxic/chat.c | 6 | ||||
-rw-r--r-- | testing/toxic/configdir.c | 14 | ||||
-rw-r--r-- | testing/toxic/configdir.h | 4 | ||||
-rw-r--r-- | testing/toxic/friendlist.c | 36 | ||||
-rw-r--r-- | testing/toxic/friendlist.h | 2 | ||||
-rw-r--r-- | testing/toxic/main.c | 23 | ||||
-rw-r--r-- | testing/toxic/prompt.c | 9 | ||||
-rw-r--r-- | testing/toxic/prompt.h | 4 | ||||
-rw-r--r-- | testing/toxic/windows.c | 172 | ||||
-rw-r--r-- | testing/toxic/windows.h | 10 |
10 files changed, 111 insertions, 169 deletions
diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index ef932cd2..57404a59 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c | |||
@@ -123,8 +123,7 @@ static void chat_onStatusChange(ToxWindow *self, int num, uint8_t *status, uint1 | |||
123 | 123 | ||
124 | status[len - 1] = '\0'; | 124 | status[len - 1] = '\0'; |
125 | fix_name(status); | 125 | fix_name(status); |
126 | snprintf(self->title, sizeof(self->title), "[%s (%d)]", status, num); | 126 | |
127 | |||
128 | wattron(ctx->history, COLOR_PAIR(3)); | 127 | wattron(ctx->history, COLOR_PAIR(3)); |
129 | wprintw(ctx->history, "* Your partner changed status to '%s'\n", status); | 128 | wprintw(ctx->history, "* Your partner changed status to '%s'\n", status); |
130 | wattroff(ctx->history, COLOR_PAIR(3)); | 129 | wattroff(ctx->history, COLOR_PAIR(3)); |
@@ -335,7 +334,8 @@ void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd) | |||
335 | else if (strcmp(ctx->line, "/close") == 0) { | 334 | else if (strcmp(ctx->line, "/close") == 0) { |
336 | int f_num = ctx->friendnum; | 335 | int f_num = ctx->friendnum; |
337 | delwin(ctx->linewin); | 336 | delwin(ctx->linewin); |
338 | del_window(self, f_num); | 337 | del_window(self); |
338 | disable_chatwin(f_num); | ||
339 | } | 339 | } |
340 | 340 | ||
341 | else | 341 | else |
diff --git a/testing/toxic/configdir.c b/testing/toxic/configdir.c index 1a62e8ed..a43dd1de 100644 --- a/testing/toxic/configdir.c +++ b/testing/toxic/configdir.c | |||
@@ -98,14 +98,18 @@ char *get_user_config_dir(void) | |||
98 | 98 | ||
99 | snprintf(user_config_dir, len, "%s/Library/Application Support", home); | 99 | snprintf(user_config_dir, len, "%s/Library/Application Support", home); |
100 | # else /* __APPLE__ */ | 100 | # else /* __APPLE__ */ |
101 | len = strlen(home) + strlen("/.config") + 1; | ||
102 | user_config_dir = malloc(len); | ||
103 | 101 | ||
104 | if (user_config_dir == NULL) { | 102 | if (!(user_config_dir = getenv("XDG_CONFIG_HOME"))) { |
105 | return NULL; | 103 | len = strlen(home) + strlen("/.config") + 1; |
104 | user_config_dir = malloc(len); | ||
105 | |||
106 | if (user_config_dir == NULL) { | ||
107 | return NULL; | ||
108 | } | ||
109 | |||
110 | snprintf(user_config_dir, len, "%s/.config", home); | ||
106 | } | 111 | } |
107 | 112 | ||
108 | snprintf(user_config_dir, len, "%s/.config", home); | ||
109 | # endif /* __APPLE__ */ | 113 | # endif /* __APPLE__ */ |
110 | 114 | ||
111 | return user_config_dir; | 115 | return user_config_dir; |
diff --git a/testing/toxic/configdir.h b/testing/toxic/configdir.h index 17d95107..e886e53a 100644 --- a/testing/toxic/configdir.h +++ b/testing/toxic/configdir.h | |||
@@ -19,9 +19,9 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | #ifdef _win32 | 21 | #ifdef _win32 |
22 | #define CONFIGDIR "\\toxic\\" | 22 | #define CONFIGDIR "\\tox\\" |
23 | #else | 23 | #else |
24 | #define CONFIGDIR "/toxic/" | 24 | #define CONFIGDIR "/tox/" |
25 | #endif | 25 | #endif |
26 | 26 | ||
27 | #ifndef S_ISDIR | 27 | #ifndef S_ISDIR |
diff --git a/testing/toxic/friendlist.c b/testing/toxic/friendlist.c index c85fd3ae..0a58bc54 100644 --- a/testing/toxic/friendlist.c +++ b/testing/toxic/friendlist.c | |||
@@ -13,7 +13,6 @@ | |||
13 | #include "windows.h" | 13 | #include "windows.h" |
14 | #include "friendlist.h" | 14 | #include "friendlist.h" |
15 | 15 | ||
16 | static char *WINDOW_STATUS; | ||
17 | 16 | ||
18 | typedef struct { | 17 | typedef struct { |
19 | uint8_t name[MAX_NAME_LENGTH]; | 18 | uint8_t name[MAX_NAME_LENGTH]; |
@@ -48,17 +47,7 @@ void friendlist_onMessage(ToxWindow *self, Messenger *m, int num, uint8_t *str, | |||
48 | return; | 47 | return; |
49 | 48 | ||
50 | if (friends[num].chatwin == -1) { | 49 | if (friends[num].chatwin == -1) { |
51 | friends[num].chatwin = num; | 50 | friends[num].chatwin = add_window(m, new_chat(m, num)); |
52 | int i; | ||
53 | |||
54 | /* Find first open slot to hold chat window */ | ||
55 | for (i = N_DEFAULT_WINS; i < MAX_WINDOW_SLOTS; ++i) { | ||
56 | if (WINDOW_STATUS[i] == -1) { | ||
57 | WINDOW_STATUS[i] = num; | ||
58 | add_window(m, new_chat(m, num), i); | ||
59 | break; | ||
60 | } | ||
61 | } | ||
62 | } | 51 | } |
63 | } | 52 | } |
64 | 53 | ||
@@ -106,25 +95,9 @@ static void friendlist_onKey(ToxWindow *self, Messenger *m, int key) | |||
106 | } else if (key == '\n') { | 95 | } else if (key == '\n') { |
107 | /* Jump to chat window if already open */ | 96 | /* Jump to chat window if already open */ |
108 | if (friends[num_selected].chatwin != -1) { | 97 | if (friends[num_selected].chatwin != -1) { |
109 | int i; | 98 | set_active_window(friends[num_selected].chatwin); |
110 | |||
111 | for (i = N_DEFAULT_WINS; i < MAX_WINDOW_SLOTS; ++i) { | ||
112 | if (WINDOW_STATUS[i] == num_selected) { | ||
113 | set_active_window(i); | ||
114 | break; | ||
115 | } | ||
116 | } | ||
117 | } else { | 99 | } else { |
118 | int i; | 100 | friends[num_selected].chatwin = add_window(m, new_chat(m, num_selected)); |
119 | |||
120 | for (i = N_DEFAULT_WINS; i < MAX_WINDOW_SLOTS; ++i) { | ||
121 | if (WINDOW_STATUS[i] == -1) { | ||
122 | WINDOW_STATUS[i] = num_selected; | ||
123 | friends[num_selected].chatwin = num_selected; | ||
124 | add_window(m, new_chat(m, num_selected), i); | ||
125 | break; | ||
126 | } | ||
127 | } | ||
128 | } | 101 | } |
129 | } | 102 | } |
130 | } | 103 | } |
@@ -172,9 +145,8 @@ static void friendlist_onInit(ToxWindow *self, Messenger *m) | |||
172 | 145 | ||
173 | } | 146 | } |
174 | 147 | ||
175 | ToxWindow new_friendlist(char *ws) | 148 | ToxWindow new_friendlist() |
176 | { | 149 | { |
177 | WINDOW_STATUS = ws; | ||
178 | ToxWindow ret; | 150 | ToxWindow ret; |
179 | memset(&ret, 0, sizeof(ret)); | 151 | memset(&ret, 0, sizeof(ret)); |
180 | 152 | ||
diff --git a/testing/toxic/friendlist.h b/testing/toxic/friendlist.h index f0c27f53..91b917fd 100644 --- a/testing/toxic/friendlist.h +++ b/testing/toxic/friendlist.h | |||
@@ -4,7 +4,7 @@ | |||
4 | #include "windows.h" | 4 | #include "windows.h" |
5 | #include "chat.h" | 5 | #include "chat.h" |
6 | 6 | ||
7 | ToxWindow new_friendlist(char *ws); | 7 | ToxWindow new_friendlist(); |
8 | int friendlist_onFriendAdded(Messenger *m, int num); | 8 | int friendlist_onFriendAdded(Messenger *m, int num); |
9 | void disable_chatwin(int f_num); | 9 | void disable_chatwin(int f_num); |
10 | void fix_name(uint8_t *name); | 10 | void fix_name(uint8_t *name); |
diff --git a/testing/toxic/main.c b/testing/toxic/main.c index 2da87bc6..9abe8de4 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c | |||
@@ -27,6 +27,7 @@ | |||
27 | 27 | ||
28 | /* Export for use in Callbacks */ | 28 | /* Export for use in Callbacks */ |
29 | char *DATA_FILE = NULL; | 29 | char *DATA_FILE = NULL; |
30 | char *SRVLIST_FILE = NULL; | ||
30 | 31 | ||
31 | void on_window_resize(int sig) | 32 | void on_window_resize(int sig) |
32 | { | 33 | { |
@@ -74,10 +75,12 @@ static Messenger *init_tox() | |||
74 | m_callback_action(m, on_action, NULL); | 75 | m_callback_action(m, on_action, NULL); |
75 | #ifdef __linux__ | 76 | #ifdef __linux__ |
76 | setname(m, (uint8_t *) "Cool guy", sizeof("Cool guy")); | 77 | setname(m, (uint8_t *) "Cool guy", sizeof("Cool guy")); |
77 | #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) | 78 | #elif defined(WIN32) |
78 | setname(m, (uint8_t *) "I should install GNU/Linux", sizeof("I should install GNU/Linux")); | 79 | setname(m, (uint8_t *) "I should install GNU/Linux", sizeof("I should install GNU/Linux")); |
80 | #elif defined(__APPLE__) | ||
81 | setname(m, (uint8_t *) "Hipster", sizeof("Hipster")); //This used to users of other Unixes are hipsters | ||
79 | #else | 82 | #else |
80 | setname(m, (uint8_t *) "Hipster", sizeof("Hipster")); | 83 | setname(m, (uint8_t *) "Registered Minix user #4", sizeof("Registered Minix user #4")); |
81 | #endif | 84 | #endif |
82 | return m; | 85 | return m; |
83 | } | 86 | } |
@@ -89,14 +92,12 @@ static Messenger *init_tox() | |||
89 | /* Connects to a random DHT server listed in the DHTservers file */ | 92 | /* Connects to a random DHT server listed in the DHTservers file */ |
90 | int init_connection(void) | 93 | int init_connection(void) |
91 | { | 94 | { |
95 | FILE *fp = NULL; | ||
96 | |||
92 | if (DHT_isconnected()) | 97 | if (DHT_isconnected()) |
93 | return 0; | 98 | return 0; |
94 | 99 | ||
95 | #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) | 100 | fp = fopen(SRVLIST_FILE, "r"); |
96 | FILE *fp = fopen("DHTservers", "r"); | ||
97 | #else | ||
98 | FILE *fp = fopen("~/.tox/DHTservers", "r"); | ||
99 | #endif | ||
100 | 101 | ||
101 | if (!fp) | 102 | if (!fp) |
102 | return 1; | 103 | return 1; |
@@ -290,11 +291,17 @@ int main(int argc, char *argv[]) | |||
290 | 291 | ||
291 | if (config_err) { | 292 | if (config_err) { |
292 | DATA_FILE = strdup("data"); | 293 | DATA_FILE = strdup("data"); |
294 | SRVLIST_FILE = strdup("../../other/DHTservers"); | ||
293 | } else { | 295 | } else { |
294 | DATA_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("data") + 1); | 296 | DATA_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("data") + 1); |
295 | strcpy(DATA_FILE, user_config_dir); | 297 | strcpy(DATA_FILE, user_config_dir); |
296 | strcat(DATA_FILE, CONFIGDIR); | 298 | strcat(DATA_FILE, CONFIGDIR); |
297 | strcat(DATA_FILE, "data"); | 299 | strcat(DATA_FILE, "data"); |
300 | |||
301 | SRVLIST_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("DHTservers") + 1); | ||
302 | strcpy(SRVLIST_FILE, user_config_dir); | ||
303 | strcat(SRVLIST_FILE, CONFIGDIR); | ||
304 | strcat(SRVLIST_FILE, "DHTservers"); | ||
298 | } | 305 | } |
299 | } | 306 | } |
300 | 307 | ||
@@ -303,7 +310,6 @@ int main(int argc, char *argv[]) | |||
303 | init_term(); | 310 | init_term(); |
304 | Messenger *m = init_tox(); | 311 | Messenger *m = init_tox(); |
305 | ToxWindow *prompt = init_windows(m); | 312 | ToxWindow *prompt = init_windows(m); |
306 | init_window_status(); | ||
307 | 313 | ||
308 | if (f_loadfromfile) | 314 | if (f_loadfromfile) |
309 | load_data(m, DATA_FILE); | 315 | load_data(m, DATA_FILE); |
@@ -332,5 +338,6 @@ int main(int argc, char *argv[]) | |||
332 | 338 | ||
333 | cleanupMessenger(m); | 339 | cleanupMessenger(m); |
334 | free(DATA_FILE); | 340 | free(DATA_FILE); |
341 | free(SRVLIST_FILE); | ||
335 | return 0; | 342 | return 0; |
336 | } | 343 | } |
diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index a37fdaaa..473633d4 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c | |||
@@ -19,7 +19,6 @@ extern int store_data(Messenger *m, char *path); | |||
19 | uint8_t pending_requests[MAX_STR_SIZE][CLIENT_ID_SIZE]; // XXX | 19 | uint8_t pending_requests[MAX_STR_SIZE][CLIENT_ID_SIZE]; // XXX |
20 | uint8_t num_requests = 0; // XXX | 20 | uint8_t num_requests = 0; // XXX |
21 | 21 | ||
22 | static friendAddedFn *on_friendadded_cb; | ||
23 | static char prompt_buf[MAX_STR_SIZE] = {0}; | 22 | static char prompt_buf[MAX_STR_SIZE] = {0}; |
24 | static int prompt_buf_pos = 0; | 23 | static int prompt_buf_pos = 0; |
25 | 24 | ||
@@ -97,7 +96,7 @@ void cmd_accept(ToxWindow *self, Messenger *m, char **args) | |||
97 | wprintw(self->window, "Failed to add friend.\n"); | 96 | wprintw(self->window, "Failed to add friend.\n"); |
98 | else { | 97 | else { |
99 | wprintw(self->window, "Friend accepted as: %d.\n", num); | 98 | wprintw(self->window, "Friend accepted as: %d.\n", num); |
100 | on_friendadded_cb(m, num); | 99 | on_friendadded(m, num); |
101 | } | 100 | } |
102 | } | 101 | } |
103 | 102 | ||
@@ -174,7 +173,7 @@ void cmd_add(ToxWindow *self, Messenger *m, char **args) | |||
174 | 173 | ||
175 | default: | 174 | default: |
176 | wprintw(self->window, "Friend added as %d.\n", num); | 175 | wprintw(self->window, "Friend added as %d.\n", num); |
177 | on_friendadded_cb(m, num); | 176 | on_friendadded(m, num); |
178 | break; | 177 | break; |
179 | } | 178 | } |
180 | } | 179 | } |
@@ -273,6 +272,7 @@ void cmd_nick(ToxWindow *self, Messenger *m, char **args) | |||
273 | char *nick = args[1]; | 272 | char *nick = args[1]; |
274 | setname(m, (uint8_t *) nick, strlen(nick) + 1); | 273 | setname(m, (uint8_t *) nick, strlen(nick) + 1); |
275 | wprintw(self->window, "Nickname set to: %s\n", nick); | 274 | wprintw(self->window, "Nickname set to: %s\n", nick); |
275 | |||
276 | if (store_data(m, DATA_FILE)) { | 276 | if (store_data(m, DATA_FILE)) { |
277 | wprintw(self->window, "\nCould not store Messenger data\n"); | 277 | wprintw(self->window, "\nCould not store Messenger data\n"); |
278 | } | 278 | } |
@@ -480,9 +480,8 @@ static void prompt_onInit(ToxWindow *self, Messenger *m) | |||
480 | wclrtoeol(self->window); | 480 | wclrtoeol(self->window); |
481 | } | 481 | } |
482 | 482 | ||
483 | ToxWindow new_prompt(friendAddedFn *f) | 483 | ToxWindow new_prompt() |
484 | { | 484 | { |
485 | on_friendadded_cb = f; | ||
486 | ToxWindow ret; | 485 | ToxWindow ret; |
487 | memset(&ret, 0, sizeof(ret)); | 486 | memset(&ret, 0, sizeof(ret)); |
488 | ret.onKey = &prompt_onKey; | 487 | ret.onKey = &prompt_onKey; |
diff --git a/testing/toxic/prompt.h b/testing/toxic/prompt.h index 6c5320ab..8e12a42f 100644 --- a/testing/toxic/prompt.h +++ b/testing/toxic/prompt.h | |||
@@ -3,9 +3,7 @@ | |||
3 | 3 | ||
4 | #include "windows.h" | 4 | #include "windows.h" |
5 | 5 | ||
6 | typedef void (friendAddedFn)(Messenger *m, int friendnumber); | 6 | ToxWindow new_prompt(); |
7 | |||
8 | ToxWindow new_prompt(friendAddedFn *f); | ||
9 | int add_req(uint8_t *public_key); | 7 | int add_req(uint8_t *public_key); |
10 | unsigned char *hex_string_to_bin(char hex_string[]); | 8 | unsigned char *hex_string_to_bin(char hex_string[]); |
11 | 9 | ||
diff --git a/testing/toxic/windows.c b/testing/toxic/windows.c index 11396e2c..c0ff3026 100644 --- a/testing/toxic/windows.c +++ b/testing/toxic/windows.c | |||
@@ -6,15 +6,10 @@ | |||
6 | extern char *DATA_FILE; | 6 | extern char *DATA_FILE; |
7 | extern int store_data(Messenger *m, char *path); | 7 | extern int store_data(Messenger *m, char *path); |
8 | 8 | ||
9 | /* Holds status of chat windows */ | 9 | static ToxWindow windows[MAX_WINDOWS_NUM]; |
10 | char WINDOW_STATUS[MAX_WINDOW_SLOTS]; | 10 | static ToxWindow *active_window; |
11 | |||
12 | static int w_num; | ||
13 | static ToxWindow windows[MAX_WINDOW_SLOTS]; | ||
14 | static Messenger *m; | ||
15 | int active_window; | ||
16 | |||
17 | static ToxWindow *prompt; | 11 | static ToxWindow *prompt; |
12 | static Messenger *m; | ||
18 | 13 | ||
19 | /* CALLBACKS START */ | 14 | /* CALLBACKS START */ |
20 | void on_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata) | 15 | void on_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata) |
@@ -31,7 +26,7 @@ void on_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userd | |||
31 | wprintw(prompt->window, "\nWith the message: %s\n", data); | 26 | wprintw(prompt->window, "\nWith the message: %s\n", data); |
32 | wprintw(prompt->window, "\nUse \"accept %d\" to accept it.\n", n); | 27 | wprintw(prompt->window, "\nUse \"accept %d\" to accept it.\n", n); |
33 | 28 | ||
34 | for (i = 0; i < MAX_WINDOW_SLOTS; ++i) { | 29 | for (i = 0; i < MAX_WINDOWS_NUM; ++i) { |
35 | if (windows[i].onFriendRequest != NULL) | 30 | if (windows[i].onFriendRequest != NULL) |
36 | windows[i].onFriendRequest(&windows[i], public_key, data, length); | 31 | windows[i].onFriendRequest(&windows[i], public_key, data, length); |
37 | } | 32 | } |
@@ -41,7 +36,7 @@ void on_message(Messenger *m, int friendnumber, uint8_t *string, uint16_t length | |||
41 | { | 36 | { |
42 | int i; | 37 | int i; |
43 | 38 | ||
44 | for (i = 0; i < MAX_WINDOW_SLOTS; ++i) { | 39 | for (i = 0; i < MAX_WINDOWS_NUM; ++i) { |
45 | if (windows[i].onMessage != NULL) | 40 | if (windows[i].onMessage != NULL) |
46 | windows[i].onMessage(&windows[i], m, friendnumber, string, length); | 41 | windows[i].onMessage(&windows[i], m, friendnumber, string, length); |
47 | } | 42 | } |
@@ -51,7 +46,7 @@ void on_action(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, | |||
51 | { | 46 | { |
52 | int i; | 47 | int i; |
53 | 48 | ||
54 | for (i = 0; i < MAX_WINDOW_SLOTS; ++i) { | 49 | for (i = 0; i < MAX_WINDOWS_NUM; ++i) { |
55 | if (windows[i].onAction != NULL) | 50 | if (windows[i].onAction != NULL) |
56 | windows[i].onAction(&windows[i], m, friendnumber, string, length); | 51 | windows[i].onAction(&windows[i], m, friendnumber, string, length); |
57 | } | 52 | } |
@@ -62,7 +57,7 @@ void on_nickchange(Messenger *m, int friendnumber, uint8_t *string, uint16_t len | |||
62 | wprintw(prompt->window, "\n(nickchange) %d: %s\n", friendnumber, string); | 57 | wprintw(prompt->window, "\n(nickchange) %d: %s\n", friendnumber, string); |
63 | int i; | 58 | int i; |
64 | 59 | ||
65 | for (i = 0; i < MAX_WINDOW_SLOTS; ++i) { | 60 | for (i = 0; i < MAX_WINDOWS_NUM; ++i) { |
66 | if (windows[i].onNickChange != NULL) | 61 | if (windows[i].onNickChange != NULL) |
67 | windows[i].onNickChange(&windows[i], friendnumber, string, length); | 62 | windows[i].onNickChange(&windows[i], friendnumber, string, length); |
68 | } | 63 | } |
@@ -73,7 +68,7 @@ void on_statuschange(Messenger *m, int friendnumber, uint8_t *string, uint16_t l | |||
73 | wprintw(prompt->window, "\n(statuschange) %d: %s\n", friendnumber, string); | 68 | wprintw(prompt->window, "\n(statuschange) %d: %s\n", friendnumber, string); |
74 | int i; | 69 | int i; |
75 | 70 | ||
76 | for (i = 0; i < MAX_WINDOW_SLOTS; ++i) { | 71 | for (i = 0; i < MAX_WINDOWS_NUM; ++i) { |
77 | if (windows[i].onStatusChange != NULL) | 72 | if (windows[i].onStatusChange != NULL) |
78 | windows[i].onStatusChange(&windows[i], friendnumber, string, length); | 73 | windows[i].onStatusChange(&windows[i], friendnumber, string, length); |
79 | } | 74 | } |
@@ -89,119 +84,89 @@ void on_friendadded(Messenger *m, int friendnumber) | |||
89 | } | 84 | } |
90 | /* CALLBACKS END */ | 85 | /* CALLBACKS END */ |
91 | 86 | ||
92 | int add_window(Messenger *m, ToxWindow w, int n) | 87 | int add_window(Messenger *m, ToxWindow w) |
93 | { | 88 | { |
94 | if (w_num >= TOXWINDOWS_MAX_NUM) | ||
95 | return -1; | ||
96 | |||
97 | if (LINES < 2) | 89 | if (LINES < 2) |
98 | return -1; | 90 | return -1; |
99 | 91 | ||
100 | w.window = newwin(LINES - 2, COLS, 0, 0); | 92 | int i; |
101 | 93 | for(i = 0; i < MAX_WINDOWS_NUM; i++) { | |
102 | if (w.window == NULL) | 94 | if (windows[i].window) |
103 | return -1; | 95 | continue; |
104 | 96 | ||
105 | windows[n] = w; | 97 | w.window = newwin(LINES - 2, COLS, 0, 0); |
106 | w.onInit(&w, m); | 98 | if (w.window == NULL) |
107 | w_num++; | 99 | return -1; |
108 | active_window = n; | 100 | |
109 | return n; | 101 | windows[i] = w; |
102 | w.onInit(&w, m); | ||
103 | |||
104 | active_window = windows+i; | ||
105 | return i; | ||
106 | } | ||
107 | |||
108 | return -1; | ||
110 | } | 109 | } |
111 | 110 | ||
112 | /* Deletes window w and cleans up */ | 111 | /* Deletes window w and cleans up */ |
113 | void del_window(ToxWindow *w, int f_num) | 112 | void del_window(ToxWindow *w) |
114 | { | 113 | { |
115 | active_window = 0; // Go to prompt screen | 114 | active_window = windows; // Go to prompt screen |
116 | delwin(w->window); | 115 | delwin(w->window); |
117 | int i; | 116 | if (w->x) |
118 | 117 | free(w->x); | |
119 | for (i = N_DEFAULT_WINS; i < MAX_WINDOW_SLOTS; ++i) { | 118 | w->window = NULL; |
120 | if (WINDOW_STATUS[i] == f_num) { | 119 | memset(w, 0, sizeof(ToxWindow)); |
121 | WINDOW_STATUS[i] = -1; | ||
122 | disable_chatwin(f_num); | ||
123 | break; | ||
124 | } | ||
125 | } | ||
126 | |||
127 | clear(); | 120 | clear(); |
128 | refresh(); | 121 | refresh(); |
129 | } | 122 | } |
130 | 123 | ||
131 | /* Shows next window when tab or back-tab is pressed */ | 124 | /* Shows next window when tab or back-tab is pressed */ |
132 | void set_active_window(int ch) | 125 | void set_next_window(int ch) |
133 | { | 126 | { |
134 | int f_inf = 0; | 127 | ToxWindow *end = windows+MAX_WINDOWS_NUM-1; |
135 | int max = MAX_WINDOW_SLOTS - 1; | 128 | ToxWindow *inf = active_window; |
136 | 129 | while(true) { | |
137 | if (ch == '\t') { | 130 | if (ch == '\t') { |
138 | int i = (active_window + 1) % max; | 131 | if (++active_window > end) |
139 | 132 | active_window = windows; | |
140 | while (true) { | 133 | } else |
141 | if (WINDOW_STATUS[i] != -1) { | 134 | if (--active_window < windows) |
142 | active_window = i; | 135 | active_window = end; |
143 | return; | 136 | |
144 | } | 137 | if (active_window->window) |
145 | 138 | return; | |
146 | i = (i + 1) % max; | 139 | |
147 | 140 | if (active_window == inf) { // infinite loop check | |
148 | if (f_inf++ > max) { // infinite loop check | 141 | endwin(); |
149 | endwin(); | 142 | exit(2); |
150 | exit(2); | ||
151 | } | ||
152 | } | ||
153 | } else { | ||
154 | int i = active_window - 1; | ||
155 | |||
156 | if (i < 0) i = max; | ||
157 | |||
158 | while (true) { | ||
159 | if (WINDOW_STATUS[i] != -1) { | ||
160 | active_window = i; | ||
161 | return; | ||
162 | } | ||
163 | |||
164 | if (--i < 0) i = max; | ||
165 | |||
166 | if (f_inf++ > max) { | ||
167 | endwin(); | ||
168 | exit(2); | ||
169 | } | ||
170 | } | 143 | } |
171 | } | 144 | } |
172 | } | 145 | } |
173 | 146 | ||
174 | void init_window_status() | 147 | void set_active_window(int index) |
175 | { | 148 | { |
176 | /* Default window values decrement from -2 */ | 149 | if (index < 0 || index >= MAX_WINDOWS_NUM) |
177 | int i; | 150 | return; |
178 | 151 | ||
179 | for (i = 0; i < N_DEFAULT_WINS; ++i) | 152 | active_window = windows+index; |
180 | WINDOW_STATUS[i] = -(i + 2); | ||
181 | |||
182 | int j; | ||
183 | |||
184 | for (j = N_DEFAULT_WINS; j < MAX_WINDOW_SLOTS; j++) | ||
185 | WINDOW_STATUS[j] = -1; | ||
186 | } | 153 | } |
187 | 154 | ||
188 | ToxWindow *init_windows() | 155 | ToxWindow *init_windows() |
189 | { | 156 | { |
190 | w_num = 0; | 157 | int n_prompt = add_window(m, new_prompt()); |
191 | int n_prompt = 0; | 158 | |
192 | int n_friendslist = 1; | 159 | if (n_prompt == -1 |
193 | int n_dhtstatus = 2; | 160 | || add_window(m, new_friendlist()) == -1 |
194 | 161 | || add_window(m, new_dhtstatus()) == -1) { | |
195 | if (add_window(m, new_prompt(on_friendadded), n_prompt) == -1 | ||
196 | || add_window(m, new_friendlist(WINDOW_STATUS), n_friendslist) == -1 | ||
197 | || add_window(m, new_dhtstatus(), n_dhtstatus) == -1) { | ||
198 | fprintf(stderr, "add_window() failed.\n"); | 162 | fprintf(stderr, "add_window() failed.\n"); |
199 | endwin(); | 163 | endwin(); |
200 | exit(1); | 164 | exit(1); |
201 | } | 165 | } |
202 | 166 | ||
203 | active_window = n_prompt; | ||
204 | prompt = &windows[n_prompt]; | 167 | prompt = &windows[n_prompt]; |
168 | active_window = prompt; | ||
169 | |||
205 | return prompt; | 170 | return prompt; |
206 | } | 171 | } |
207 | 172 | ||
@@ -222,9 +187,9 @@ static void draw_bar() | |||
222 | 187 | ||
223 | int i; | 188 | int i; |
224 | 189 | ||
225 | for (i = 0; i < (MAX_WINDOW_SLOTS); ++i) { | 190 | for (i = 0; i < (MAX_WINDOWS_NUM); ++i) { |
226 | if (WINDOW_STATUS[i] != -1) { | 191 | if (windows[i].window) { |
227 | if (i == active_window) | 192 | if (windows+i == active_window) |
228 | attron(A_BOLD); | 193 | attron(A_BOLD); |
229 | 194 | ||
230 | odd = (odd + 1) % blinkrate; | 195 | odd = (odd + 1) % blinkrate; |
@@ -232,12 +197,13 @@ static void draw_bar() | |||
232 | if (windows[i].blink && (odd < (blinkrate / 2))) | 197 | if (windows[i].blink && (odd < (blinkrate / 2))) |
233 | attron(COLOR_PAIR(3)); | 198 | attron(COLOR_PAIR(3)); |
234 | 199 | ||
200 | clrtoeol(); | ||
235 | printw(" %s", windows[i].title); | 201 | printw(" %s", windows[i].title); |
236 | 202 | ||
237 | if (windows[i].blink && (odd < (blinkrate / 2))) | 203 | if (windows[i].blink && (odd < (blinkrate / 2))) |
238 | attroff(COLOR_PAIR(3)); | 204 | attroff(COLOR_PAIR(3)); |
239 | 205 | ||
240 | if (i == active_window) { | 206 | if (windows+i == active_window) { |
241 | attroff(A_BOLD); | 207 | attroff(A_BOLD); |
242 | } | 208 | } |
243 | } | 209 | } |
@@ -255,7 +221,7 @@ void prepare_window(WINDOW *w) | |||
255 | void draw_active_window(Messenger *m) | 221 | void draw_active_window(Messenger *m) |
256 | { | 222 | { |
257 | 223 | ||
258 | ToxWindow *a = &windows[active_window]; | 224 | ToxWindow *a = active_window; |
259 | prepare_window(a->window); | 225 | prepare_window(a->window); |
260 | a->blink = false; | 226 | a->blink = false; |
261 | draw_bar(); | 227 | draw_bar(); |
@@ -265,7 +231,7 @@ void draw_active_window(Messenger *m) | |||
265 | int ch = getch(); | 231 | int ch = getch(); |
266 | 232 | ||
267 | if (ch == '\t' || ch == KEY_BTAB) | 233 | if (ch == '\t' || ch == KEY_BTAB) |
268 | set_active_window(ch); | 234 | set_next_window(ch); |
269 | else if (ch != ERR) | 235 | else if (ch != ERR) |
270 | a->onKey(a, m, ch); | 236 | a->onKey(a, m, ch); |
271 | } | 237 | } |
diff --git a/testing/toxic/windows.h b/testing/toxic/windows.h index 553a6200..be5557e9 100644 --- a/testing/toxic/windows.h +++ b/testing/toxic/windows.h | |||
@@ -8,7 +8,7 @@ | |||
8 | #include <stdint.h> | 8 | #include <stdint.h> |
9 | #include <stdbool.h> | 9 | #include <stdbool.h> |
10 | #include "../../core/Messenger.h" | 10 | #include "../../core/Messenger.h" |
11 | #define TOXWINDOWS_MAX_NUM 32 | 11 | #define MAX_WINDOWS_NUM 32 |
12 | #define MAX_FRIENDS_NUM 100 | 12 | #define MAX_FRIENDS_NUM 100 |
13 | #define MAX_STR_SIZE 256 | 13 | #define MAX_STR_SIZE 256 |
14 | #define KEY_SIZE_BYTES 32 | 14 | #define KEY_SIZE_BYTES 32 |
@@ -16,9 +16,6 @@ | |||
16 | /* number of permanent default windows */ | 16 | /* number of permanent default windows */ |
17 | #define N_DEFAULT_WINS 3 | 17 | #define N_DEFAULT_WINS 3 |
18 | 18 | ||
19 | /* maximum window slots for WINDOW_STATUS array */ | ||
20 | #define MAX_WINDOW_SLOTS N_DEFAULT_WINS+MAX_FRIENDS_NUM | ||
21 | |||
22 | #ifndef TOXICVER | 19 | #ifndef TOXICVER |
23 | #define TOXICVER "NOVER" //Use the -D flag to set this | 20 | #define TOXICVER "NOVER" //Use the -D flag to set this |
24 | #endif | 21 | #endif |
@@ -48,11 +45,10 @@ void on_action(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, | |||
48 | void on_nickchange(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata); | 45 | void on_nickchange(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata); |
49 | void on_statuschange(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata); | 46 | void on_statuschange(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata); |
50 | void on_friendadded(Messenger *m, int friendnumber); | 47 | void on_friendadded(Messenger *m, int friendnumber); |
51 | void init_window_status(); | ||
52 | ToxWindow *init_windows(); | 48 | ToxWindow *init_windows(); |
53 | void draw_active_window(Messenger *m); | 49 | void draw_active_window(Messenger *m); |
54 | int add_window(Messenger *m, ToxWindow w, int n); | 50 | int add_window(Messenger *m, ToxWindow w); |
55 | void del_window(ToxWindow *w, int f_num); | 51 | void del_window(ToxWindow *w); |
56 | void set_active_window(int ch); | 52 | void set_active_window(int ch); |
57 | #endif | 53 | #endif |
58 | 54 | ||