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 */ |
1
|
33 WINDOW *rosterWnd, *chatWnd, *inputWnd; |
|
34 WINDOW *logWnd, *logWnd_border; |
|
35 PANEL *rosterPanel, *chatPanel, *inputPanel; |
2
|
36 static PANEL *logPanel, *logPanel_border; |
0
|
37 int maxY, maxX; |
|
38 window_entry_t *ventanaActual; |
|
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, |
|
162 int cols) |
|
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); |
|
170 scr_draw_box(tmp->win, 0, 0, lines, cols, COLOR_GENERAL, 0, 0); |
|
171 mvwprintw(tmp->win, 0, (cols - (2 + strlen(title))) / 2, " %s ", title); |
|
172 |
|
173 list_add_tail(&tmp->list, &window_list); |
|
174 update_panels(); |
|
175 |
|
176 return tmp; |
|
177 } |
|
178 |
|
179 |
1
|
180 void scr_CreatePopup(char *title, char *texto, int corte, int type, |
|
181 char *returnstring) |
0
|
182 { |
|
183 WINDOW *popupWin; |
|
184 PANEL *popupPanel; |
|
185 |
|
186 int lineas = 0; |
|
187 int cols = 0; |
|
188 |
|
189 char **submsgs; |
|
190 int n = 0; |
|
191 int i; |
|
192 |
|
193 char *instr = (char *) calloc(1, 1024); |
|
194 |
|
195 /* fprintf(stderr, "\r\n%d", lineas); */ |
|
196 |
|
197 submsgs = ut_SplitMessage(texto, &n, corte); |
|
198 |
|
199 switch (type) { |
|
200 case 1: |
|
201 case 0: |
|
202 lineas = n + 4; |
|
203 break; |
|
204 } |
|
205 |
|
206 cols = corte + 3; |
|
207 popupWin = newwin(lineas, cols, (maxY - lineas) / 2, (maxX - cols) / 2); |
|
208 popupPanel = new_panel(popupWin); |
|
209 |
|
210 /*ATENCION!!! Colorear el popup ?? |
|
211 / box (popupWin, 0, 0); */ |
|
212 scr_draw_box(popupWin, 0, 0, lineas, cols, COLOR_POPUP, 0, 0); |
|
213 mvwprintw(popupWin, 0, (cols - (2 + strlen(title))) / 2, " %s ", title); |
|
214 |
|
215 for (i = 0; i < n; i++) |
|
216 mvwprintw(popupWin, i + 1, 2, "%s", submsgs[i]); |
|
217 |
|
218 |
|
219 for (i = 0; i < n; i++) |
|
220 free(submsgs[i]); |
|
221 free(submsgs); |
|
222 |
|
223 switch (type) { |
|
224 case 0: |
|
225 mvwprintw(popupWin, n + 2, |
|
226 (cols - (2 + strlen(i18n("Press any key")))) / 2, |
|
227 i18n("Press any key")); |
|
228 update_panels(); |
|
229 doupdate(); |
|
230 getch(); |
|
231 break; |
|
232 case 1: |
|
233 { |
|
234 char ch; |
|
235 int scroll = 0; |
|
236 int input_x = 0; |
|
237 |
|
238 wmove(popupWin, 3, 1); |
|
239 wrefresh(popupWin); |
|
240 keypad(popupWin, TRUE); |
|
241 while ((ch = getch()) != '\n') { |
|
242 switch (ch) { |
|
243 case 0x09: |
|
244 case KEY_UP: |
|
245 case KEY_DOWN: |
|
246 break; |
|
247 case KEY_RIGHT: |
|
248 case KEY_LEFT: |
|
249 break; |
|
250 case KEY_BACKSPACE: |
|
251 case 127: |
|
252 if (input_x || scroll) { |
|
253 /* wattrset (popupWin, 0); */ |
|
254 if (!input_x) { |
|
255 scroll = scroll < cols - 3 ? 0 : scroll - (cols - 3); |
|
256 wmove(popupWin, 3, 1); |
|
257 for (i = 0; i < cols; i++) |
|
258 waddch |
|
259 (popupWin, |
|
260 instr |
|
261 [scroll |
|
262 + input_x + i] ? instr[scroll + input_x + i] : ' '); |
|
263 input_x = strlen(instr) - scroll; |
|
264 } else |
|
265 input_x--; |
|
266 instr[scroll + input_x] = '\0'; |
|
267 mvwaddch(popupWin, 3, input_x + 1, ' '); |
|
268 wmove(popupWin, 3, input_x + 1); |
|
269 wrefresh(popupWin); |
|
270 } |
|
271 default: |
|
272 if ( /*ch<0x100 && */ isprint(ch) || ch == '�' |
|
273 || ch == '�') { |
|
274 if (scroll + input_x < 1024) { |
|
275 instr[scroll + input_x] = ch; |
|
276 instr[scroll + input_x + 1] = '\0'; |
|
277 if (input_x == cols - 3) { |
|
278 scroll++; |
|
279 wmove(popupWin, 3, 1); |
|
280 for (i = 0; i < cols - 3; i++) |
|
281 waddch(popupWin, instr[scroll + i]); |
|
282 } else { |
|
283 wmove(popupWin, 3, 1 + input_x++); |
|
284 waddch(popupWin, ch); |
|
285 } |
|
286 wrefresh(popupWin); |
|
287 } else { |
|
288 flash(); |
|
289 } |
|
290 } |
|
291 } |
|
292 } |
|
293 } |
|
294 if (returnstring != NULL) |
|
295 strcpy(returnstring, instr); |
|
296 break; |
|
297 } |
|
298 |
|
299 del_panel(popupPanel); |
|
300 delwin(popupWin); |
|
301 update_panels(); |
|
302 doupdate(); |
|
303 free(instr); |
2
|
304 keypad(inputWnd, TRUE); |
0
|
305 } |
|
306 |
|
307 |
|
308 |
|
309 void scr_RoolWindow(void) |
|
310 { |
|
311 } |
|
312 |
|
313 window_entry_t *scr_SearchWindow(char *nombreVentana) |
|
314 { |
|
315 struct list_head *pos, *n; |
|
316 window_entry_t *search_entry = NULL; |
|
317 |
|
318 list_for_each_safe(pos, n, &window_list) { |
|
319 search_entry = window_entry(pos); |
|
320 if (search_entry->name) { |
|
321 if (!strcasecmp(search_entry->name, nombreVentana)) { |
|
322 return search_entry; |
|
323 } |
|
324 } |
|
325 } |
|
326 return NULL; |
|
327 } |
|
328 |
|
329 void scr_ShowWindow(char *nombreVentana) |
|
330 { |
|
331 int n, width, i; |
|
332 window_entry_t *tmp = scr_SearchWindow(nombreVentana); |
|
333 if (tmp != NULL) { |
|
334 top_panel(tmp->panel); |
|
335 width = scr_WindowHeight(tmp->win); |
|
336 for (n = 0; n < tmp->nlines; n++) { |
|
337 mvwprintw(tmp->win, n + 1, 1, ""); |
|
338 for (i = 0; i < width - 2; i++) |
|
339 waddch(tmp->win, ' '); |
|
340 mvwprintw(tmp->win, n + 1, 1, "%s", tmp->texto[n]); |
|
341 } |
1
|
342 move(CHAT_WIN_HEIGHT - 1, maxX - 1); |
0
|
343 update_panels(); |
|
344 doupdate(); |
|
345 } |
|
346 } |
|
347 |
|
348 void scr_ShowBuddyWindow(void) |
|
349 { |
|
350 buddy_entry_t *tmp = bud_SelectedInfo(); |
|
351 if (tmp->jid != NULL) |
|
352 scr_ShowWindow(tmp->jid); |
|
353 } |
|
354 |
|
355 |
|
356 void scr_WriteInWindow(char *nombreVentana, char *texto, int TimeStamp) |
|
357 { |
|
358 time_t ahora; |
|
359 int n; |
|
360 int i; |
|
361 int width; |
|
362 window_entry_t *tmp; |
|
363 |
|
364 tmp = scr_SearchWindow(nombreVentana); |
|
365 if (tmp == NULL) { |
1
|
366 tmp = scr_CreatePanel(nombreVentana, 20, 0, CHAT_WIN_HEIGHT, maxX - 20); |
|
367 tmp->texto = (char **) calloc((CHAT_WIN_HEIGHT+1) * 3, sizeof(char *)); |
|
368 for (n = 0; n < CHAT_WIN_HEIGHT * 3; n++) |
0
|
369 tmp->texto[n] = (char *) calloc(1, 1024); |
|
370 |
|
371 if (TimeStamp) { |
|
372 ahora = time(NULL); |
|
373 strftime(tmp->texto[tmp->nlines], 1024, "[%H:%M] ", |
|
374 localtime(&ahora)); |
|
375 strcat(tmp->texto[tmp->nlines], texto); |
|
376 } else { |
|
377 sprintf(tmp->texto[tmp->nlines], " %s", texto); |
|
378 } |
|
379 tmp->nlines++; |
|
380 } else { |
1
|
381 if (tmp->nlines < CHAT_WIN_HEIGHT - 2) { |
0
|
382 if (TimeStamp) { |
|
383 ahora = time(NULL); |
|
384 strftime(tmp->texto[tmp->nlines], 1024, |
|
385 "[%H:%M] ", localtime(&ahora)); |
|
386 strcat(tmp->texto[tmp->nlines], texto); |
|
387 } else { |
|
388 sprintf(tmp->texto[tmp->nlines], " %s", texto); |
|
389 } |
|
390 tmp->nlines++; |
|
391 } else { |
|
392 for (n = 0; n < tmp->nlines; n++) { |
|
393 memset(tmp->texto[n], 0, 1024); |
|
394 strncpy(tmp->texto[n], tmp->texto[n + 1], 1024); |
|
395 } |
|
396 if (TimeStamp) { |
|
397 ahora = time(NULL); |
|
398 strftime(tmp->texto[tmp->nlines - 1], 1024, |
|
399 "[%H:%M] ", localtime(&ahora)); |
|
400 strcat(tmp->texto[tmp->nlines - 1], texto); |
|
401 } else { |
|
402 sprintf(tmp->texto[tmp->nlines - 1], " %s", texto); |
|
403 } |
|
404 } |
|
405 } |
|
406 |
|
407 top_panel(tmp->panel); |
|
408 width = scr_WindowHeight(tmp->win); |
|
409 for (n = 0; n < tmp->nlines; n++) { |
|
410 mvwprintw(tmp->win, n + 1, 1, ""); |
|
411 for (i = 0; i < width - 2; i++) |
|
412 waddch(tmp->win, ' '); |
|
413 mvwprintw(tmp->win, n + 1, 1, "%s", tmp->texto[n]); |
|
414 } |
|
415 |
|
416 update_panels(); |
|
417 doupdate(); |
|
418 } |
|
419 |
|
420 void scr_InitCurses(void) |
|
421 { |
|
422 initscr(); |
|
423 noecho(); |
|
424 raw(); |
2
|
425 //cbreak(); |
0
|
426 start_color(); |
|
427 use_default_colors(); |
|
428 |
|
429 ParseColors(); |
|
430 |
|
431 getmaxyx(stdscr, maxY, maxX); |
1
|
432 inputLine[0] = 0; |
|
433 ptr_inputline = inputLine; |
0
|
434 |
|
435 return; |
|
436 } |
|
437 |
|
438 void scr_DrawMainWindow(void) |
|
439 { |
1
|
440 /* Draw main panels */ |
0
|
441 rosterWnd = newwin(maxY-1, 20, 0, 0); |
|
442 rosterPanel = new_panel(rosterWnd); |
|
443 scr_draw_box(rosterWnd, 0, 0, maxY-1, 20, COLOR_GENERAL, 0, 0); |
|
444 mvwprintw(rosterWnd, 0, (20 - strlen(i18n("Roster"))) / 2, |
|
445 i18n("Roster")); |
|
446 |
1
|
447 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - 20, 0, 20); |
0
|
448 chatPanel = new_panel(chatWnd); |
1
|
449 scr_draw_box(chatWnd, 0, 0, CHAT_WIN_HEIGHT, maxX - 20, COLOR_GENERAL, 0, 0); |
0
|
450 mvwprintw(chatWnd, 0, |
|
451 ((maxX - 20) - strlen(i18n("Status Window"))) / 2, |
|
452 i18n("Status Window")); |
|
453 |
1
|
454 logWnd_border = newwin(LOG_WIN_HEIGHT, maxX - 20, CHAT_WIN_HEIGHT, 20); |
|
455 logPanel_border = new_panel(logWnd_border); |
|
456 scr_draw_box(logWnd_border, 0, 0, LOG_WIN_HEIGHT, maxX - 20, COLOR_GENERAL, 0, 0); |
|
457 // mvwprintw(logWnd_border, 0, |
|
458 // ((maxX - 20) - strlen(i18n("Log Window"))) / 2, |
|
459 // i18n("Log Window")); |
|
460 //logWnd = newwin(LOG_WIN_HEIGHT - 2, maxX-20 - 2, CHAT_WIN_HEIGHT+1, 20+1); |
|
461 logWnd = derwin(logWnd_border, LOG_WIN_HEIGHT-2, maxX-20-2, 1, 1); |
|
462 logPanel = new_panel(logWnd); |
|
463 wbkgd(logWnd, COLOR_PAIR(COLOR_GENERAL)); |
|
464 //wattrset(logWnd, COLOR_PAIR(COLOR_GENERAL)); |
|
465 wprintw(logWnd, "Here we are\n"); |
|
466 |
|
467 scrollok(logWnd,TRUE); |
|
468 idlok(logWnd,TRUE); // XXX Necessary? |
|
469 |
|
470 inputWnd = newwin(1, maxX, maxY-1, 0); |
|
471 inputPanel = new_panel(inputWnd); |
|
472 //wbkgd(inputWnd, COLOR_PAIR(COLOR_GENERAL)); |
|
473 |
0
|
474 bud_DrawRoster(rosterWnd); |
|
475 update_panels(); |
|
476 doupdate(); |
|
477 return; |
|
478 } |
|
479 |
|
480 void scr_TerminateCurses(void) |
|
481 { |
|
482 clear(); |
|
483 refresh(); |
|
484 endwin(); |
|
485 return; |
|
486 } |
|
487 |
|
488 void scr_WriteIncomingMessage(char *jidfrom, char *text) |
|
489 { |
|
490 char **submsgs; |
|
491 int n, i; |
|
492 char *buffer = (char *) malloc(5 + strlen(text)); |
|
493 |
|
494 sprintf(buffer, "<<< %s", text); |
|
495 |
|
496 submsgs = |
|
497 ut_SplitMessage(buffer, &n, maxX - scr_WindowHeight(rosterWnd) - 20); |
|
498 |
|
499 for (i = 0; i < n; i++) { |
|
500 if (i == 0) |
|
501 scr_WriteInWindow(jidfrom, submsgs[i], TRUE); |
|
502 else |
|
503 scr_WriteInWindow(jidfrom, submsgs[i], FALSE); |
|
504 } |
|
505 |
|
506 for (i = 0; i < n; i++) |
|
507 free(submsgs[i]); |
|
508 |
|
509 free(submsgs); |
|
510 free(buffer); |
|
511 |
2
|
512 top_panel(inputPanel); |
|
513 //wmove(inputWnd, 0, ptr_inputline - (char*)&inputLine); |
|
514 update_panels(); |
|
515 doupdate(); |
0
|
516 } |
|
517 |
|
518 void scr_WriteMessage(int sock) |
|
519 { |
|
520 char **submsgs; |
|
521 int n, i; |
|
522 char *buffer = (char *) calloc(1, 1024); |
|
523 char *buffer2 = (char *) calloc(1, 1024); |
|
524 buddy_entry_t *tmp = bud_SelectedInfo(); |
|
525 |
|
526 scr_ShowWindow(tmp->jid); |
|
527 |
|
528 ut_CenterMessage(i18n("write your message here"), 60, buffer2); |
|
529 |
|
530 scr_CreatePopup(tmp->jid, buffer2, 60, 1, buffer); |
|
531 |
|
532 if (strlen(buffer)) { |
|
533 sprintf(buffer2, ">>> %s", buffer); |
|
534 |
|
535 submsgs = |
|
536 ut_SplitMessage(buffer2, &n, |
|
537 maxX - scr_WindowHeight(rosterWnd) - 20); |
|
538 for (i = 0; i < n; i++) { |
|
539 if (i == 0) |
|
540 scr_WriteInWindow(tmp->jid, submsgs[i], TRUE); |
|
541 else |
|
542 scr_WriteInWindow(tmp->jid, submsgs[i], FALSE); |
|
543 } |
|
544 |
|
545 for (i = 0; i < n; i++) |
|
546 free(submsgs[i]); |
|
547 free(submsgs); |
|
548 |
1
|
549 move(CHAT_WIN_HEIGHT - 1, maxX - 1); |
0
|
550 refresh(); |
|
551 sprintf(buffer2, "%s@%s/%s", cfg_read("username"), |
|
552 cfg_read("server"), cfg_read("resource")); |
|
553 srv_sendtext(sock, tmp->jid, buffer, buffer2); |
|
554 } |
|
555 free(buffer); |
|
556 free(buffer2); |
|
557 } |
|
558 |
|
559 int scr_Getch(void) |
|
560 { |
|
561 int ch; |
2
|
562 // keypad(inputWnd, TRUE); |
|
563 ch = wgetch(inputWnd); |
0
|
564 return ch; |
|
565 } |
|
566 |
|
567 WINDOW *scr_GetRosterWindow(void) |
|
568 { |
|
569 return rosterWnd; |
|
570 } |
|
571 |
|
572 WINDOW *scr_GetStatusWindow(void) |
|
573 { |
|
574 return chatWnd; |
|
575 } |
1
|
576 |
2
|
577 WINDOW *scr_GetInputWindow(void) |
|
578 { |
|
579 return inputWnd; |
|
580 } |
|
581 |
|
582 void send_message(int sock, char *msg) |
|
583 { |
|
584 char **submsgs; |
|
585 char *buffer = (char *) calloc(1, 24+strlen(msg)); |
|
586 char *buffer2 = (char *) calloc(1, 1024); |
|
587 int n, i; |
|
588 buddy_entry_t *tmp = bud_SelectedInfo(); |
|
589 |
|
590 scr_ShowWindow(tmp->jid); |
|
591 |
|
592 sprintf(buffer, ">>> %s", msg); |
|
593 |
|
594 submsgs = |
|
595 ut_SplitMessage(buffer, &n, |
|
596 maxX - scr_WindowHeight(rosterWnd) - 20); |
|
597 for (i = 0; i < n; i++) { |
|
598 if (i == 0) |
|
599 scr_WriteInWindow(tmp->jid, submsgs[i], TRUE); |
|
600 else |
|
601 scr_WriteInWindow(tmp->jid, submsgs[i], FALSE); |
|
602 } |
|
603 |
|
604 for (i = 0; i < n; i++) |
|
605 free(submsgs[i]); |
|
606 free(submsgs); |
|
607 |
|
608 //move(CHAT_WIN_HEIGHT - 1, maxX - 1); |
|
609 refresh(); |
|
610 sprintf(buffer2, "%s@%s/%s", cfg_read("username"), |
|
611 cfg_read("server"), cfg_read("resource")); |
|
612 srv_sendtext(sock, tmp->jid, buffer, buffer2); |
|
613 free(buffer); |
|
614 free(buffer2); |
|
615 |
|
616 top_panel(inputPanel); |
|
617 } |
|
618 |
|
619 int process_line(char *line, int sock) |
|
620 { |
|
621 if (*line == 0) // XXX Simple checks should maybe be in process_key() |
|
622 return 0; |
|
623 if (*line != '/') { |
|
624 send_message(sock, line); |
|
625 return 0; |
|
626 } |
|
627 if (!strcasecmp(line, "/quit")) { |
|
628 return 255; |
|
629 } |
|
630 // Commands handling |
|
631 // TODO |
|
632 // say... |
|
633 wprintw(logWnd, "\nUnrecognised command, sorry."); |
|
634 return 0; |
|
635 } |
|
636 |
|
637 int process_key(int key, int sock) |
1
|
638 { |
|
639 if (isprint(key)) { |
|
640 char tmpLine[INPUTLINE_LENGTH]; |
|
641 strcpy(tmpLine, ptr_inputline); |
|
642 *ptr_inputline++ = key; |
|
643 strcpy(ptr_inputline, tmpLine); |
|
644 } else { |
|
645 switch(key) { |
|
646 case KEY_BACKSPACE: |
|
647 if (ptr_inputline != (char*)&inputLine) { |
|
648 *--ptr_inputline = 0; |
|
649 } |
|
650 break; |
2
|
651 case KEY_DC: |
|
652 if (*ptr_inputline) |
|
653 strcpy(ptr_inputline, ptr_inputline+1); |
|
654 break; |
1
|
655 case KEY_LEFT: |
|
656 if (ptr_inputline != (char*)&inputLine) { |
|
657 ptr_inputline--; |
|
658 } |
|
659 break; |
|
660 case KEY_RIGHT: |
|
661 if (*ptr_inputline) |
|
662 ptr_inputline++; |
|
663 break; |
|
664 case 9: // Tab |
|
665 wprintw(logWnd, "\nI'm unable to complete yet"); |
|
666 break; |
|
667 case '\n': // Enter |
|
668 // XXX Test: |
2
|
669 if (process_line(inputLine, sock)) |
1
|
670 return 255; |
|
671 ptr_inputline = inputLine; |
|
672 *ptr_inputline = 0; |
|
673 break; |
|
674 case KEY_UP: |
|
675 bud_RosterUp(); |
2
|
676 scr_ShowBuddyWindow(); |
1
|
677 break; |
|
678 case KEY_DOWN: |
|
679 bud_RosterDown(); |
2
|
680 scr_ShowBuddyWindow(); |
1
|
681 break; |
2
|
682 case KEY_PPAGE: |
|
683 wprintw(logWnd, "\nPageUp??"); |
|
684 break; |
|
685 case KEY_NPAGE: |
|
686 wprintw(logWnd, "\nPageDown??"); |
|
687 break; |
|
688 case KEY_HOME: |
|
689 case 1: |
|
690 ptr_inputline = inputLine; |
|
691 break; |
|
692 case KEY_END: |
|
693 case 5: |
|
694 for (; *ptr_inputline; ptr_inputline++) ; |
|
695 break; |
|
696 case 21: // Ctrl-u |
|
697 strcpy(inputLine, ptr_inputline); |
|
698 ptr_inputline = inputLine; |
|
699 break; |
|
700 case KEY_EOL: |
|
701 case 11: // Ctrl-k |
|
702 *ptr_inputline = 0; |
|
703 break; |
|
704 default: |
|
705 wprintw(logWnd, "\nUnkown key=%o", key); |
1
|
706 } |
2
|
707 //wprintw(logWnd, "\n[%02x]", key); |
1
|
708 } |
|
709 mvwprintw(inputWnd, 0,0, "%s", inputLine); |
|
710 wclrtoeol(inputWnd); |
|
711 if (*ptr_inputline) { |
|
712 wmove(inputWnd, 0, ptr_inputline - (char*)&inputLine); |
|
713 } |
|
714 update_panels(); |
|
715 doupdate(); |
|
716 return 0; |
|
717 } |