Mercurial > hg
comparison mcabber/src/screen.c @ 81:0bd578421ce9
[/trunk] Changeset 95 by mikael
* Switch from buddies.* to roster.*
Seems to work fine...
author | mikael |
---|---|
date | Sat, 16 Apr 2005 22:28:55 +0000 |
parents | a8f8492abd44 |
children | 134fe2567f07 |
comparison
equal
deleted
inserted
replaced
80:7fb661f19a77 | 81:0bd578421ce9 |
---|---|
6 #include <time.h> | 6 #include <time.h> |
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 "hbuf.h" |
12 #include "commands.h" | 12 #include "commands.h" |
13 #include "buddies.h" | 13 #include "roster.h" |
14 #include "parsecfg.h" | 14 #include "parsecfg.h" |
15 #include "lang.h" | 15 #include "lang.h" |
16 #include "utf8.h" | |
17 #include "utils.h" | |
16 #include "list.h" | 18 #include "list.h" |
17 #include "utf8.h" | |
18 #include "hbuf.h" | |
19 | 19 |
20 #define window_entry(n) list_entry(n, window_entry_t, list) | 20 #define window_entry(n) list_entry(n, window_entry_t, list) |
21 | 21 |
22 LIST_HEAD(window_list); | 22 LIST_HEAD(window_list); |
23 | 23 |
24 typedef struct _window_entry_t { | 24 typedef struct _window_entry_t { |
25 WINDOW *win; | 25 WINDOW *win; |
26 PANEL *panel; | 26 PANEL *panel; |
27 char *name; | 27 char *name; |
28 GList *hbuf; | 28 GList *hbuf; |
29 int hidden_msg; | |
30 struct list_head list; | 29 struct list_head list; |
31 } window_entry_t; | 30 } window_entry_t; |
32 | 31 |
33 | 32 |
34 /* Variables globales a SCREEN.C */ | 33 /* Variables globales a SCREEN.C */ |
200 update_panels(); | 199 update_panels(); |
201 | 200 |
202 return tmp; | 201 return tmp; |
203 } | 202 } |
204 | 203 |
205 void scr_RoolWindow(void) | |
206 { | |
207 } | |
208 | |
209 window_entry_t *scr_SearchWindow(const char *winId) | 204 window_entry_t *scr_SearchWindow(const char *winId) |
210 { | 205 { |
211 struct list_head *pos, *n; | 206 struct list_head *pos, *n; |
212 window_entry_t *search_entry = NULL; | 207 window_entry_t *search_entry = NULL; |
213 | 208 |
269 | 264 |
270 if (win_entry != NULL) { | 265 if (win_entry != NULL) { |
271 top_panel(win_entry->panel); | 266 top_panel(win_entry->panel); |
272 currentWindow = win_entry; | 267 currentWindow = win_entry; |
273 chatmode = TRUE; | 268 chatmode = TRUE; |
274 win_entry->hidden_msg = FALSE; | 269 roster_setflags(winId, ROSTER_FLAG_MSG, FALSE); |
275 update_roster = TRUE; | 270 update_roster = TRUE; |
276 | 271 |
277 // Refresh the window entry | 272 // Refresh the window entry |
278 scr_UpdateWindow(win_entry); | 273 scr_UpdateWindow(win_entry); |
279 | 274 |
286 } | 281 } |
287 } | 282 } |
288 | 283 |
289 void scr_ShowBuddyWindow(void) | 284 void scr_ShowBuddyWindow(void) |
290 { | 285 { |
291 buddy_entry_t *tmp = bud_SelectedInfo(); | 286 const gchar *jid = CURRENT_JID; |
292 if (tmp->jid != NULL) | 287 if (jid != NULL) |
293 scr_ShowWindow(tmp->jid); | 288 scr_ShowWindow(jid); |
294 top_panel(inputPanel); | 289 top_panel(inputPanel); |
295 } | 290 } |
296 | 291 |
297 | 292 |
298 void scr_WriteInWindow(const char *winId, const char *text, int TimeStamp, | 293 void scr_WriteInWindow(const char *winId, const char *text, int TimeStamp, |
339 top_panel(win_entry->panel); | 334 top_panel(win_entry->panel); |
340 scr_UpdateWindow(win_entry); | 335 scr_UpdateWindow(win_entry); |
341 update_panels(); | 336 update_panels(); |
342 doupdate(); | 337 doupdate(); |
343 } else { | 338 } else { |
344 win_entry->hidden_msg = TRUE; | 339 roster_setflags(winId, ROSTER_FLAG_MSG, TRUE); |
345 update_roster = TRUE; | 340 update_roster = TRUE; |
346 } | 341 } |
347 } | 342 } |
348 | 343 |
349 void scr_InitCurses(void) | 344 void scr_InitCurses(void) |
361 inputLine[0] = 0; | 356 inputLine[0] = 0; |
362 ptr_inputline = inputLine; | 357 ptr_inputline = inputLine; |
363 | 358 |
364 setlocale(LC_CTYPE, ""); | 359 setlocale(LC_CTYPE, ""); |
365 | 360 |
361 return; | |
362 } | |
363 | |
364 void scr_TerminateCurses(void) | |
365 { | |
366 clear(); | |
367 refresh(); | |
368 endwin(); | |
366 return; | 369 return; |
367 } | 370 } |
368 | 371 |
369 void scr_DrawMainWindow(void) | 372 void scr_DrawMainWindow(void) |
370 { | 373 { |
395 scrollok(logWnd, TRUE); | 398 scrollok(logWnd, TRUE); |
396 | 399 |
397 inputWnd = newwin(1, maxX, maxY-1, 0); | 400 inputWnd = newwin(1, maxX, maxY-1, 0); |
398 inputPanel = new_panel(inputWnd); | 401 inputPanel = new_panel(inputWnd); |
399 | 402 |
400 bud_DrawRoster(rosterWnd); | 403 scr_DrawRoster(); |
401 update_panels(); | 404 update_panels(); |
402 doupdate(); | 405 doupdate(); |
403 return; | 406 return; |
404 } | 407 } |
405 | 408 |
406 void scr_TerminateCurses(void) | 409 void scr_DrawRoster(void) |
407 { | 410 { |
408 clear(); | 411 static guint offset = 0; |
409 refresh(); | 412 char name[ROSTER_WIDTH]; |
410 endwin(); | 413 int maxx, maxy; |
411 return; | 414 GList *buddy; |
415 int i, n; | |
416 int rOffset; | |
417 | |
418 getmaxyx(rosterWnd, maxy, maxx); | |
419 maxx --; // last char is for vertical border | |
420 name[ROSTER_WIDTH-7] = 0; | |
421 | |
422 // cleanup of roster window | |
423 wattrset(rosterWnd, COLOR_PAIR(COLOR_GENERAL)); | |
424 for (i = 0; i < maxy; i++) { | |
425 mvwprintw(rosterWnd, i, 0, ""); | |
426 for (n = 0; n < maxx; n++) | |
427 waddch(rosterWnd, ' '); | |
428 } | |
429 | |
430 // Leave now if buddylist is empty | |
431 if (!buddylist) { | |
432 offset = 0; | |
433 return; | |
434 } | |
435 | |
436 // TODO: update offset if necessary | |
437 | |
438 buddy = buddylist; | |
439 rOffset = offset; | |
440 | |
441 for (i=0; i<maxy && buddy; i++, buddy = g_list_next(buddy)) { | |
442 | |
443 char status = '?'; | |
444 char pending = ' '; | |
445 enum imstatus budstate; | |
446 | |
447 if (rOffset > 0) { | |
448 rOffset--; | |
449 continue; | |
450 } | |
451 | |
452 if (buddy_getflags(BUDDATA(buddy)) & ROSTER_FLAG_MSG) { | |
453 pending = '#'; | |
454 } | |
455 | |
456 budstate = buddy_getstatus(BUDDATA(buddy)); | |
457 if (budstate >= 0 && budstate < imstatus_size) | |
458 status = imstatus2char[budstate]; | |
459 if (buddy == current_buddy) { | |
460 wattrset(rosterWnd, COLOR_PAIR(COLOR_BD_DESSEL)); | |
461 // The 3 following lines aim to color the whole line | |
462 wmove(rosterWnd, i, 0); | |
463 for (n = 0; n < maxx; n++) | |
464 waddch(rosterWnd, ' '); | |
465 } else { | |
466 wattrset(rosterWnd, COLOR_PAIR(COLOR_BD_DES)); | |
467 } | |
468 | |
469 strncpy(name, buddy_getname(BUDDATA(buddy)), ROSTER_WIDTH-7); | |
470 // TODO: status is meaningless for groups: | |
471 if (buddy_gettype(BUDDATA(buddy)) & ROSTER_TYPE_GROUP) status='G'; | |
472 mvwprintw(rosterWnd, i, 0, " %c[%c] %s", pending, status, name); | |
473 } | |
474 | |
475 update_panels(); | |
476 doupdate(); | |
477 update_roster = FALSE; | |
412 } | 478 } |
413 | 479 |
414 void scr_WriteMessage(const char *jid, const char *text, char *prefix) | 480 void scr_WriteMessage(const char *jid, const char *text, char *prefix) |
415 { | 481 { |
416 scr_WriteInWindow(jid, text, TRUE, prefix, FALSE); | 482 scr_WriteInWindow(jid, text, TRUE, prefix, FALSE); |
455 WINDOW *scr_GetInputWindow(void) | 521 WINDOW *scr_GetInputWindow(void) |
456 { | 522 { |
457 return inputWnd; | 523 return inputWnd; |
458 } | 524 } |
459 | 525 |
526 void scr_RosterUp() | |
527 { | |
528 if (current_buddy) { | |
529 if (g_list_previous(current_buddy)) { | |
530 current_buddy = g_list_previous(current_buddy); | |
531 scr_DrawRoster(); | |
532 } | |
533 } | |
534 // XXX We should rebuild the buddylist but perhaps not everytime? | |
535 } | |
536 | |
537 void scr_RosterDown() | |
538 { | |
539 if (current_buddy) { | |
540 if (g_list_next(current_buddy)) { | |
541 current_buddy = g_list_next(current_buddy); | |
542 scr_DrawRoster(); | |
543 } | |
544 } | |
545 // XXX We should rebuild the buddylist but perhaps not everytime? | |
546 } | |
547 | |
460 // scr_LogPrint(...) | 548 // scr_LogPrint(...) |
461 // Display a message in the log window. | 549 // Display a message in the log window. |
462 void scr_LogPrint(const char *fmt, ...) | 550 void scr_LogPrint(const char *fmt, ...) |
463 { | 551 { |
464 time_t timestamp; | 552 time_t timestamp; |
478 wprintw(logWnd, "%s", buffer); | 566 wprintw(logWnd, "%s", buffer); |
479 free(buffer); | 567 free(buffer); |
480 | 568 |
481 update_panels(); | 569 update_panels(); |
482 doupdate(); | 570 doupdate(); |
483 } | |
484 | |
485 // scr_IsHiddenMessage(jid) | |
486 // Returns TRUE if there is a hidden message in the window | |
487 // for the jid contact. | |
488 int scr_IsHiddenMessage(const char *jid) { | |
489 window_entry_t *wintmp; | |
490 | |
491 wintmp = scr_SearchWindow(jid); | |
492 if ((wintmp) && (wintmp->hidden_msg)) | |
493 return TRUE; | |
494 | |
495 return FALSE; | |
496 } | 571 } |
497 | 572 |
498 // check_offset(int direction) | 573 // check_offset(int direction) |
499 // Check inputline_offset value, and make sure the cursor is inside the | 574 // Check inputline_offset value, and make sure the cursor is inside the |
500 // screen. | 575 // screen. |
572 ptr_inputline = inputLine; | 647 ptr_inputline = inputLine; |
573 *ptr_inputline = 0; | 648 *ptr_inputline = 0; |
574 inputline_offset = 0; | 649 inputline_offset = 0; |
575 break; | 650 break; |
576 case KEY_UP: | 651 case KEY_UP: |
577 bud_RosterUp(); | 652 scr_RosterUp(); |
578 if (chatmode) | 653 if (chatmode) |
579 scr_ShowBuddyWindow(); | 654 scr_ShowBuddyWindow(); |
580 break; | 655 break; |
581 case KEY_DOWN: | 656 case KEY_DOWN: |
582 bud_RosterDown(); | 657 scr_RosterDown(); |
583 if (chatmode) | 658 if (chatmode) |
584 scr_ShowBuddyWindow(); | 659 scr_ShowBuddyWindow(); |
585 break; | 660 break; |
586 case KEY_PPAGE: | 661 case KEY_PPAGE: |
587 scr_LogPrint("PageUp??"); | 662 scr_LogPrint("PageUp??"); |