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