0
|
1 #include <stdio.h> |
|
2 #include <stdlib.h> |
|
3 #include <string.h> |
|
4 #include <ncurses.h> |
|
5 #include <panel.h> |
|
6 #include <time.h> |
|
7 #include <ctype.h> |
|
8 |
|
9 #include "screen.h" |
|
10 #include "utils.h" |
|
11 #include "buddies.h" |
|
12 #include "parsecfg.h" |
|
13 #include "lang.h" |
|
14 #include "server.h" |
|
15 |
|
16 #include "list.h" |
|
17 |
|
18 /* Definicion de tipos */ |
|
19 #define window_entry(n) list_entry(n, window_entry_t, list) |
|
20 |
|
21 typedef struct _window_entry_t { |
|
22 WINDOW *win; |
|
23 PANEL *panel; |
|
24 char *name; |
|
25 int nlines; |
|
26 char **texto; |
|
27 struct list_head list; |
|
28 } window_entry_t; |
|
29 |
|
30 LIST_HEAD(window_list); |
|
31 |
|
32 /* Variables globales a SCREEN.C */ |
3
|
33 static WINDOW *rosterWnd, *chatWnd, *inputWnd; |
|
34 static WINDOW *logWnd, *logWnd_border; |
|
35 static PANEL *rosterPanel, *chatPanel, *inputPanel; |
2
|
36 static PANEL *logPanel, *logPanel_border; |
3
|
37 static int maxY, maxX; |
|
38 static window_entry_t *currentWindow; |
0
|
39 |
1
|
40 char inputLine[INPUTLINE_LENGTH]; |
|
41 char *ptr_inputline; |
|
42 |
0
|
43 |
|
44 /* Funciones */ |
|
45 |
|
46 int scr_WindowHeight(WINDOW * win) |
|
47 { |
|
48 int x, y; |
|
49 getmaxyx(win, y, x); |
|
50 return x; |
|
51 } |
|
52 |
1
|
53 void scr_draw_box(WINDOW * win, int y, int x, int height, int width, |
|
54 int Color, chtype box, chtype border) |
0
|
55 { |
|
56 int i, j; |
|
57 |
|
58 wattrset(win, COLOR_PAIR(Color)); |
|
59 for (i = 0; i < height; i++) { |
|
60 wmove(win, y + i, x); |
|
61 for (j = 0; j < width; j++) |
|
62 if (!i && !j) |
|
63 waddch(win, border | ACS_ULCORNER); |
|
64 else if (i == height - 1 && !j) |
|
65 waddch(win, border | ACS_LLCORNER); |
|
66 else if (!i && j == width - 1) |
|
67 waddch(win, box | ACS_URCORNER); |
|
68 else if (i == height - 1 && j == width - 1) |
|
69 waddch(win, box | ACS_LRCORNER); |
|
70 else if (!i) |
|
71 waddch(win, border | ACS_HLINE); |
|
72 else if (i == height - 1) |
|
73 waddch(win, box | ACS_HLINE); |
|
74 else if (!j) |
|
75 waddch(win, border | ACS_VLINE); |
|
76 else if (j == width - 1) |
|
77 waddch(win, box | ACS_VLINE); |
|
78 else |
|
79 waddch(win, box | ' '); |
|
80 } |
|
81 } |
|
82 |
|
83 int FindColor(char *name) |
|
84 { |
|
85 if (!strcmp(name, "default")) |
|
86 return -1; |
|
87 if (!strcmp(name, "black")) |
|
88 return COLOR_BLACK; |
|
89 if (!strcmp(name, "red")) |
|
90 return COLOR_RED; |
|
91 if (!strcmp(name, "green")) |
|
92 return COLOR_GREEN; |
|
93 if (!strcmp(name, "yellow")) |
|
94 return COLOR_YELLOW; |
|
95 if (!strcmp(name, "blue")) |
|
96 return COLOR_BLUE; |
|
97 if (!strcmp(name, "magenta")) |
|
98 return COLOR_MAGENTA; |
|
99 if (!strcmp(name, "cyan")) |
|
100 return COLOR_CYAN; |
|
101 if (!strcmp(name, "white")) |
|
102 return COLOR_WHITE; |
|
103 |
|
104 return -1; |
|
105 } |
|
106 |
|
107 void ParseColors(void) |
|
108 { |
|
109 char *colors[11] = { |
|
110 "", "", |
|
111 "borderlines", |
|
112 "jidonlineselected", |
|
113 "jidonline", |
|
114 "jidofflineselected", |
|
115 "jidoffline", |
|
116 "text", |
|
117 NULL |
|
118 }; |
|
119 |
|
120 char *tmp = malloc(1024); |
|
121 char *color1; |
|
122 char *background = cfg_read("color_background"); |
|
123 char *backselected = cfg_read("color_backselected"); |
|
124 int i = 0; |
|
125 |
|
126 while (colors[i]) { |
|
127 sprintf(tmp, "color_%s", colors[i]); |
|
128 color1 = cfg_read(tmp); |
|
129 |
|
130 switch (i + 1) { |
|
131 case 1: |
|
132 init_pair(1, COLOR_BLACK, COLOR_WHITE); |
|
133 break; |
|
134 case 2: |
|
135 init_pair(2, COLOR_WHITE, COLOR_BLACK); |
|
136 break; |
|
137 case 3: |
|
138 init_pair(3, FindColor(color1), FindColor(background)); |
|
139 break; |
|
140 case 4: |
|
141 init_pair(4, FindColor(color1), FindColor(backselected)); |
|
142 break; |
|
143 case 5: |
|
144 init_pair(5, FindColor(color1), FindColor(background)); |
|
145 break; |
|
146 case 6: |
|
147 init_pair(6, FindColor(color1), FindColor(backselected)); |
|
148 break; |
|
149 case 7: |
|
150 init_pair(7, FindColor(color1), FindColor(background)); |
|
151 break; |
|
152 case 8: |
|
153 init_pair(8, FindColor(color1), FindColor(background)); |
|
154 break; |
|
155 } |
|
156 i++; |
|
157 } |
|
158 } |
|
159 |
|
160 |
|
161 window_entry_t *scr_CreatePanel(char *title, int x, int y, int lines, |
3
|
162 int cols, int dont_show) |
0
|
163 { |
|
164 window_entry_t *tmp = calloc(1, sizeof(window_entry_t)); |
|
165 |
|
166 tmp->win = newwin(lines, cols, y, x); |
|
167 tmp->panel = new_panel(tmp->win); |
|
168 tmp->name = (char *) calloc(1, 1024); |
|
169 strncpy(tmp->name, title, 1024); |
3
|
170 /* |
|
171 if (!dont_show) { |
|
172 currentWindow = tmp; |
|
173 scr_draw_box(tmp->win, 0, 0, lines, cols, COLOR_GENERAL, 0, 0); |
|
174 mvwprintw(tmp->win, 0, (cols - (2 + strlen(title))) / 2, " %s ", title); |
|
175 } |
|
176 */ |
|
177 // *** |
0
|
178 scr_draw_box(tmp->win, 0, 0, lines, cols, COLOR_GENERAL, 0, 0); |
|
179 mvwprintw(tmp->win, 0, (cols - (2 + strlen(title))) / 2, " %s ", title); |
3
|
180 if (!dont_show) { |
|
181 currentWindow = tmp; |
|
182 } else { |
|
183 top_panel(currentWindow->panel); |
|
184 } |
|
185 // *** |
0
|
186 list_add_tail(&tmp->list, &window_list); |
|
187 update_panels(); |
|
188 |
|
189 return tmp; |
|
190 } |
|
191 |
|
192 |
1
|
193 void scr_CreatePopup(char *title, char *texto, int corte, int type, |
|
194 char *returnstring) |
0
|
195 { |
|
196 WINDOW *popupWin; |
|
197 PANEL *popupPanel; |
|
198 |
|
199 int lineas = 0; |
|
200 int cols = 0; |
|
201 |
|
202 char **submsgs; |
|
203 int n = 0; |
|
204 int i; |
|
205 |
|
206 char *instr = (char *) calloc(1, 1024); |
|
207 |
|
208 /* fprintf(stderr, "\r\n%d", lineas); */ |
|
209 |
|
210 submsgs = ut_SplitMessage(texto, &n, corte); |
|
211 |
|
212 switch (type) { |
|
213 case 1: |
|
214 case 0: |
|
215 lineas = n + 4; |
|
216 break; |
|
217 } |
|
218 |
|
219 cols = corte + 3; |
|
220 popupWin = newwin(lineas, cols, (maxY - lineas) / 2, (maxX - cols) / 2); |
|
221 popupPanel = new_panel(popupWin); |
|
222 |
|
223 /*ATENCION!!! Colorear el popup ?? |
|
224 / box (popupWin, 0, 0); */ |
|
225 scr_draw_box(popupWin, 0, 0, lineas, cols, COLOR_POPUP, 0, 0); |
|
226 mvwprintw(popupWin, 0, (cols - (2 + strlen(title))) / 2, " %s ", title); |
|
227 |
|
228 for (i = 0; i < n; i++) |
|
229 mvwprintw(popupWin, i + 1, 2, "%s", submsgs[i]); |
|
230 |
|
231 |
|
232 for (i = 0; i < n; i++) |
|
233 free(submsgs[i]); |
|
234 free(submsgs); |
|
235 |
|
236 switch (type) { |
|
237 case 0: |
|
238 mvwprintw(popupWin, n + 2, |
|
239 (cols - (2 + strlen(i18n("Press any key")))) / 2, |
|
240 i18n("Press any key")); |
|
241 update_panels(); |
|
242 doupdate(); |
|
243 getch(); |
|
244 break; |
|
245 case 1: |
|
246 { |
|
247 char ch; |
|
248 int scroll = 0; |
|
249 int input_x = 0; |
|
250 |
|
251 wmove(popupWin, 3, 1); |
|
252 wrefresh(popupWin); |
|
253 keypad(popupWin, TRUE); |
|
254 while ((ch = getch()) != '\n') { |
|
255 switch (ch) { |
|
256 case 0x09: |
|
257 case KEY_UP: |
|
258 case KEY_DOWN: |
|
259 break; |
|
260 case KEY_RIGHT: |
|
261 case KEY_LEFT: |
|
262 break; |
|
263 case KEY_BACKSPACE: |
|
264 case 127: |
|
265 if (input_x || scroll) { |
|
266 /* wattrset (popupWin, 0); */ |
|
267 if (!input_x) { |
|
268 scroll = scroll < cols - 3 ? 0 : scroll - (cols - 3); |
|
269 wmove(popupWin, 3, 1); |
|
270 for (i = 0; i < cols; i++) |
|
271 waddch |
|
272 (popupWin, |
|
273 instr |
|
274 [scroll |
|
275 + input_x + i] ? instr[scroll + input_x + i] : ' '); |
|
276 input_x = strlen(instr) - scroll; |
|
277 } else |
|
278 input_x--; |
|
279 instr[scroll + input_x] = '\0'; |
|
280 mvwaddch(popupWin, 3, input_x + 1, ' '); |
|
281 wmove(popupWin, 3, input_x + 1); |
|
282 wrefresh(popupWin); |
|
283 } |
|
284 default: |
|
285 if ( /*ch<0x100 && */ isprint(ch) || ch == '�' |
|
286 || ch == '�') { |
|
287 if (scroll + input_x < 1024) { |
|
288 instr[scroll + input_x] = ch; |
|
289 instr[scroll + input_x + 1] = '\0'; |
|
290 if (input_x == cols - 3) { |
|
291 scroll++; |
|
292 wmove(popupWin, 3, 1); |
|
293 for (i = 0; i < cols - 3; i++) |
|
294 waddch(popupWin, instr[scroll + i]); |
|
295 } else { |
|
296 wmove(popupWin, 3, 1 + input_x++); |
|
297 waddch(popupWin, ch); |
|
298 } |
|
299 wrefresh(popupWin); |
|
300 } else { |
|
301 flash(); |
|
302 } |
|
303 } |
|
304 } |
|
305 } |
|
306 } |
|
307 if (returnstring != NULL) |
|
308 strcpy(returnstring, instr); |
|
309 break; |
|
310 } |
|
311 |
|
312 del_panel(popupPanel); |
|
313 delwin(popupWin); |
|
314 update_panels(); |
|
315 doupdate(); |
|
316 free(instr); |
2
|
317 keypad(inputWnd, TRUE); |
0
|
318 } |
|
319 |
|
320 |
|
321 |
|
322 void scr_RoolWindow(void) |
|
323 { |
|
324 } |
|
325 |
3
|
326 window_entry_t *scr_SearchWindow(char *winId) |
0
|
327 { |
|
328 struct list_head *pos, *n; |
|
329 window_entry_t *search_entry = NULL; |
|
330 |
|
331 list_for_each_safe(pos, n, &window_list) { |
|
332 search_entry = window_entry(pos); |
|
333 if (search_entry->name) { |
3
|
334 if (!strcasecmp(search_entry->name, winId)) { |
0
|
335 return search_entry; |
|
336 } |
|
337 } |
|
338 } |
|
339 return NULL; |
|
340 } |
|
341 |
3
|
342 void scr_ShowWindow(char *winId) |
0
|
343 { |
|
344 int n, width, i; |
3
|
345 window_entry_t *tmp = scr_SearchWindow(winId); |
0
|
346 if (tmp != NULL) { |
|
347 top_panel(tmp->panel); |
3
|
348 currentWindow = tmp; |
0
|
349 width = scr_WindowHeight(tmp->win); |
|
350 for (n = 0; n < tmp->nlines; n++) { |
|
351 mvwprintw(tmp->win, n + 1, 1, ""); |
|
352 for (i = 0; i < width - 2; i++) |
|
353 waddch(tmp->win, ' '); |
|
354 mvwprintw(tmp->win, n + 1, 1, "%s", tmp->texto[n]); |
|
355 } |
1
|
356 move(CHAT_WIN_HEIGHT - 1, maxX - 1); |
0
|
357 update_panels(); |
|
358 doupdate(); |
|
359 } |
|
360 } |
|
361 |
|
362 void scr_ShowBuddyWindow(void) |
|
363 { |
|
364 buddy_entry_t *tmp = bud_SelectedInfo(); |
|
365 if (tmp->jid != NULL) |
|
366 scr_ShowWindow(tmp->jid); |
|
367 } |
|
368 |
|
369 |
3
|
370 void scr_WriteInWindow(char *winId, char *texto, int TimeStamp) |
0
|
371 { |
|
372 time_t ahora; |
|
373 int n; |
|
374 int i; |
|
375 int width; |
|
376 window_entry_t *tmp; |
3
|
377 int dont_show = 0; |
0
|
378 |
3
|
379 |
|
380 tmp = scr_SearchWindow(winId); |
|
381 |
|
382 if ((currentWindow) && (currentWindow != tmp)) |
|
383 dont_show = 1; |
|
384 |
0
|
385 if (tmp == NULL) { |
3
|
386 tmp = scr_CreatePanel(winId, 20, 0, CHAT_WIN_HEIGHT, maxX - 20, dont_show); |
1
|
387 tmp->texto = (char **) calloc((CHAT_WIN_HEIGHT+1) * 3, sizeof(char *)); |
|
388 for (n = 0; n < CHAT_WIN_HEIGHT * 3; n++) |
0
|
389 tmp->texto[n] = (char *) calloc(1, 1024); |
|
390 |
|
391 if (TimeStamp) { |
|
392 ahora = time(NULL); |
|
393 strftime(tmp->texto[tmp->nlines], 1024, "[%H:%M] ", |
|
394 localtime(&ahora)); |
|
395 strcat(tmp->texto[tmp->nlines], texto); |
|
396 } else { |
|
397 sprintf(tmp->texto[tmp->nlines], " %s", texto); |
|
398 } |
|
399 tmp->nlines++; |
|
400 } else { |
1
|
401 if (tmp->nlines < CHAT_WIN_HEIGHT - 2) { |
0
|
402 if (TimeStamp) { |
|
403 ahora = time(NULL); |
|
404 strftime(tmp->texto[tmp->nlines], 1024, |
|
405 "[%H:%M] ", localtime(&ahora)); |
|
406 strcat(tmp->texto[tmp->nlines], texto); |
|
407 } else { |
|
408 sprintf(tmp->texto[tmp->nlines], " %s", texto); |
|
409 } |
|
410 tmp->nlines++; |
|
411 } else { |
|
412 for (n = 0; n < tmp->nlines; n++) { |
|
413 memset(tmp->texto[n], 0, 1024); |
|
414 strncpy(tmp->texto[n], tmp->texto[n + 1], 1024); |
|
415 } |
|
416 if (TimeStamp) { |
|
417 ahora = time(NULL); |
|
418 strftime(tmp->texto[tmp->nlines - 1], 1024, |
|
419 "[%H:%M] ", localtime(&ahora)); |
|
420 strcat(tmp->texto[tmp->nlines - 1], texto); |
|
421 } else { |
|
422 sprintf(tmp->texto[tmp->nlines - 1], " %s", texto); |
|
423 } |
|
424 } |
|
425 } |
|
426 |
3
|
427 if (!dont_show) { |
|
428 top_panel(tmp->panel); |
|
429 width = scr_WindowHeight(tmp->win); |
|
430 for (n = 0; n < tmp->nlines; n++) { |
|
431 mvwprintw(tmp->win, n + 1, 1, ""); |
|
432 for (i = 0; i < width - 2; i++) |
|
433 waddch(tmp->win, ' '); |
|
434 mvwprintw(tmp->win, n + 1, 1, "%s", tmp->texto[n]); |
|
435 } |
|
436 |
|
437 update_panels(); |
|
438 doupdate(); |
0
|
439 } |
|
440 } |
|
441 |
|
442 void scr_InitCurses(void) |
|
443 { |
|
444 initscr(); |
|
445 noecho(); |
|
446 raw(); |
2
|
447 //cbreak(); |
0
|
448 start_color(); |
|
449 use_default_colors(); |
|
450 |
|
451 ParseColors(); |
|
452 |
|
453 getmaxyx(stdscr, maxY, maxX); |
1
|
454 inputLine[0] = 0; |
|
455 ptr_inputline = inputLine; |
0
|
456 |
|
457 return; |
|
458 } |
|
459 |
|
460 void scr_DrawMainWindow(void) |
|
461 { |
1
|
462 /* Draw main panels */ |
0
|
463 rosterWnd = newwin(maxY-1, 20, 0, 0); |
|
464 rosterPanel = new_panel(rosterWnd); |
|
465 scr_draw_box(rosterWnd, 0, 0, maxY-1, 20, COLOR_GENERAL, 0, 0); |
|
466 mvwprintw(rosterWnd, 0, (20 - strlen(i18n("Roster"))) / 2, |
|
467 i18n("Roster")); |
|
468 |
1
|
469 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - 20, 0, 20); |
0
|
470 chatPanel = new_panel(chatWnd); |
1
|
471 scr_draw_box(chatWnd, 0, 0, CHAT_WIN_HEIGHT, maxX - 20, COLOR_GENERAL, 0, 0); |
0
|
472 mvwprintw(chatWnd, 0, |
|
473 ((maxX - 20) - strlen(i18n("Status Window"))) / 2, |
|
474 i18n("Status Window")); |
|
475 |
1
|
476 logWnd_border = newwin(LOG_WIN_HEIGHT, maxX - 20, CHAT_WIN_HEIGHT, 20); |
|
477 logPanel_border = new_panel(logWnd_border); |
|
478 scr_draw_box(logWnd_border, 0, 0, LOG_WIN_HEIGHT, maxX - 20, COLOR_GENERAL, 0, 0); |
|
479 // mvwprintw(logWnd_border, 0, |
|
480 // ((maxX - 20) - strlen(i18n("Log Window"))) / 2, |
|
481 // i18n("Log Window")); |
|
482 //logWnd = newwin(LOG_WIN_HEIGHT - 2, maxX-20 - 2, CHAT_WIN_HEIGHT+1, 20+1); |
|
483 logWnd = derwin(logWnd_border, LOG_WIN_HEIGHT-2, maxX-20-2, 1, 1); |
|
484 logPanel = new_panel(logWnd); |
|
485 wbkgd(logWnd, COLOR_PAIR(COLOR_GENERAL)); |
|
486 //wattrset(logWnd, COLOR_PAIR(COLOR_GENERAL)); |
|
487 wprintw(logWnd, "Here we are\n"); |
|
488 |
|
489 scrollok(logWnd,TRUE); |
|
490 idlok(logWnd,TRUE); // XXX Necessary? |
|
491 |
|
492 inputWnd = newwin(1, maxX, maxY-1, 0); |
|
493 inputPanel = new_panel(inputWnd); |
|
494 //wbkgd(inputWnd, COLOR_PAIR(COLOR_GENERAL)); |
|
495 |
0
|
496 bud_DrawRoster(rosterWnd); |
|
497 update_panels(); |
|
498 doupdate(); |
|
499 return; |
|
500 } |
|
501 |
|
502 void scr_TerminateCurses(void) |
|
503 { |
|
504 clear(); |
|
505 refresh(); |
|
506 endwin(); |
|
507 return; |
|
508 } |
|
509 |
|
510 void scr_WriteIncomingMessage(char *jidfrom, char *text) |
|
511 { |
|
512 char **submsgs; |
|
513 int n, i; |
|
514 char *buffer = (char *) malloc(5 + strlen(text)); |
|
515 |
|
516 sprintf(buffer, "<<< %s", text); |
|
517 |
|
518 submsgs = |
|
519 ut_SplitMessage(buffer, &n, maxX - scr_WindowHeight(rosterWnd) - 20); |
|
520 |
|
521 for (i = 0; i < n; i++) { |
|
522 if (i == 0) |
|
523 scr_WriteInWindow(jidfrom, submsgs[i], TRUE); |
|
524 else |
|
525 scr_WriteInWindow(jidfrom, submsgs[i], FALSE); |
|
526 } |
|
527 |
|
528 for (i = 0; i < n; i++) |
|
529 free(submsgs[i]); |
|
530 |
|
531 free(submsgs); |
|
532 free(buffer); |
|
533 |
2
|
534 top_panel(inputPanel); |
|
535 //wmove(inputWnd, 0, ptr_inputline - (char*)&inputLine); |
|
536 update_panels(); |
|
537 doupdate(); |
0
|
538 } |
|
539 |
|
540 void scr_WriteMessage(int sock) |
|
541 { |
|
542 char **submsgs; |
|
543 int n, i; |
|
544 char *buffer = (char *) calloc(1, 1024); |
|
545 char *buffer2 = (char *) calloc(1, 1024); |
|
546 buddy_entry_t *tmp = bud_SelectedInfo(); |
|
547 |
|
548 scr_ShowWindow(tmp->jid); |
|
549 |
|
550 ut_CenterMessage(i18n("write your message here"), 60, buffer2); |
|
551 |
|
552 scr_CreatePopup(tmp->jid, buffer2, 60, 1, buffer); |
|
553 |
|
554 if (strlen(buffer)) { |
|
555 sprintf(buffer2, ">>> %s", buffer); |
|
556 |
|
557 submsgs = |
|
558 ut_SplitMessage(buffer2, &n, |
|
559 maxX - scr_WindowHeight(rosterWnd) - 20); |
|
560 for (i = 0; i < n; i++) { |
|
561 if (i == 0) |
|
562 scr_WriteInWindow(tmp->jid, submsgs[i], TRUE); |
|
563 else |
|
564 scr_WriteInWindow(tmp->jid, submsgs[i], FALSE); |
|
565 } |
|
566 |
|
567 for (i = 0; i < n; i++) |
|
568 free(submsgs[i]); |
|
569 free(submsgs); |
|
570 |
1
|
571 move(CHAT_WIN_HEIGHT - 1, maxX - 1); |
0
|
572 refresh(); |
|
573 sprintf(buffer2, "%s@%s/%s", cfg_read("username"), |
|
574 cfg_read("server"), cfg_read("resource")); |
|
575 srv_sendtext(sock, tmp->jid, buffer, buffer2); |
|
576 } |
|
577 free(buffer); |
|
578 free(buffer2); |
|
579 } |
|
580 |
|
581 int scr_Getch(void) |
|
582 { |
|
583 int ch; |
2
|
584 // keypad(inputWnd, TRUE); |
|
585 ch = wgetch(inputWnd); |
0
|
586 return ch; |
|
587 } |
|
588 |
|
589 WINDOW *scr_GetRosterWindow(void) |
|
590 { |
|
591 return rosterWnd; |
|
592 } |
|
593 |
|
594 WINDOW *scr_GetStatusWindow(void) |
|
595 { |
|
596 return chatWnd; |
|
597 } |
1
|
598 |
2
|
599 WINDOW *scr_GetInputWindow(void) |
|
600 { |
|
601 return inputWnd; |
|
602 } |
|
603 |
|
604 void send_message(int sock, char *msg) |
|
605 { |
|
606 char **submsgs; |
|
607 char *buffer = (char *) calloc(1, 24+strlen(msg)); |
|
608 char *buffer2 = (char *) calloc(1, 1024); |
|
609 int n, i; |
|
610 buddy_entry_t *tmp = bud_SelectedInfo(); |
|
611 |
|
612 scr_ShowWindow(tmp->jid); |
|
613 |
|
614 sprintf(buffer, ">>> %s", msg); |
|
615 |
|
616 submsgs = |
|
617 ut_SplitMessage(buffer, &n, |
|
618 maxX - scr_WindowHeight(rosterWnd) - 20); |
|
619 for (i = 0; i < n; i++) { |
|
620 if (i == 0) |
|
621 scr_WriteInWindow(tmp->jid, submsgs[i], TRUE); |
|
622 else |
|
623 scr_WriteInWindow(tmp->jid, submsgs[i], FALSE); |
|
624 } |
|
625 |
|
626 for (i = 0; i < n; i++) |
|
627 free(submsgs[i]); |
|
628 free(submsgs); |
|
629 |
|
630 //move(CHAT_WIN_HEIGHT - 1, maxX - 1); |
|
631 refresh(); |
|
632 sprintf(buffer2, "%s@%s/%s", cfg_read("username"), |
|
633 cfg_read("server"), cfg_read("resource")); |
3
|
634 srv_sendtext(sock, tmp->jid, msg, buffer2); |
2
|
635 free(buffer); |
|
636 free(buffer2); |
|
637 |
|
638 top_panel(inputPanel); |
|
639 } |
|
640 |
|
641 int process_line(char *line, int sock) |
|
642 { |
|
643 if (*line == 0) // XXX Simple checks should maybe be in process_key() |
|
644 return 0; |
|
645 if (*line != '/') { |
|
646 send_message(sock, line); |
|
647 return 0; |
|
648 } |
|
649 if (!strcasecmp(line, "/quit")) { |
|
650 return 255; |
|
651 } |
|
652 // Commands handling |
|
653 // TODO |
|
654 // say... |
|
655 wprintw(logWnd, "\nUnrecognised command, sorry."); |
|
656 return 0; |
|
657 } |
|
658 |
|
659 int process_key(int key, int sock) |
1
|
660 { |
|
661 if (isprint(key)) { |
|
662 char tmpLine[INPUTLINE_LENGTH]; |
|
663 strcpy(tmpLine, ptr_inputline); |
|
664 *ptr_inputline++ = key; |
|
665 strcpy(ptr_inputline, tmpLine); |
|
666 } else { |
|
667 switch(key) { |
|
668 case KEY_BACKSPACE: |
|
669 if (ptr_inputline != (char*)&inputLine) { |
|
670 *--ptr_inputline = 0; |
|
671 } |
|
672 break; |
2
|
673 case KEY_DC: |
|
674 if (*ptr_inputline) |
|
675 strcpy(ptr_inputline, ptr_inputline+1); |
|
676 break; |
1
|
677 case KEY_LEFT: |
|
678 if (ptr_inputline != (char*)&inputLine) { |
|
679 ptr_inputline--; |
|
680 } |
|
681 break; |
|
682 case KEY_RIGHT: |
|
683 if (*ptr_inputline) |
|
684 ptr_inputline++; |
|
685 break; |
|
686 case 9: // Tab |
|
687 wprintw(logWnd, "\nI'm unable to complete yet"); |
|
688 break; |
|
689 case '\n': // Enter |
|
690 // XXX Test: |
2
|
691 if (process_line(inputLine, sock)) |
1
|
692 return 255; |
|
693 ptr_inputline = inputLine; |
|
694 *ptr_inputline = 0; |
|
695 break; |
|
696 case KEY_UP: |
|
697 bud_RosterUp(); |
2
|
698 scr_ShowBuddyWindow(); |
1
|
699 break; |
|
700 case KEY_DOWN: |
|
701 bud_RosterDown(); |
2
|
702 scr_ShowBuddyWindow(); |
1
|
703 break; |
2
|
704 case KEY_PPAGE: |
|
705 wprintw(logWnd, "\nPageUp??"); |
|
706 break; |
|
707 case KEY_NPAGE: |
|
708 wprintw(logWnd, "\nPageDown??"); |
|
709 break; |
|
710 case KEY_HOME: |
|
711 case 1: |
|
712 ptr_inputline = inputLine; |
|
713 break; |
|
714 case KEY_END: |
|
715 case 5: |
|
716 for (; *ptr_inputline; ptr_inputline++) ; |
|
717 break; |
|
718 case 21: // Ctrl-u |
|
719 strcpy(inputLine, ptr_inputline); |
|
720 ptr_inputline = inputLine; |
|
721 break; |
|
722 case KEY_EOL: |
|
723 case 11: // Ctrl-k |
|
724 *ptr_inputline = 0; |
|
725 break; |
|
726 default: |
|
727 wprintw(logWnd, "\nUnkown key=%o", key); |
1
|
728 } |
2
|
729 //wprintw(logWnd, "\n[%02x]", key); |
1
|
730 } |
|
731 mvwprintw(inputWnd, 0,0, "%s", inputLine); |
|
732 wclrtoeol(inputWnd); |
|
733 if (*ptr_inputline) { |
|
734 wmove(inputWnd, 0, ptr_inputline - (char*)&inputLine); |
|
735 } |
|
736 update_panels(); |
|
737 doupdate(); |
|
738 return 0; |
|
739 } |