comparison mcabber/src/screen.c @ 47:7259a61e1a4b

[/trunk] Changeset 63 by mikael * Add commands.[ch] files, to deal with command lines. Move sendmessage() to commands.c * Update Makefile accordingly. * Create a scr_WriteMessage() function, layer between UI and the scr_WriteIncomingMessage() / scr_WriteOutgoingMessage(). (The last one is a new function)
author mikael
date Wed, 06 Apr 2005 10:07:59 +0000
parents c10f95f959d0
children 5425ee13dce6
comparison
equal deleted inserted replaced
46:f22e1d120606 47:7259a61e1a4b
7 #include <ctype.h> 7 #include <ctype.h>
8 #include <locale.h> 8 #include <locale.h>
9 9
10 #include "screen.h" 10 #include "screen.h"
11 #include "utils.h" 11 #include "utils.h"
12 #include "commands.h"
12 #include "buddies.h" 13 #include "buddies.h"
13 #include "parsecfg.h" 14 #include "parsecfg.h"
14 #include "lang.h" 15 #include "lang.h"
15 #include "list.h" 16 #include "list.h"
17 #include "utf8.h"
16 18
17 #define window_entry(n) list_entry(n, window_entry_t, list) 19 #define window_entry(n) list_entry(n, window_entry_t, list)
18 20
19 LIST_HEAD(window_list); 21 LIST_HEAD(window_list);
20 22
381 refresh(); 383 refresh();
382 endwin(); 384 endwin();
383 return; 385 return;
384 } 386 }
385 387
386 void scr_WriteIncomingMessage(char *jidfrom, char *text) 388 void scr_WriteMessage(char *jid, char *text, char *prefix)
387 { 389 {
388 char **submsgs; 390 char **submsgs;
389 int n, i; 391 int n, i;
390 char *buffer = (char *) malloc(5 + strlen(text)); 392 char *buffer = (char *) malloc(strlen(text) + strlen(text));
391 393
392 sprintf(buffer, "<== %s", utf8_decode(text)); 394 if (prefix)
395 strcpy(buffer, prefix);
396 else
397 *buffer = 0;
398
399 strcat(buffer, text);
393 400
394 submsgs = 401 submsgs =
395 ut_SplitMessage(buffer, &n, maxX - scr_WindowHeight(rosterWnd) - 14); 402 ut_SplitMessage(buffer, &n, maxX - scr_WindowHeight(rosterWnd) - 14);
396 403
397 for (i = 0; i < n; i++) { 404 for (i = 0; i < n; i++) {
398 if (i == 0) 405 if (i == 0)
399 scr_WriteInWindow(jidfrom, submsgs[i], TRUE, FALSE); 406 scr_WriteInWindow(jid, submsgs[i], TRUE, FALSE);
400 else 407 else
401 scr_WriteInWindow(jidfrom, submsgs[i], FALSE, FALSE); 408 scr_WriteInWindow(jid, submsgs[i], FALSE, FALSE);
402 } 409 }
403 410
404 for (i = 0; i < n; i++) 411 for (i = 0; i < n; i++)
405 free(submsgs[i]); 412 free(submsgs[i]);
406
407 free(submsgs); 413 free(submsgs);
408 free(buffer); 414 free(buffer);
409 415
410 top_panel(inputPanel); 416 top_panel(inputPanel);
411 //wmove(inputWnd, 0, ptr_inputline - (char*)&inputLine); 417 }
418
419 void scr_WriteIncomingMessage(char *jidfrom, char *text)
420 {
421 char *buffer = utf8_decode(text);
422 scr_WriteMessage(jidfrom, buffer, "<== ");
423 free(buffer);
412 update_panels(); 424 update_panels();
413 doupdate(); 425 doupdate();
426 }
427
428 void scr_WriteOutgoingMessage(char *jidto, char *text)
429 {
430 scr_ShowWindow(jidto);
431 scr_WriteMessage(jidto, text, "--> ");
432 //refresh(); // XXX ?
414 } 433 }
415 434
416 int scr_Getch(void) 435 int scr_Getch(void)
417 { 436 {
418 int ch; 437 int ch;
470 wintmp = scr_SearchWindow(jid); 489 wintmp = scr_SearchWindow(jid);
471 if ((wintmp) && (wintmp->hidden_msg)) 490 if ((wintmp) && (wintmp->hidden_msg))
472 return TRUE; 491 return TRUE;
473 492
474 return FALSE; 493 return FALSE;
475 }
476
477 // send_message(msg)
478 // Write the message in the buddy's window and send the message on
479 // the network.
480 void send_message(char *msg)
481 {
482 char **submsgs;
483 char *buffer = (char *) calloc(1, 24+strlen(msg));
484 char *buffer2 = (char *) calloc(1, 1024);
485 int n, i;
486 buddy_entry_t *tmp = bud_SelectedInfo();
487
488 scr_ShowWindow(tmp->jid);
489
490 sprintf(buffer, "--> %s", msg);
491
492 submsgs =
493 ut_SplitMessage(buffer, &n,
494 maxX - scr_WindowHeight(rosterWnd) - 14);
495 for (i = 0; i < n; i++) {
496 if (i == 0)
497 scr_WriteInWindow(tmp->jid, submsgs[i], TRUE, TRUE);
498 else
499 scr_WriteInWindow(tmp->jid, submsgs[i], FALSE, TRUE);
500 }
501
502 for (i = 0; i < n; i++)
503 free(submsgs[i]);
504 free(submsgs);
505
506 refresh();
507 sprintf(buffer2, "%s@%s/%s", cfg_read("username"),
508 cfg_read("server"), cfg_read("resource"));
509 jb_send_msg(tmp->jid, utf8_encode(msg));
510 free(buffer);
511 free(buffer2);
512
513 top_panel(inputPanel);
514 }
515
516 // process_line(line)
517 // Process the line *line. Note: if this isn't a command, this is a message
518 // and it is sent to the current buddy.
519 int process_line(char *line)
520 {
521 if (*line != '/') {
522 send_message(line);
523 return 0;
524 }
525 if (!strcasecmp(line, "/quit")) {
526 return 255;
527 }
528 // Commands handling
529 // TODO
530 // say, send_raw...
531
532 scr_LogPrint("Unrecognised command, sorry.");
533 return 0;
534 } 494 }
535 495
536 // check_offset(int direction) 496 // check_offset(int direction)
537 // Check inputline_offset value, and make sure the cursor is inside the 497 // Check inputline_offset value, and make sure the cursor is inside the
538 // screen. 498 // screen.