24
|
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 #include <locale.h>
|
|
9
|
|
10 #include "screen.h"
|
|
11 #include "utils.h"
|
|
12 #include "buddies.h"
|
|
13 #include "parsecfg.h"
|
|
14 #include "lang.h"
|
|
15 #include "list.h"
|
|
16
|
|
17 #define window_entry(n) list_entry(n, window_entry_t, list)
|
|
18
|
|
19 LIST_HEAD(window_list);
|
|
20
|
|
21 typedef struct _window_entry_t {
|
|
22 WINDOW *win;
|
|
23 PANEL *panel;
|
|
24 char *name;
|
|
25 int nlines;
|
|
26 char **texto;
|
|
27 int hidden_msg;
|
|
28 struct list_head list;
|
|
29 } window_entry_t;
|
|
30
|
|
31
|
|
32 /* Variables globales a SCREEN.C */
|
|
33 static WINDOW *rosterWnd, *chatWnd, *inputWnd;
|
|
34 static WINDOW *logWnd, *logWnd_border;
|
|
35 static PANEL *rosterPanel, *chatPanel, *inputPanel;
|
|
36 static PANEL *logPanel, *logPanel_border;
|
|
37 static int maxY, maxX;
|
|
38 static window_entry_t *currentWindow;
|
|
39
|
|
40 static int chatmode;
|
30
|
41 int update_roster;
|
24
|
42
|
|
43 static char inputLine[INPUTLINE_LENGTH+1];
|
|
44 static char *ptr_inputline;
|
|
45 static short int inputline_offset;
|
|
46
|
|
47
|
|
48 /* Funciones */
|
|
49
|
|
50 int scr_WindowHeight(WINDOW * win)
|
|
51 {
|
|
52 int x, y;
|
|
53 getmaxyx(win, y, x);
|
|
54 return x;
|
|
55 }
|
|
56
|
|
57 void scr_draw_box(WINDOW * win, int y, int x, int height, int width,
|
|
58 int Color, chtype box, chtype border)
|
|
59 {
|
|
60 int i, j;
|
|
61
|
|
62 wattrset(win, COLOR_PAIR(Color));
|
|
63 for (i = 0; i < height; i++) {
|
|
64 wmove(win, y + i, x);
|
|
65 for (j = 0; j < width; j++)
|
|
66 if (!i && !j)
|
|
67 waddch(win, border | ACS_ULCORNER);
|
|
68 else if (i == height - 1 && !j)
|
|
69 waddch(win, border | ACS_LLCORNER);
|
|
70 else if (!i && j == width - 1)
|
|
71 waddch(win, box | ACS_URCORNER);
|
|
72 else if (i == height - 1 && j == width - 1)
|
|
73 waddch(win, box | ACS_LRCORNER);
|
|
74 else if (!i)
|
|
75 waddch(win, border | ACS_HLINE);
|
|
76 else if (i == height - 1)
|
|
77 waddch(win, box | ACS_HLINE);
|
|
78 else if (!j)
|
|
79 waddch(win, border | ACS_VLINE);
|
|
80 else if (j == width - 1)
|
|
81 waddch(win, box | ACS_VLINE);
|
|
82 else
|
|
83 waddch(win, box | ' ');
|
|
84 }
|
|
85 }
|
|
86
|
|
87 int FindColor(char *name)
|
|
88 {
|
|
89 if (!strcmp(name, "default"))
|
|
90 return -1;
|
|
91 if (!strcmp(name, "black"))
|
|
92 return COLOR_BLACK;
|
|
93 if (!strcmp(name, "red"))
|
|
94 return COLOR_RED;
|
|
95 if (!strcmp(name, "green"))
|
|
96 return COLOR_GREEN;
|
|
97 if (!strcmp(name, "yellow"))
|
|
98 return COLOR_YELLOW;
|
|
99 if (!strcmp(name, "blue"))
|
|
100 return COLOR_BLUE;
|
|
101 if (!strcmp(name, "magenta"))
|
|
102 return COLOR_MAGENTA;
|
|
103 if (!strcmp(name, "cyan"))
|
|
104 return COLOR_CYAN;
|
|
105 if (!strcmp(name, "white"))
|
|
106 return COLOR_WHITE;
|
|
107
|
|
108 return -1;
|
|
109 }
|
|
110
|
|
111 void ParseColors(void)
|
|
112 {
|
|
113 char *colors[11] = {
|
|
114 "", "",
|
|
115 "borderlines",
|
|
116 "jidonlineselected",
|
|
117 "jidonline",
|
|
118 "jidofflineselected",
|
|
119 "jidoffline",
|
|
120 "text",
|
|
121 NULL
|
|
122 };
|
|
123
|
|
124 char *tmp = malloc(1024);
|
|
125 char *color1;
|
|
126 char *background = cfg_read("color_background");
|
|
127 char *backselected = cfg_read("color_backselected");
|
|
128 int i = 0;
|
|
129
|
|
130 while (colors[i]) {
|
|
131 sprintf(tmp, "color_%s", colors[i]);
|
|
132 color1 = cfg_read(tmp);
|
|
133
|
|
134 switch (i + 1) {
|
|
135 case 1:
|
|
136 init_pair(1, COLOR_BLACK, COLOR_WHITE);
|
|
137 break;
|
|
138 case 2:
|
|
139 init_pair(2, COLOR_WHITE, COLOR_BLACK);
|
|
140 break;
|
|
141 case 3:
|
|
142 init_pair(3, FindColor(color1), FindColor(background));
|
|
143 break;
|
|
144 case 4:
|
|
145 init_pair(4, FindColor(color1), FindColor(backselected));
|
|
146 break;
|
|
147 case 5:
|
|
148 init_pair(5, FindColor(color1), FindColor(background));
|
|
149 break;
|
|
150 case 6:
|
|
151 init_pair(6, FindColor(color1), FindColor(backselected));
|
|
152 break;
|
|
153 case 7:
|
|
154 init_pair(7, FindColor(color1), FindColor(background));
|
|
155 break;
|
|
156 case 8:
|
|
157 init_pair(8, FindColor(color1), FindColor(background));
|
|
158 break;
|
|
159 }
|
|
160 i++;
|
|
161 }
|
|
162 }
|
|
163
|
|
164
|
|
165 window_entry_t *scr_CreatePanel(char *title, int x, int y, int lines,
|
|
166 int cols, int dont_show)
|
|
167 {
|
|
168 window_entry_t *tmp = calloc(1, sizeof(window_entry_t));
|
|
169
|
|
170 tmp->win = newwin(lines, cols, y, x);
|
|
171 tmp->panel = new_panel(tmp->win);
|
|
172 tmp->name = (char *) calloc(1, 1024);
|
|
173 strncpy(tmp->name, title, 1024);
|
|
174
|
|
175 scr_draw_box(tmp->win, 0, 0, lines, cols, COLOR_GENERAL, 0, 0);
|
|
176 //mvwprintw(tmp->win, 0, (cols - (2 + strlen(title))) / 2, " %s ", title);
|
|
177 if ((!dont_show)) {
|
|
178 currentWindow = tmp;
|
|
179 } else {
|
|
180 if (currentWindow)
|
|
181 top_panel(currentWindow->panel);
|
|
182 else
|
|
183 top_panel(chatPanel);
|
|
184 }
|
|
185
|
|
186 list_add_tail(&tmp->list, &window_list);
|
|
187 update_panels();
|
|
188
|
|
189 return tmp;
|
|
190 }
|
|
191
|
|
192
|
|
193 void scr_CreatePopup(char *title, char *texto, int corte, int type,
|
|
194 char *returnstring)
|
|
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);
|
|
317 keypad(inputWnd, TRUE);
|
|
318 }
|
|
319
|
|
320 void scr_RoolWindow(void)
|
|
321 {
|
|
322 }
|
|
323
|
|
324 window_entry_t *scr_SearchWindow(char *winId)
|
|
325 {
|
|
326 struct list_head *pos, *n;
|
|
327 window_entry_t *search_entry = NULL;
|
|
328
|
|
329 list_for_each_safe(pos, n, &window_list) {
|
|
330 search_entry = window_entry(pos);
|
|
331 if (search_entry->name) {
|
|
332 if (!strcasecmp(search_entry->name, winId)) {
|
|
333 return search_entry;
|
|
334 }
|
|
335 }
|
|
336 }
|
|
337 return NULL;
|
|
338 }
|
|
339
|
|
340 void scr_ShowWindow(char *winId)
|
|
341 {
|
|
342 int n, width, i;
|
|
343 window_entry_t *tmp = scr_SearchWindow(winId);
|
|
344 if (tmp != NULL) {
|
|
345 top_panel(tmp->panel);
|
|
346 currentWindow = tmp;
|
|
347 chatmode = TRUE;
|
|
348 tmp->hidden_msg = FALSE;
|
30
|
349 update_roster = TRUE;
|
24
|
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 }
|
|
357 //move(CHAT_WIN_HEIGHT - 1, maxX - 1);
|
|
358 update_panels();
|
|
359 doupdate();
|
|
360 } else {
|
|
361 top_panel(chatPanel);
|
|
362 currentWindow = tmp;
|
|
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);
|
|
371 top_panel(inputPanel);
|
|
372 }
|
|
373
|
|
374
|
|
375 void scr_WriteInWindow(char *winId, char *texto, int TimeStamp, int force_show)
|
|
376 {
|
|
377 time_t ahora;
|
|
378 int n;
|
|
379 int i;
|
|
380 int width;
|
|
381 window_entry_t *tmp;
|
|
382 int dont_show = FALSE;
|
|
383
|
|
384
|
|
385 tmp = scr_SearchWindow(winId);
|
|
386
|
|
387 if (!chatmode)
|
|
388 dont_show = TRUE;
|
|
389 else if ((!force_show) && ((!currentWindow || (currentWindow != tmp))))
|
|
390 dont_show = TRUE;
|
|
391 // scr_LogPrint("dont_show=%d", dont_show);
|
|
392
|
|
393 if (tmp == NULL) {
|
|
394 tmp = scr_CreatePanel(winId, 20, 0, CHAT_WIN_HEIGHT, maxX - 20, dont_show);
|
|
395 tmp->texto = (char **) calloc((CHAT_WIN_HEIGHT+1) * 3, sizeof(char *));
|
|
396 for (n = 0; n < CHAT_WIN_HEIGHT * 3; n++)
|
|
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 {
|
|
409 if (tmp->nlines < CHAT_WIN_HEIGHT - 2) {
|
|
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
|
|
435 if (!dont_show) {
|
|
436 top_panel(tmp->panel);
|
|
437 width = scr_WindowHeight(tmp->win);
|
|
438 for (n = 0; n < tmp->nlines; n++) {
|
|
439 mvwprintw(tmp->win, n + 1, 1, "");
|
|
440 for (i = 0; i < width - 2; i++)
|
|
441 waddch(tmp->win, ' ');
|
|
442 mvwprintw(tmp->win, n + 1, 1, "%s", tmp->texto[n]);
|
|
443 }
|
|
444
|
|
445 update_panels();
|
|
446 doupdate();
|
|
447 } else {
|
|
448 tmp->hidden_msg = TRUE;
|
30
|
449 update_roster = TRUE;
|
24
|
450 }
|
|
451 }
|
|
452
|
|
453 void scr_InitCurses(void)
|
|
454 {
|
|
455 initscr();
|
|
456 noecho();
|
|
457 raw();
|
35
|
458 halfdelay(5);
|
24
|
459 start_color();
|
|
460 use_default_colors();
|
|
461
|
|
462 ParseColors();
|
|
463
|
|
464 getmaxyx(stdscr, maxY, maxX);
|
|
465 inputLine[0] = 0;
|
|
466 ptr_inputline = inputLine;
|
|
467
|
35
|
468 setlocale(LC_CTYPE, "");
|
24
|
469
|
|
470 return;
|
|
471 }
|
|
472
|
|
473 void scr_DrawMainWindow(void)
|
|
474 {
|
|
475 /* Draw main panels */
|
|
476 rosterWnd = newwin(CHAT_WIN_HEIGHT, 20, 0, 0);
|
|
477 rosterPanel = new_panel(rosterWnd);
|
|
478 scr_draw_box(rosterWnd, 0, 0, CHAT_WIN_HEIGHT, 20, COLOR_GENERAL, 0, 0);
|
|
479 mvwprintw(rosterWnd, 0, (20 - strlen(i18n("Roster"))) / 2,
|
|
480 i18n("Roster"));
|
|
481
|
|
482 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - 20, 0, 20);
|
|
483 chatPanel = new_panel(chatWnd);
|
|
484 scr_draw_box(chatWnd, 0, 0, CHAT_WIN_HEIGHT, maxX - 20, COLOR_GENERAL, 0, 0);
|
|
485 //mvwprintw(chatWnd, 0,
|
|
486 // ((maxX - 20) - strlen(i18n("Status Window"))) / 2,
|
|
487 // i18n("Status Window"));
|
|
488 //wbkgd(chatWnd, COLOR_PAIR(COLOR_GENERAL));
|
|
489 mvwprintw(chatWnd, 1, 1, "This is the status window");
|
|
490
|
|
491 logWnd_border = newwin(LOG_WIN_HEIGHT, maxX, CHAT_WIN_HEIGHT, 0);
|
|
492 logPanel_border = new_panel(logWnd_border);
|
|
493 scr_draw_box(logWnd_border, 0, 0, LOG_WIN_HEIGHT, maxX, COLOR_GENERAL, 0, 0);
|
|
494 // mvwprintw(logWnd_border, 0,
|
|
495 // ((maxX - 20) - strlen(i18n("Log Window"))) / 2,
|
|
496 // i18n("Log Window"));
|
|
497 //logWnd = newwin(LOG_WIN_HEIGHT - 2, maxX-20 - 2, CHAT_WIN_HEIGHT+1, 20+1);
|
|
498 logWnd = derwin(logWnd_border, LOG_WIN_HEIGHT-2, maxX-2, 1, 1);
|
|
499 logPanel = new_panel(logWnd);
|
|
500 wbkgd(logWnd, COLOR_PAIR(COLOR_GENERAL));
|
|
501 //wattrset(logWnd, COLOR_PAIR(COLOR_GENERAL));
|
|
502
|
|
503 scrollok(logWnd,TRUE);
|
|
504 //idlok(logWnd,TRUE); // XXX Necessary?
|
|
505
|
|
506 inputWnd = newwin(1, maxX, maxY-1, 0);
|
|
507 inputPanel = new_panel(inputWnd);
|
|
508 //wbkgd(inputWnd, COLOR_PAIR(COLOR_GENERAL));
|
|
509
|
|
510 bud_DrawRoster(rosterWnd);
|
|
511 update_panels();
|
|
512 doupdate();
|
|
513 return;
|
|
514 }
|
|
515
|
|
516 void scr_TerminateCurses(void)
|
|
517 {
|
|
518 clear();
|
|
519 refresh();
|
|
520 endwin();
|
|
521 return;
|
|
522 }
|
|
523
|
|
524 void scr_WriteIncomingMessage(char *jidfrom, char *text)
|
|
525 {
|
|
526 char **submsgs;
|
|
527 int n, i;
|
|
528 char *buffer = (char *) malloc(5 + strlen(text));
|
|
529
|
35
|
530 sprintf(buffer, "<== %s", utf8_decode(text));
|
24
|
531
|
|
532 submsgs =
|
|
533 ut_SplitMessage(buffer, &n, maxX - scr_WindowHeight(rosterWnd) - 20);
|
|
534
|
|
535 for (i = 0; i < n; i++) {
|
|
536 if (i == 0)
|
|
537 scr_WriteInWindow(jidfrom, submsgs[i], TRUE, FALSE);
|
|
538 else
|
|
539 scr_WriteInWindow(jidfrom, submsgs[i], FALSE, FALSE);
|
|
540 }
|
|
541
|
|
542 for (i = 0; i < n; i++)
|
|
543 free(submsgs[i]);
|
|
544
|
|
545 free(submsgs);
|
|
546 free(buffer);
|
|
547
|
|
548 top_panel(inputPanel);
|
|
549 //wmove(inputWnd, 0, ptr_inputline - (char*)&inputLine);
|
|
550 update_panels();
|
|
551 doupdate();
|
|
552 }
|
|
553
|
|
554 int scr_Getch(void)
|
|
555 {
|
|
556 int ch;
|
|
557 // keypad(inputWnd, TRUE);
|
|
558 ch = wgetch(inputWnd);
|
|
559 return ch;
|
|
560 }
|
|
561
|
|
562 WINDOW *scr_GetRosterWindow(void)
|
|
563 {
|
|
564 return rosterWnd;
|
|
565 }
|
|
566
|
|
567 WINDOW *scr_GetStatusWindow(void)
|
|
568 {
|
|
569 return chatWnd;
|
|
570 }
|
|
571
|
|
572 WINDOW *scr_GetInputWindow(void)
|
|
573 {
|
|
574 return inputWnd;
|
|
575 }
|
|
576
|
|
577 void scr_LogPrint(const char *fmt, ...)
|
|
578 {
|
|
579 time_t timestamp;
|
|
580 char *buffer;
|
|
581 va_list ap;
|
|
582
|
|
583 buffer = (char *) calloc(1, 4096);
|
|
584
|
|
585 timestamp = time(NULL);
|
|
586 strftime(buffer, 64, "[%H:%M:%S] ", localtime(×tamp));
|
|
587 wprintw(logWnd, "\n%s", buffer);
|
|
588
|
|
589 va_start(ap, fmt);
|
|
590 vsnprintf(buffer, 4096, fmt, ap);
|
|
591 va_end(ap);
|
|
592
|
|
593 wprintw(logWnd, "%s", buffer);
|
|
594 free(buffer);
|
|
595
|
|
596 update_panels();
|
|
597 doupdate();
|
|
598 }
|
|
599
|
|
600 // scr_IsHiddenMessage(jid)
|
|
601 // Returns TRUE if there is a hidden message in the window
|
|
602 // for the jid contact.
|
|
603 int scr_IsHiddenMessage(char *jid) {
|
|
604 window_entry_t *wintmp;
|
|
605
|
|
606 wintmp = scr_SearchWindow(jid);
|
|
607 if ((wintmp) && (wintmp->hidden_msg))
|
|
608 return TRUE;
|
|
609
|
|
610 return FALSE;
|
|
611 }
|
|
612
|
29
|
613 void send_message(char *msg)
|
24
|
614 {
|
|
615 char **submsgs;
|
|
616 char *buffer = (char *) calloc(1, 24+strlen(msg));
|
|
617 char *buffer2 = (char *) calloc(1, 1024);
|
|
618 int n, i;
|
|
619 buddy_entry_t *tmp = bud_SelectedInfo();
|
|
620
|
|
621 scr_ShowWindow(tmp->jid);
|
|
622
|
|
623 sprintf(buffer, "--> %s", msg);
|
|
624
|
|
625 submsgs =
|
|
626 ut_SplitMessage(buffer, &n,
|
|
627 maxX - scr_WindowHeight(rosterWnd) - 20);
|
|
628 for (i = 0; i < n; i++) {
|
|
629 if (i == 0)
|
|
630 scr_WriteInWindow(tmp->jid, submsgs[i], TRUE, TRUE);
|
|
631 else
|
|
632 scr_WriteInWindow(tmp->jid, submsgs[i], FALSE, TRUE);
|
|
633 }
|
|
634
|
|
635 for (i = 0; i < n; i++)
|
|
636 free(submsgs[i]);
|
|
637 free(submsgs);
|
|
638
|
|
639 //move(CHAT_WIN_HEIGHT - 1, maxX - 1);
|
|
640 refresh();
|
|
641 sprintf(buffer2, "%s@%s/%s", cfg_read("username"),
|
|
642 cfg_read("server"), cfg_read("resource"));
|
35
|
643 jb_send_msg(tmp->jid, utf8_encode(msg));
|
24
|
644 free(buffer);
|
|
645 free(buffer2);
|
|
646
|
|
647 top_panel(inputPanel);
|
|
648 }
|
|
649
|
29
|
650 int process_line(char *line)
|
24
|
651 {
|
|
652 if (*line != '/') {
|
35
|
653 send_message(line);
|
24
|
654 return 0;
|
|
655 }
|
|
656 if (!strcasecmp(line, "/quit")) {
|
|
657 return 255;
|
|
658 }
|
|
659 // Commands handling
|
|
660 // TODO
|
35
|
661 // say, send_raw...
|
24
|
662
|
|
663 scr_LogPrint("Unrecognised command, sorry.");
|
|
664 return 0;
|
|
665 }
|
|
666
|
|
667 // check_offset(int direction)
|
|
668 // Check inputline_offset value, and make sure the cursor is inside the
|
|
669 // screen.
|
|
670 inline void check_offset(int direction)
|
|
671 {
|
|
672 // Left side
|
|
673 if (inputline_offset && direction <= 0) {
|
|
674 while (ptr_inputline <= (char*)&inputLine + inputline_offset) {
|
|
675 if (inputline_offset) {
|
|
676 inputline_offset -= 5;
|
|
677 if (inputline_offset < 0)
|
|
678 inputline_offset = 0;
|
|
679 }
|
|
680 }
|
|
681 }
|
|
682 // Right side
|
|
683 if (direction >= 0) {
|
|
684 while (ptr_inputline >= inputline_offset + (char*)&inputLine + maxX)
|
|
685 inputline_offset += 5;
|
|
686 }
|
|
687 }
|
|
688
|
29
|
689 int process_key(int key)
|
24
|
690 {
|
|
691 if (isprint(key)) {
|
|
692 char tmpLine[INPUTLINE_LENGTH+1];
|
|
693
|
|
694 // Check the line isn't too long
|
|
695 if (strlen(inputLine) >= INPUTLINE_LENGTH)
|
|
696 return 0;
|
|
697
|
|
698 // Insert char
|
|
699 strcpy(tmpLine, ptr_inputline);
|
|
700 *ptr_inputline++ = key;
|
|
701 strcpy(ptr_inputline, tmpLine);
|
|
702 check_offset(1);
|
|
703 } else {
|
|
704 switch(key) {
|
|
705 case KEY_BACKSPACE:
|
|
706 if (ptr_inputline != (char*)&inputLine) {
|
|
707 *--ptr_inputline = 0;
|
|
708 check_offset(-1);
|
|
709 }
|
|
710 break;
|
|
711 case KEY_DC:
|
|
712 if (*ptr_inputline)
|
|
713 strcpy(ptr_inputline, ptr_inputline+1);
|
|
714 break;
|
|
715 case KEY_LEFT:
|
|
716 if (ptr_inputline != (char*)&inputLine) {
|
|
717 ptr_inputline--;
|
|
718 check_offset(-1);
|
|
719 }
|
|
720 break;
|
|
721 case KEY_RIGHT:
|
|
722 if (*ptr_inputline)
|
|
723 ptr_inputline++;
|
|
724 check_offset(1);
|
|
725 break;
|
|
726 case 9: // Tab
|
|
727 scr_LogPrint("I'm unable to complete yet");
|
|
728 break;
|
|
729 case '\n': // Enter
|
|
730 // XXX Test:
|
|
731 chatmode = TRUE;
|
|
732 if (inputLine[0] == 0) {
|
|
733 scr_ShowBuddyWindow();
|
|
734 break;
|
|
735 }
|
29
|
736 if (process_line(inputLine))
|
24
|
737 return 255;
|
|
738 ptr_inputline = inputLine;
|
|
739 *ptr_inputline = 0;
|
|
740 inputline_offset = 0;
|
|
741 break;
|
|
742 case KEY_UP:
|
|
743 bud_RosterUp();
|
|
744 if (chatmode)
|
|
745 scr_ShowBuddyWindow();
|
|
746 break;
|
|
747 case KEY_DOWN:
|
|
748 bud_RosterDown();
|
|
749 if (chatmode)
|
|
750 scr_ShowBuddyWindow();
|
|
751 break;
|
|
752 case KEY_PPAGE:
|
|
753 scr_LogPrint("PageUp??");
|
|
754 break;
|
|
755 case KEY_NPAGE:
|
|
756 scr_LogPrint("PageDown??");
|
|
757 break;
|
|
758 case KEY_HOME:
|
|
759 case 1:
|
|
760 ptr_inputline = inputLine;
|
|
761 inputline_offset = 0;
|
|
762 break;
|
|
763 case KEY_END:
|
|
764 case 5:
|
|
765 for (; *ptr_inputline; ptr_inputline++) ;
|
|
766 check_offset(1);
|
|
767 break;
|
|
768 case 21: // Ctrl-u
|
|
769 strcpy(inputLine, ptr_inputline);
|
|
770 ptr_inputline = inputLine;
|
|
771 inputline_offset = 0;
|
|
772 break;
|
|
773 case KEY_EOL:
|
|
774 case 11: // Ctrl-k
|
|
775 *ptr_inputline = 0;
|
|
776 break;
|
|
777 case 16: // Ctrl-p
|
|
778 scr_LogPrint("Ctrl-p not yet implemented");
|
|
779 break;
|
|
780 case 14: // Ctrl-n
|
|
781 scr_LogPrint("Ctrl-n not yet implemented");
|
|
782 break;
|
|
783 case 27: // ESC
|
|
784 currentWindow = NULL;
|
|
785 chatmode = FALSE;
|
|
786 top_panel(chatPanel);
|
|
787 top_panel(inputPanel);
|
|
788 break;
|
|
789 default:
|
|
790 scr_LogPrint("Unkown key=%d", key);
|
|
791 }
|
|
792 //scr_LogPrint("[%02x]", key);
|
|
793 }
|
|
794 mvwprintw(inputWnd, 0,0, "%s", inputLine + inputline_offset);
|
|
795 wclrtoeol(inputWnd);
|
|
796 if (*ptr_inputline) {
|
|
797 wmove(inputWnd, 0, ptr_inputline - (char*)&inputLine - inputline_offset);
|
|
798 }
|
|
799 update_panels();
|
|
800 doupdate();
|
|
801 return 0;
|
|
802 }
|