comparison mcabber/src/screen.c @ 1483:e74cc83e7158

Refactor scr_UpdateWindow()
author Mikael Berthe <mikael@lilotux.net>
date Sun, 20 Apr 2008 11:45:01 +0200
parents 77afd831f8f7
children 7b36b91a4388
comparison
equal deleted inserted replaced
1482:f16b280e70d4 1483:e74cc83e7158
988 tmp->bd = g_new0(buffdata, 1); 988 tmp->bd = g_new0(buffdata, 1);
989 } 989 }
990 return tmp; 990 return tmp;
991 } 991 }
992 992
993 // scr_line_prefix(line, pref, preflen)
994 // Use data from the hbb_line structure and write the prefix
995 // to pref (not exceeding preflen, trailing null byte included).
996 void scr_line_prefix(hbb_line *line, char *pref, guint preflen)
997 {
998 char date[64];
999
1000 if (line->timestamp &&
1001 !(line->flags & (HBB_PREFIX_SPECIAL|HBB_PREFIX_CONT))) {
1002 strftime(date, 30, gettprefix(), localtime(&line->timestamp));
1003 } else
1004 strcpy(date, " ");
1005
1006 if (!(line->flags & HBB_PREFIX_CONT)) {
1007 if (line->flags & HBB_PREFIX_INFO) {
1008 char dir = '*';
1009 if (line->flags & HBB_PREFIX_IN)
1010 dir = '<';
1011 else if (line->flags & HBB_PREFIX_OUT)
1012 dir = '>';
1013 g_snprintf(pref, preflen, "%s*%c* ", date, dir);
1014 } else if (line->flags & HBB_PREFIX_ERR) {
1015 char dir = '#';
1016 if (line->flags & HBB_PREFIX_IN)
1017 dir = '<';
1018 else if (line->flags & HBB_PREFIX_OUT)
1019 dir = '>';
1020 g_snprintf(pref, preflen, "%s#%c# ", date, dir);
1021 } else if (line->flags & HBB_PREFIX_IN) {
1022 char cryptflag = line->flags & HBB_PREFIX_PGPCRYPT ? '~' : '=';
1023 g_snprintf(pref, preflen, "%s<%c= ", date, cryptflag);
1024 } else if (line->flags & HBB_PREFIX_OUT) {
1025 char cryptflag = line->flags & HBB_PREFIX_PGPCRYPT ? '~' : '-';
1026 g_snprintf(pref, preflen, "%s-%c> ", date, cryptflag);
1027 } else if (line->flags & HBB_PREFIX_SPECIAL) {
1028 strftime(date, 30, getspectprefix(), localtime(&line->timestamp));
1029 g_snprintf(pref, preflen, "%s ", date);
1030 } else {
1031 g_snprintf(pref, preflen, "%s ", date);
1032 }
1033 } else {
1034 g_snprintf(pref, preflen, " ");
1035 }
1036 }
1037
993 // scr_UpdateWindow() 1038 // scr_UpdateWindow()
994 // (Re-)Display the given chat window. 1039 // (Re-)Display the given chat window.
995 static void scr_UpdateWindow(winbuf *win_entry) 1040 static void scr_UpdateWindow(winbuf *win_entry)
996 { 1041 {
997 int n; 1042 int n;
998 int width, prefixwidth; 1043 int width, prefixwidth;
1044 char pref[96];
999 hbb_line **lines, *line; 1045 hbb_line **lines, *line;
1000 GList *hbuf_head; 1046 GList *hbuf_head;
1001 char date[64];
1002 int color; 1047 int color;
1003 1048
1004 width = getmaxx(win_entry->win); 1049 width = getmaxx(win_entry->win);
1005 prefixwidth = getprefixwidth(); 1050 prefixwidth = getprefixwidth();
1006 1051
1052 color = COLOR_GENERAL; 1097 color = COLOR_GENERAL;
1053 1098
1054 if (color != COLOR_GENERAL) 1099 if (color != COLOR_GENERAL)
1055 wattrset(win_entry->win, get_color(color)); 1100 wattrset(win_entry->win, get_color(color));
1056 1101
1057 if (line->timestamp && 1102 // Generate the prefix area and display it
1058 !(line->flags & (HBB_PREFIX_SPECIAL|HBB_PREFIX_CONT))) { 1103 scr_line_prefix(line, pref, sizeof pref);
1059 strftime(date, 30, gettprefix(), localtime(&line->timestamp)); 1104 wprintw(win_entry->win, pref);
1060 } else
1061 strcpy(date, " ");
1062 if (!(line->flags & HBB_PREFIX_CONT)) {
1063 if (line->flags & HBB_PREFIX_INFO) {
1064 char dir = '*';
1065 if (line->flags & HBB_PREFIX_IN)
1066 dir = '<';
1067 else if (line->flags & HBB_PREFIX_OUT)
1068 dir = '>';
1069 wprintw(win_entry->win, "%s*%c* ", date, dir);
1070 } else if (line->flags & HBB_PREFIX_ERR) {
1071 char dir = '#';
1072 if (line->flags & HBB_PREFIX_IN)
1073 dir = '<';
1074 else if (line->flags & HBB_PREFIX_OUT)
1075 dir = '>';
1076 wprintw(win_entry->win, "%s#%c# ", date, dir);
1077 } else if (line->flags & HBB_PREFIX_IN) {
1078 char cryptflag = line->flags & HBB_PREFIX_PGPCRYPT ? '~' : '=';
1079 wprintw(win_entry->win, "%s<%c= ", date, cryptflag);
1080 } else if (line->flags & HBB_PREFIX_OUT) {
1081 char cryptflag = line->flags & HBB_PREFIX_PGPCRYPT ? '~' : '-';
1082 wprintw(win_entry->win, "%s-%c> ", date, cryptflag);
1083 } else if (line->flags & HBB_PREFIX_SPECIAL) {
1084 strftime(date, 30, getspectprefix(), localtime(&line->timestamp));
1085 wprintw(win_entry->win, "%s ", date);
1086 } else {
1087 wprintw(win_entry->win, "%s ", date);
1088 }
1089 } else {
1090 wprintw(win_entry->win, " " );
1091 }
1092 1105
1093 // Make sure we are at the right position 1106 // Make sure we are at the right position
1094 wmove(win_entry->win, n, prefixwidth-1); 1107 wmove(win_entry->win, n, prefixwidth-1);
1095 1108
1096 // The MUC nick - overwrite with proper color 1109 // The MUC nick - overwrite with proper color
1149 wclrtoeol(win_entry->win); 1162 wclrtoeol(win_entry->win);
1150 1163
1151 // Return the color back 1164 // Return the color back
1152 if (color != COLOR_GENERAL) 1165 if (color != COLOR_GENERAL)
1153 wattrset(win_entry->win, get_color(COLOR_GENERAL)); 1166 wattrset(win_entry->win, get_color(COLOR_GENERAL));
1167
1154 g_free(line->text); 1168 g_free(line->text);
1155 g_free(line); 1169 g_free(line);
1156 } else { 1170 } else {
1157 wclrtobot(win_entry->win); 1171 wclrtobot(win_entry->win);
1158 break; 1172 break;