Mercurial > hg
comparison mcabber/src/screen.c @ 822:0dbb2be10975
Get rid of list.h
We use glib functions instead.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sun, 23 Apr 2006 11:21:24 +0200 |
parents | f6cda389db48 |
children | 37ef269330f0 |
comparison
equal
deleted
inserted
replaced
821:8c64874c449e | 822:0dbb2be10975 |
---|---|
36 #include "compl.h" | 36 #include "compl.h" |
37 #include "roster.h" | 37 #include "roster.h" |
38 #include "histolog.h" | 38 #include "histolog.h" |
39 #include "settings.h" | 39 #include "settings.h" |
40 #include "utils.h" | 40 #include "utils.h" |
41 #include "list.h" | 41 |
42 | |
43 #define window_entry(n) list_entry(n, window_entry_t, list) | |
44 #define get_color(col) (COLOR_PAIR(col)|COLOR_ATTRIB[col]) | 42 #define get_color(col) (COLOR_PAIR(col)|COLOR_ATTRIB[col]) |
45 | 43 |
46 #define DEFAULT_LOG_WIN_HEIGHT (5+2) | 44 #define DEFAULT_LOG_WIN_HEIGHT (5+2) |
47 #define DEFAULT_ROSTER_WIDTH 24 | 45 #define DEFAULT_ROSTER_WIDTH 24 |
48 #define CHAT_WIN_HEIGHT (maxY-1-Log_Win_Height) | 46 #define CHAT_WIN_HEIGHT (maxY-1-Log_Win_Height) |
52 static unsigned short int Log_Win_Height; | 50 static unsigned short int Log_Win_Height; |
53 static unsigned short int Roster_Width; | 51 static unsigned short int Roster_Width; |
54 | 52 |
55 static inline void check_offset(int); | 53 static inline void check_offset(int); |
56 | 54 |
57 LIST_HEAD(window_list); | 55 static GSList *winbuflst; |
58 | 56 |
59 typedef struct _window_entry_t { | 57 typedef struct { |
60 WINDOW *win; | 58 WINDOW *win; |
61 PANEL *panel; | 59 PANEL *panel; |
62 char *name; | 60 char *name; |
63 GList *hbuf; | 61 GList *hbuf; |
64 GList *top; // If top is NULL, we'll display the last lines | 62 GList *top; // If top is NULL, we'll display the last lines |
65 char cleared; // For ex, user has issued a /clear command... | 63 char cleared; // For ex, user has issued a /clear command... |
66 struct list_head list; | 64 } winbuf; |
67 } window_entry_t; | |
68 | 65 |
69 | 66 |
70 static WINDOW *rosterWnd, *chatWnd, *inputWnd, *logWnd; | 67 static WINDOW *rosterWnd, *chatWnd, *inputWnd, *logWnd; |
71 static WINDOW *mainstatusWnd, *chatstatusWnd; | 68 static WINDOW *mainstatusWnd, *chatstatusWnd; |
72 static PANEL *rosterPanel, *chatPanel, *inputPanel; | 69 static PANEL *rosterPanel, *chatPanel, *inputPanel; |
73 static PANEL *mainstatusPanel, *chatstatusPanel; | 70 static PANEL *mainstatusPanel, *chatstatusPanel; |
74 static PANEL *logPanel; | 71 static PANEL *logPanel; |
75 static int maxY, maxX; | 72 static int maxY, maxX; |
76 static window_entry_t *currentWindow; | 73 static winbuf *currentWindow; |
77 | 74 |
78 static int roster_hidden; | 75 static int roster_hidden; |
79 static int chatmode; | 76 static int chatmode; |
80 static int multimode; | 77 static int multimode; |
81 static char *multiline, *multimode_subj; | 78 static char *multiline, *multimode_subj; |
374 g_free(buffer2); | 371 g_free(buffer2); |
375 } | 372 } |
376 g_free(buffer); | 373 g_free(buffer); |
377 } | 374 } |
378 | 375 |
379 static window_entry_t *scr_CreateBuddyPanel(const char *title, int dont_show) | 376 static winbuf *scr_CreateBuddyPanel(const char *title, int dont_show) |
380 { | 377 { |
381 int x; | 378 int x; |
382 int y; | 379 int y; |
383 int lines; | 380 int lines; |
384 int cols; | 381 int cols; |
385 window_entry_t *tmp; | 382 winbuf *tmp; |
386 | 383 |
387 tmp = g_new0(window_entry_t, 1); | 384 tmp = g_new0(winbuf, 1); |
388 | 385 |
389 // Dimensions | 386 // Dimensions |
390 x = Roster_Width; | 387 x = Roster_Width; |
391 y = 0; | 388 y = 0; |
392 lines = CHAT_WIN_HEIGHT; | 389 lines = CHAT_WIN_HEIGHT; |
413 update_panels(); | 410 update_panels(); |
414 | 411 |
415 // Load buddy history from file (if enabled) | 412 // Load buddy history from file (if enabled) |
416 hlog_read_history(title, &tmp->hbuf, maxX - Roster_Width - PREFIX_WIDTH); | 413 hlog_read_history(title, &tmp->hbuf, maxX - Roster_Width - PREFIX_WIDTH); |
417 | 414 |
418 list_add_tail(&tmp->list, &window_list); | 415 winbuflst = g_slist_append(winbuflst, tmp); |
419 | |
420 return tmp; | 416 return tmp; |
421 } | 417 } |
422 | 418 |
423 static window_entry_t *scr_SearchWindow(const char *winId) | 419 static winbuf *scr_SearchWindow(const char *winId) |
424 { | 420 { |
425 struct list_head *pos, *n; | 421 GSList *wblp; |
426 window_entry_t *search_entry = NULL; | 422 winbuf *wbp; |
427 | 423 |
428 if (!winId) return NULL; | 424 if (!winId) return NULL; |
429 | 425 |
430 list_for_each_safe(pos, n, &window_list) { | 426 for (wblp = winbuflst; wblp; wblp = g_slist_next(wblp)) { |
431 search_entry = window_entry(pos); | 427 wbp = wblp->data; |
432 if (search_entry->name) { | 428 if (wbp->name) { |
433 if (!strcasecmp(search_entry->name, winId)) { | 429 if (!strcasecmp(wbp->name, winId)) |
434 return search_entry; | 430 return wbp; |
435 } | |
436 } | 431 } |
437 } | 432 } |
438 return NULL; | 433 return NULL; |
439 } | 434 } |
440 | 435 |
443 return (scr_SearchWindow(jid) != NULL); | 438 return (scr_SearchWindow(jid) != NULL); |
444 } | 439 } |
445 | 440 |
446 // scr_UpdateWindow() | 441 // scr_UpdateWindow() |
447 // (Re-)Display the given chat window. | 442 // (Re-)Display the given chat window. |
448 static void scr_UpdateWindow(window_entry_t *win_entry) | 443 static void scr_UpdateWindow(winbuf *win_entry) |
449 { | 444 { |
450 int n; | 445 int n; |
451 int width; | 446 int width; |
452 hbb_line **lines, *line; | 447 hbb_line **lines, *line; |
453 GList *hbuf_head; | 448 GList *hbuf_head; |
535 | 530 |
536 // scr_ShowWindow() | 531 // scr_ShowWindow() |
537 // Display the chat window with the given identifier. | 532 // Display the chat window with the given identifier. |
538 static void scr_ShowWindow(const char *winId) | 533 static void scr_ShowWindow(const char *winId) |
539 { | 534 { |
540 window_entry_t *win_entry = scr_SearchWindow(winId); | 535 winbuf *win_entry = scr_SearchWindow(winId); |
541 | 536 |
542 if (!win_entry) | 537 if (!win_entry) |
543 win_entry = scr_CreateBuddyPanel(winId, FALSE); | 538 win_entry = scr_CreateBuddyPanel(winId, FALSE); |
544 | 539 |
545 top_panel(win_entry->panel); | 540 top_panel(win_entry->panel); |
584 // Lines are splitted when they are too long to fit in the chat window. | 579 // Lines are splitted when they are too long to fit in the chat window. |
585 // If this window doesn't exist, it is created. | 580 // If this window doesn't exist, it is created. |
586 void scr_WriteInWindow(const char *winId, const char *text, time_t timestamp, | 581 void scr_WriteInWindow(const char *winId, const char *text, time_t timestamp, |
587 unsigned int prefix_flags, int force_show) | 582 unsigned int prefix_flags, int force_show) |
588 { | 583 { |
589 window_entry_t *win_entry; | 584 winbuf *win_entry; |
590 char *text_locale; | 585 char *text_locale; |
591 int dont_show = FALSE; | 586 int dont_show = FALSE; |
592 | 587 |
593 // Look for the window entry. | 588 // Look for the window entry. |
594 win_entry = scr_SearchWindow(winId); | 589 win_entry = scr_SearchWindow(winId); |
785 // Function called when the window is resized. | 780 // Function called when the window is resized. |
786 // - Resize windows | 781 // - Resize windows |
787 // - Rewrap lines in each buddy buffer | 782 // - Rewrap lines in each buddy buffer |
788 void scr_Resize() | 783 void scr_Resize() |
789 { | 784 { |
790 struct list_head *pos, *n; | |
791 window_entry_t *search_entry; | |
792 int x, y, lines, cols; | 785 int x, y, lines, cols; |
786 GSList *wblp; | |
787 winbuf *wbp; | |
793 | 788 |
794 // First, update the global variables | 789 // First, update the global variables |
795 getmaxyx(stdscr, maxY, maxX); | 790 getmaxyx(stdscr, maxY, maxX); |
796 // scr_DrawMainWindow() will take care of maxY and Log_Win_Height | 791 // scr_DrawMainWindow() will take care of maxY and Log_Win_Height |
797 | 792 |
806 y = 0; | 801 y = 0; |
807 lines = CHAT_WIN_HEIGHT; | 802 lines = CHAT_WIN_HEIGHT; |
808 cols = maxX - Roster_Width; | 803 cols = maxX - Roster_Width; |
809 if (cols < 1) cols = 1; | 804 if (cols < 1) cols = 1; |
810 | 805 |
811 list_for_each_safe(pos, n, &window_list) { | 806 for (wblp = winbuflst; wblp; wblp = g_slist_next(wblp)) { |
812 search_entry = window_entry(pos); | 807 wbp = wblp->data; |
813 if (search_entry->win) { | 808 if (wbp->win) { |
814 GList *rescue_top; | 809 GList *rescue_top; |
815 // Resize/move buddy window | 810 // Resize/move buddy window |
816 wresize(search_entry->win, lines, cols); | 811 wresize(wbp->win, lines, cols); |
817 mvwin(search_entry->win, 0, Roster_Width); | 812 mvwin(wbp->win, 0, Roster_Width); |
818 werase(search_entry->win); | 813 werase(wbp->win); |
819 // If a panel exists, replace the old window with the new | 814 // If a panel exists, replace the old window with the new |
820 if (search_entry->panel) { | 815 if (wbp->panel) |
821 replace_panel(search_entry->panel, search_entry->win); | 816 replace_panel(wbp->panel, wbp->win); |
822 } | |
823 // Redo line wrapping | 817 // Redo line wrapping |
824 rescue_top = hbuf_previous_persistent(search_entry->top); | 818 rescue_top = hbuf_previous_persistent(wbp->top); |
825 hbuf_rebuild(&search_entry->hbuf, | 819 hbuf_rebuild(&wbp->hbuf, maxX - Roster_Width - PREFIX_WIDTH); |
826 maxX - Roster_Width - PREFIX_WIDTH); | 820 if (g_list_position(g_list_first(wbp->hbuf), wbp->top) == -1) { |
827 if (g_list_position(g_list_first(search_entry->hbuf), | 821 wbp->top = rescue_top; |
828 search_entry->top) == -1) { | |
829 search_entry->top = rescue_top; | |
830 } | 822 } |
831 } | 823 } |
832 } | 824 } |
833 | 825 |
834 // Refresh current buddy window | 826 // Refresh current buddy window |
1338 // Scroll up/down the current buddy window, | 1330 // Scroll up/down the current buddy window, |
1339 // - half a screen if nblines is 0, | 1331 // - half a screen if nblines is 0, |
1340 // - up if updown == -1, down if updown == 1 | 1332 // - up if updown == -1, down if updown == 1 |
1341 void scr_BufferScrollUpDown(int updown, unsigned int nblines) | 1333 void scr_BufferScrollUpDown(int updown, unsigned int nblines) |
1342 { | 1334 { |
1343 window_entry_t *win_entry; | 1335 winbuf *win_entry; |
1344 int n, nbl; | 1336 int n, nbl; |
1345 GList *hbuf_top; | 1337 GList *hbuf_top; |
1346 | 1338 |
1347 // Get win_entry | 1339 // Get win_entry |
1348 if (!current_buddy) return; | 1340 if (!current_buddy) return; |
1391 | 1383 |
1392 // scr_BufferClear() | 1384 // scr_BufferClear() |
1393 // Clear the current buddy window (used for the /clear command) | 1385 // Clear the current buddy window (used for the /clear command) |
1394 void scr_BufferClear(void) | 1386 void scr_BufferClear(void) |
1395 { | 1387 { |
1396 window_entry_t *win_entry; | 1388 winbuf *win_entry; |
1397 | 1389 |
1398 // Get win_entry | 1390 // Get win_entry |
1399 if (!current_buddy) return; | 1391 if (!current_buddy) return; |
1400 win_entry = scr_SearchWindow(CURRENT_JID); | 1392 win_entry = scr_SearchWindow(CURRENT_JID); |
1401 if (!win_entry) return; | 1393 if (!win_entry) return; |
1402 | 1394 |
1403 win_entry->cleared = TRUE; | 1395 win_entry->cleared = TRUE; |
1404 win_entry->top = NULL; | 1396 win_entry->top = NULL; |
1405 | 1397 |
1414 // scr_BufferTopBottom() | 1406 // scr_BufferTopBottom() |
1415 // Jump to the head/tail of the current buddy window | 1407 // Jump to the head/tail of the current buddy window |
1416 // (top if topbottom == -1, bottom topbottom == 1) | 1408 // (top if topbottom == -1, bottom topbottom == 1) |
1417 void scr_BufferTopBottom(int topbottom) | 1409 void scr_BufferTopBottom(int topbottom) |
1418 { | 1410 { |
1419 window_entry_t *win_entry; | 1411 winbuf *win_entry; |
1420 | 1412 |
1421 // Get win_entry | 1413 // Get win_entry |
1422 if (!current_buddy) return; | 1414 if (!current_buddy) return; |
1423 win_entry = scr_SearchWindow(CURRENT_JID); | 1415 win_entry = scr_SearchWindow(CURRENT_JID); |
1424 if (!win_entry) return; | 1416 if (!win_entry) return; |
1425 | 1417 |
1426 win_entry->cleared = FALSE; | 1418 win_entry->cleared = FALSE; |
1427 if (topbottom == 1) | 1419 if (topbottom == 1) |
1428 win_entry->top = NULL; | 1420 win_entry->top = NULL; |
1440 // scr_BufferSearch(direction, text) | 1432 // scr_BufferSearch(direction, text) |
1441 // Jump to the next line containing text | 1433 // Jump to the next line containing text |
1442 // (backward search if direction == -1, forward if topbottom == 1) | 1434 // (backward search if direction == -1, forward if topbottom == 1) |
1443 void scr_BufferSearch(int direction, const char *text) | 1435 void scr_BufferSearch(int direction, const char *text) |
1444 { | 1436 { |
1445 window_entry_t *win_entry; | 1437 winbuf *win_entry; |
1446 GList *current_line, *search_res; | 1438 GList *current_line, *search_res; |
1447 | 1439 |
1448 // Get win_entry | 1440 // Get win_entry |
1449 if (!current_buddy) return; | 1441 if (!current_buddy) return; |
1450 win_entry = scr_SearchWindow(CURRENT_JID); | 1442 win_entry = scr_SearchWindow(CURRENT_JID); |
1451 if (!win_entry) return; | 1443 if (!win_entry) return; |
1452 | 1444 |
1453 if (win_entry->top) | 1445 if (win_entry->top) |
1454 current_line = win_entry->top; | 1446 current_line = win_entry->top; |
1455 else | 1447 else |
1473 | 1465 |
1474 // scr_BufferPercent(n) | 1466 // scr_BufferPercent(n) |
1475 // Jump to the specified position in the buffer, in % | 1467 // Jump to the specified position in the buffer, in % |
1476 void scr_BufferPercent(int pc) | 1468 void scr_BufferPercent(int pc) |
1477 { | 1469 { |
1478 window_entry_t *win_entry; | 1470 winbuf *win_entry; |
1479 GList *search_res; | 1471 GList *search_res; |
1480 | 1472 |
1481 // Get win_entry | 1473 // Get win_entry |
1482 if (!current_buddy) return; | 1474 if (!current_buddy) return; |
1483 win_entry = scr_SearchWindow(CURRENT_JID); | 1475 win_entry = scr_SearchWindow(CURRENT_JID); |
1484 if (!win_entry) return; | 1476 if (!win_entry) return; |
1485 | 1477 |
1486 if (pc < 0 || pc > 100) { | 1478 if (pc < 0 || pc > 100) { |
1487 scr_LogPrint(LPRINT_NORMAL, "Bad % value"); | 1479 scr_LogPrint(LPRINT_NORMAL, "Bad % value"); |
1488 return; | 1480 return; |
1504 // scr_BufferDate(t) | 1496 // scr_BufferDate(t) |
1505 // Jump to the first line after date t in the buffer | 1497 // Jump to the first line after date t in the buffer |
1506 // t is a date in seconds since `00:00:00 1970-01-01 UTC' | 1498 // t is a date in seconds since `00:00:00 1970-01-01 UTC' |
1507 void scr_BufferDate(time_t t) | 1499 void scr_BufferDate(time_t t) |
1508 { | 1500 { |
1509 window_entry_t *win_entry; | 1501 winbuf *win_entry; |
1510 GList *search_res; | 1502 GList *search_res; |
1511 | 1503 |
1512 // Get win_entry | 1504 // Get win_entry |
1513 if (!current_buddy) return; | 1505 if (!current_buddy) return; |
1514 win_entry = scr_SearchWindow(CURRENT_JID); | 1506 win_entry = scr_SearchWindow(CURRENT_JID); |
1515 if (!win_entry) return; | 1507 if (!win_entry) return; |
1516 | 1508 |
1517 search_res = hbuf_jump_date(win_entry->hbuf, t); | 1509 search_res = hbuf_jump_date(win_entry->hbuf, t); |
1518 | 1510 |
1519 win_entry->cleared = FALSE; | 1511 win_entry->cleared = FALSE; |