diff options
Diffstat (limited to 'testing/toxic/chat.c')
-rw-r--r-- | testing/toxic/chat.c | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index e1897230..112b20b7 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c | |||
@@ -29,9 +29,9 @@ extern int active_window; | |||
29 | extern void del_window(ToxWindow *w, int f_num); | 29 | extern void del_window(ToxWindow *w, int f_num); |
30 | extern void fix_name(uint8_t *name); | 30 | extern void fix_name(uint8_t *name); |
31 | void print_help(ChatContext *self); | 31 | void print_help(ChatContext *self); |
32 | void execute(ToxWindow *self, ChatContext *ctx, char *cmd, struct tm *timeinfo); | 32 | void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd, struct tm *timeinfo); |
33 | 33 | ||
34 | static void chat_onMessage(ToxWindow *self, int num, uint8_t *msg, uint16_t len) | 34 | static void chat_onMessage(ToxWindow *self, Messenger *m, int num, uint8_t *msg, uint16_t len) |
35 | { | 35 | { |
36 | ChatContext *ctx = (ChatContext*) self->x; | 36 | ChatContext *ctx = (ChatContext*) self->x; |
37 | uint8_t nick[MAX_NAME_LENGTH] = {0}; | 37 | uint8_t nick[MAX_NAME_LENGTH] = {0}; |
@@ -43,7 +43,7 @@ static void chat_onMessage(ToxWindow *self, int num, uint8_t *msg, uint16_t len) | |||
43 | if (ctx->friendnum != num) | 43 | if (ctx->friendnum != num) |
44 | return; | 44 | return; |
45 | 45 | ||
46 | getname(num, (uint8_t*) &nick); | 46 | getname(m, num, (uint8_t*) &nick); |
47 | msg[len-1] = '\0'; | 47 | msg[len-1] = '\0'; |
48 | nick[MAX_NAME_LENGTH-1] = '\0'; | 48 | nick[MAX_NAME_LENGTH-1] = '\0'; |
49 | fix_name(msg); | 49 | fix_name(msg); |
@@ -61,7 +61,7 @@ static void chat_onMessage(ToxWindow *self, int num, uint8_t *msg, uint16_t len) | |||
61 | beep(); | 61 | beep(); |
62 | } | 62 | } |
63 | 63 | ||
64 | static void chat_onAction(ToxWindow *self, int num, uint8_t *action, uint16_t len) | 64 | static void chat_onAction(ToxWindow *self, Messenger *m, int num, uint8_t *action, uint16_t len) |
65 | { | 65 | { |
66 | ChatContext *ctx = (ChatContext*) self->x; | 66 | ChatContext *ctx = (ChatContext*) self->x; |
67 | time_t now; | 67 | time_t now; |
@@ -117,7 +117,7 @@ int string_is_empty(char *string) | |||
117 | return rc; | 117 | return rc; |
118 | } | 118 | } |
119 | 119 | ||
120 | static void chat_onKey(ToxWindow *self, int key) | 120 | static void chat_onKey(ToxWindow *self, Messenger *m, int key) |
121 | { | 121 | { |
122 | ChatContext *ctx = (ChatContext*) self->x; | 122 | ChatContext *ctx = (ChatContext*) self->x; |
123 | time_t now; | 123 | time_t now; |
@@ -155,7 +155,7 @@ static void chat_onKey(ToxWindow *self, int key) | |||
155 | wmove(self->window, y2-CURS_Y_OFFSET, 0); | 155 | wmove(self->window, y2-CURS_Y_OFFSET, 0); |
156 | wclrtobot(self->window); | 156 | wclrtobot(self->window); |
157 | if (ctx->line[0] == '/') | 157 | if (ctx->line[0] == '/') |
158 | execute(self, ctx, ctx->line, timeinfo); | 158 | execute(self, ctx, m, ctx->line, timeinfo); |
159 | else { | 159 | else { |
160 | if (!string_is_empty(ctx->line)) { | 160 | if (!string_is_empty(ctx->line)) { |
161 | /* make sure the string has at least non-space character */ | 161 | /* make sure the string has at least non-space character */ |
@@ -167,7 +167,7 @@ static void chat_onKey(ToxWindow *self, int key) | |||
167 | wattroff(ctx->history, COLOR_PAIR(1)); | 167 | wattroff(ctx->history, COLOR_PAIR(1)); |
168 | wprintw(ctx->history, "%s\n", ctx->line); | 168 | wprintw(ctx->history, "%s\n", ctx->line); |
169 | } | 169 | } |
170 | if (m_sendmessage(ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) == 0) { | 170 | if (m_sendmessage(m, ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) == 0) { |
171 | wattron(ctx->history, COLOR_PAIR(3)); | 171 | wattron(ctx->history, COLOR_PAIR(3)); |
172 | wprintw(ctx->history, " * Failed to send message.\n"); | 172 | wprintw(ctx->history, " * Failed to send message.\n"); |
173 | wattroff(ctx->history, COLOR_PAIR(3)); | 173 | wattroff(ctx->history, COLOR_PAIR(3)); |
@@ -178,7 +178,7 @@ static void chat_onKey(ToxWindow *self, int key) | |||
178 | } | 178 | } |
179 | } | 179 | } |
180 | 180 | ||
181 | void execute(ToxWindow *self, ChatContext *ctx, char *cmd, struct tm *timeinfo) | 181 | void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd, struct tm *timeinfo) |
182 | { | 182 | { |
183 | if (!strcmp(cmd, "/clear") || !strcmp(cmd, "/c")) { | 183 | if (!strcmp(cmd, "/clear") || !strcmp(cmd, "/c")) { |
184 | wclear(self->window); | 184 | wclear(self->window); |
@@ -210,14 +210,14 @@ void execute(ToxWindow *self, ChatContext *ctx, char *cmd, struct tm *timeinfo) | |||
210 | wattroff(ctx->history, COLOR_PAIR(2)); | 210 | wattroff(ctx->history, COLOR_PAIR(2)); |
211 | 211 | ||
212 | uint8_t selfname[MAX_NAME_LENGTH]; | 212 | uint8_t selfname[MAX_NAME_LENGTH]; |
213 | int len = getself_name(selfname); | 213 | int len = getself_name(m, selfname); |
214 | char msg[MAX_STR_SIZE-len-4]; | 214 | char msg[MAX_STR_SIZE-len-4]; |
215 | snprintf(msg, sizeof(msg), "* %s %s\n", (uint8_t*) selfname, action); | 215 | snprintf(msg, sizeof(msg), "* %s %s\n", (uint8_t*) selfname, action); |
216 | 216 | ||
217 | wattron(ctx->history, COLOR_PAIR(1)); | 217 | wattron(ctx->history, COLOR_PAIR(1)); |
218 | wprintw(ctx->history, msg); | 218 | wprintw(ctx->history, msg); |
219 | wattroff(ctx->history, COLOR_PAIR(1)); | 219 | wattroff(ctx->history, COLOR_PAIR(1)); |
220 | if (m_sendaction(ctx->friendnum, (uint8_t*) msg, strlen(msg)+1) < 0) { | 220 | if (m_sendaction(m, ctx->friendnum, (uint8_t*) msg, strlen(msg)+1) < 0) { |
221 | wattron(ctx->history, COLOR_PAIR(3)); | 221 | wattron(ctx->history, COLOR_PAIR(3)); |
222 | wprintw(ctx->history, " * Failed to send action\n"); | 222 | wprintw(ctx->history, " * Failed to send action\n"); |
223 | wattroff(ctx->history, COLOR_PAIR(3)); | 223 | wattroff(ctx->history, COLOR_PAIR(3)); |
@@ -256,13 +256,13 @@ void execute(ToxWindow *self, ChatContext *ctx, char *cmd, struct tm *timeinfo) | |||
256 | 256 | ||
257 | msg = strchr(status, ' '); | 257 | msg = strchr(status, ' '); |
258 | if (msg == NULL) { | 258 | if (msg == NULL) { |
259 | m_set_userstatus(status_kind); | 259 | m_set_userstatus(m, status_kind); |
260 | wprintw(ctx->history, "Status set to: %s\n", status_text); | 260 | wprintw(ctx->history, "Status set to: %s\n", status_text); |
261 | } | 261 | } |
262 | else { | 262 | else { |
263 | msg++; | 263 | msg++; |
264 | m_set_userstatus(status_kind); | 264 | m_set_userstatus(m, status_kind); |
265 | m_set_statusmessage((uint8_t*) msg, strlen(msg)+1); | 265 | m_set_statusmessage(m, ( uint8_t*) msg, strlen(msg)+1); |
266 | wprintw(ctx->history, "Status set to: %s, %s\n", status_text, msg); | 266 | wprintw(ctx->history, "Status set to: %s, %s\n", status_text, msg); |
267 | } | 267 | } |
268 | } | 268 | } |
@@ -275,7 +275,7 @@ void execute(ToxWindow *self, ChatContext *ctx, char *cmd, struct tm *timeinfo) | |||
275 | return; | 275 | return; |
276 | } | 276 | } |
277 | nick++; | 277 | nick++; |
278 | setname((uint8_t*) nick, strlen(nick)+1); | 278 | setname(m, (uint8_t*) nick, strlen(nick)+1); |
279 | wprintw(ctx->history, "Nickname set to: %s\n", nick); | 279 | wprintw(ctx->history, "Nickname set to: %s\n", nick); |
280 | } | 280 | } |
281 | 281 | ||
@@ -312,7 +312,7 @@ static void chat_onDraw(ToxWindow *self) | |||
312 | wrefresh(self->window); | 312 | wrefresh(self->window); |
313 | } | 313 | } |
314 | 314 | ||
315 | static void chat_onInit(ToxWindow *self) | 315 | static void chat_onInit(ToxWindow *self, Messenger *m) |
316 | { | 316 | { |
317 | int x, y; | 317 | int x, y; |
318 | ChatContext *ctx = (ChatContext*) self->x; | 318 | ChatContext *ctx = (ChatContext*) self->x; |
@@ -329,7 +329,7 @@ void print_help(ChatContext *self) | |||
329 | wattron(self->history, COLOR_PAIR(2) | A_BOLD); | 329 | wattron(self->history, COLOR_PAIR(2) | A_BOLD); |
330 | wprintw(self->history, "Commands:\n"); | 330 | wprintw(self->history, "Commands:\n"); |
331 | wattroff(self->history, A_BOLD); | 331 | wattroff(self->history, A_BOLD); |
332 | 332 | ||
333 | wprintw(self->history, " /status <type> <message> : Set your status\n"); | 333 | wprintw(self->history, " /status <type> <message> : Set your status\n"); |
334 | wprintw(self->history, " /nick <nickname> : Set your nickname\n"); | 334 | wprintw(self->history, " /nick <nickname> : Set your nickname\n"); |
335 | wprintw(self->history, " /me <action> : Do an action\n"); | 335 | wprintw(self->history, " /me <action> : Do an action\n"); |
@@ -342,7 +342,7 @@ void print_help(ChatContext *self) | |||
342 | wattroff(self->history, COLOR_PAIR(2)); | 342 | wattroff(self->history, COLOR_PAIR(2)); |
343 | } | 343 | } |
344 | 344 | ||
345 | ToxWindow new_chat(int friendnum) | 345 | ToxWindow new_chat(Messenger *m, int friendnum) |
346 | { | 346 | { |
347 | ToxWindow ret; | 347 | ToxWindow ret; |
348 | memset(&ret, 0, sizeof(ret)); | 348 | memset(&ret, 0, sizeof(ret)); |
@@ -356,7 +356,7 @@ ToxWindow new_chat(int friendnum) | |||
356 | ret.onAction = &chat_onAction; | 356 | ret.onAction = &chat_onAction; |
357 | 357 | ||
358 | uint8_t nick[MAX_NAME_LENGTH] = {0}; | 358 | uint8_t nick[MAX_NAME_LENGTH] = {0}; |
359 | getname(friendnum, (uint8_t*) &nick); | 359 | getname(m, friendnum, (uint8_t*) &nick); |
360 | fix_name(nick); | 360 | fix_name(nick); |
361 | 361 | ||
362 | snprintf(ret.title, sizeof(ret.title), "[%s (%d)]", nick, friendnum); | 362 | snprintf(ret.title, sizeof(ret.title), "[%s (%d)]", nick, friendnum); |