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