Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/screen.c @ 981:553b8ecf901f
Fixes truncating of utf-8 buddy names (again)
This patch fixes the problem with utf-8 buddy names,
which include multibyte characters. This patch version
(maybe) fixes issue for utf-8 locales too.
author | Myhailo Danylenko <isbear@ukrpost.net> |
---|---|
date | Sun, 22 Oct 2006 20:27:28 +0200 |
parents | 023891f99732 |
children | ed697234bd39 |
comparison
equal
deleted
inserted
replaced
980:023891f99732 | 981:553b8ecf901f |
---|---|
1133 update_panels(); | 1133 update_panels(); |
1134 curs_set(cursor_backup); | 1134 curs_set(cursor_backup); |
1135 return; | 1135 return; |
1136 } | 1136 } |
1137 | 1137 |
1138 name = g_new0(char, Roster_Width); | |
1139 | |
1140 // Update offset if necessary | 1138 // Update offset if necessary |
1141 // a) Try to show as many buddylist items as possible | 1139 // a) Try to show as many buddylist items as possible |
1142 i = g_list_length(buddylist) - maxy; | 1140 i = g_list_length(buddylist) - maxy; |
1143 if (i < 0) | 1141 if (i < 0) |
1144 i = 0; | 1142 i = 0; |
1146 offset = i; | 1144 offset = i; |
1147 // b) Make sure the current_buddy is visible | 1145 // b) Make sure the current_buddy is visible |
1148 i = g_list_position(buddylist, current_buddy); | 1146 i = g_list_position(buddylist, current_buddy); |
1149 if (i == -1) { // This is bad | 1147 if (i == -1) { // This is bad |
1150 scr_LogPrint(LPRINT_NORMAL, "Doh! Can't find current selected buddy!!"); | 1148 scr_LogPrint(LPRINT_NORMAL, "Doh! Can't find current selected buddy!!"); |
1151 g_free(name); | |
1152 curs_set(cursor_backup); | 1149 curs_set(cursor_backup); |
1153 return; | 1150 return; |
1154 } else if (i < offset) { | 1151 } else if (i < offset) { |
1155 offset = i; | 1152 offset = i; |
1156 } else if (i+1 > offset + maxy) { | 1153 } else if (i+1 > offset + maxy) { |
1160 if (roster_win_on_right) | 1157 if (roster_win_on_right) |
1161 x_pos = 1; // 1 char offset (vertical line) | 1158 x_pos = 1; // 1 char offset (vertical line) |
1162 else | 1159 else |
1163 x_pos = 0; | 1160 x_pos = 0; |
1164 | 1161 |
1165 rline = g_new0(char, Roster_Width+1); | 1162 name = g_new0(char, 4*Roster_Width); |
1163 rline = g_new0(char, 4*Roster_Width+1); | |
1166 | 1164 |
1167 buddy = buddylist; | 1165 buddy = buddylist; |
1168 rOffset = offset; | 1166 rOffset = offset; |
1169 | 1167 |
1170 for (i=0; i<maxy && buddy; buddy = g_list_next(buddy)) { | 1168 for (i=0; i<maxy && buddy; buddy = g_list_next(buddy)) { |
1171 unsigned short bflags, btype, ismsg, isgrp, ismuc, ishid, isspe; | 1169 unsigned short bflags, btype, ismsg, isgrp, ismuc, ishid, isspe; |
1172 gchar *name_locale; | 1170 gchar *rline_locale; |
1173 | 1171 |
1174 bflags = buddy_getflags(BUDDATA(buddy)); | 1172 bflags = buddy_getflags(BUDDATA(buddy)); |
1175 btype = buddy_gettype(BUDDATA(buddy)); | 1173 btype = buddy_gettype(BUDDATA(buddy)); |
1176 | 1174 |
1177 ismsg = bflags & ROSTER_FLAG_MSG; | 1175 ismsg = bflags & ROSTER_FLAG_MSG; |
1219 wattrset(rosterWnd, get_color(COLOR_ROSTERNMSG)); | 1217 wattrset(rosterWnd, get_color(COLOR_ROSTERNMSG)); |
1220 else | 1218 else |
1221 wattrset(rosterWnd, get_color(COLOR_ROSTER)); | 1219 wattrset(rosterWnd, get_color(COLOR_ROSTER)); |
1222 } | 1220 } |
1223 | 1221 |
1224 name_locale = from_utf8(buddy_getname(BUDDATA(buddy))); | |
1225 if (Roster_Width > 7) | 1222 if (Roster_Width > 7) |
1226 strncpy(name, name_locale, Roster_Width-7); | 1223 g_utf8_strncpy(name, buddy_getname(BUDDATA(buddy)), Roster_Width-7); |
1227 else | 1224 else |
1228 name[0] = 0; | 1225 name[0] = 0; |
1229 | 1226 |
1230 if (isgrp) { | 1227 if (isgrp) { |
1231 char *sep; | 1228 char *sep; |
1247 sepleft = '{'; | 1244 sepleft = '{'; |
1248 sepright = '}'; | 1245 sepright = '}'; |
1249 } | 1246 } |
1250 } | 1247 } |
1251 | 1248 |
1252 snprintf(rline, Roster_Width, | 1249 snprintf(rline, 4*Roster_Width, |
1253 " %c%c%c%c %s", pending, sepleft, status, sepright, name); | 1250 " %c%c%c%c %s", pending, sepleft, status, sepright, name); |
1254 } | 1251 } |
1255 | 1252 |
1256 mvwprintw(rosterWnd, i, x_pos, "%s", rline); | 1253 rline_locale = from_utf8(rline); |
1257 g_free(name_locale); | 1254 mvwprintw(rosterWnd, i, x_pos, "%s", rline_locale); |
1255 g_free(rline_locale); | |
1258 i++; | 1256 i++; |
1259 } | 1257 } |
1260 | 1258 |
1261 g_free(rline); | 1259 g_free(rline); |
1262 g_free(name); | 1260 g_free(name); |