@@ -43,7 +43,7 @@ typedef struct tab_t {
4343 gboolean hide_mail : 1 ;
4444 gboolean hide_conn : 1 ;
4545 gboolean hide_ip : 1 ;
46- int cw_user , cw_share , cw_conn , cw_desc , cw_mail , cw_tag , cw_ip ;
46+ int cw_user , cw_country , cw_share , cw_conn , cw_desc , cw_mail , cw_tag , cw_ip ;
4747} tab_t ;
4848
4949
@@ -93,11 +93,6 @@ static const char *get_name(GSequenceIter *iter) {
9393}
9494
9595
96- #ifdef USE_GEOIP
97- static GeoIP * geoip4 = NULL ;
98- static GeoIP * geoip6 = NULL ;
99- #endif
100-
10196
10297ui_tab_t * uit_userlist_create (hub_t * hub ) {
10398 tab_t * t = g_new0 (tab_t , 1 );
@@ -109,14 +104,6 @@ ui_tab_t *uit_userlist_create(hub_t *hub) {
109104 t -> hide_mail = TRUE;
110105 t -> hide_ip = TRUE;
111106
112- #ifdef USE_GEOIP
113- // init these when the first userlist tab is opened
114- if (!geoip4 ) {
115- geoip4 = GeoIP_open_type (GEOIP_COUNTRY_EDITION , GEOIP_MEMORY_CACHE );
116- geoip6 = GeoIP_open_type (GEOIP_COUNTRY_EDITION_V6 , GEOIP_MEMORY_CACHE );
117- }
118- #endif
119-
120107 GSequence * users = g_sequence_new (NULL );
121108 // populate the list
122109 // g_sequence_sort() uses insertion sort? in that case it is faster to insert
@@ -179,20 +166,11 @@ static void draw_row(ui_listing_t *list, GSequenceIter *iter, int row, void *dat
179166 if (user -> hastls )
180167 mvaddch (row , 4 , 't' );
181168
182- #ifdef USE_GEOIP
183- const char * country = NULL ;
184- if (!ip4_isany (user -> ip4 ))
185- country = GeoIP_country_code_by_addr (geoip4 , ip4_unpack (user -> ip4 ));
186- else if (!ip6_isany (user -> ip6 ))
187- country = GeoIP_country_code_by_addr_v6 (geoip6 , ip6_unpack (user -> ip6 ));
188- if (country )
189- mvaddstr (row , 6 , country );
190- int j = 9 ;
191- #else
192- int j = 6 ;
193- #endif
194-
195- if (t -> cw_user > 1 )
169+ int j = 6 ;
170+ DRAW_COL (row , j , t -> cw_country ,
171+ !ip4_isany (user -> ip4 ) ? geoip_country4 (ip4_unpack (user -> ip4 )) :
172+ !ip6_isany (user -> ip6 ) ? geoip_country6 (ip6_unpack (user -> ip6 )) : "" );
173+ if (t -> cw_user > 1 )
196174 ui_listing_draw_match (list , iter , row , j , str_offset_from_columns (user -> name , t -> cw_user - 1 ));
197175 j += t -> cw_user ;
198176 DRAW_COL (row , j , t -> cw_share , user -> hasinfo ? str_formatsize (user -> sharesize ) : "" );
@@ -224,11 +202,11 @@ static void draw_row(ui_listing_t *list, GSequenceIter *iter, int row, void *dat
224202 */
225203static void calc_widths (tab_t * t ) {
226204 // available width
227- #ifdef USE_GEOIP
228- int w = wincols - 9 ;
229- #else
230205 int w = wincols - 6 ;
231- #endif
206+
207+ // Country code column (fixed size)
208+ t -> cw_country = geoip_available ? 3 : 0 ;
209+ w -= t -> cw_country ;
232210
233211 // share has a fixed size
234212 t -> cw_share = 12 ;
@@ -277,20 +255,16 @@ static void t_draw(ui_tab_t *tab) {
277255 // header
278256 attron (UIC (list_header ));
279257 mvhline (1 , 0 , ' ' , wincols );
280- #ifdef USE_GEOIP
281- mvaddstr (1 , 2 , "opt CC" );
282- int i = 9 ;
283- #else
284258 mvaddstr (1 , 2 , "opt" );
285259 int i = 6 ;
286- #endif
287- DRAW_COL (1 , i , t -> cw_user , "Username" );
288- DRAW_COL (1 , i , t -> cw_share , "Share" );
289- DRAW_COL (1 , i , t -> cw_desc , "Description" );
290- DRAW_COL (1 , i , t -> cw_tag , "Tag" );
291- DRAW_COL (1 , i , t -> cw_mail , "E-Mail" );
292- DRAW_COL (1 , i , t -> cw_conn , "Connection" );
293- DRAW_COL (1 , i , t -> cw_ip , "IP" );
260+ DRAW_COL ( 1 , i , t -> cw_country , "CC" );
261+ DRAW_COL (1 , i , t -> cw_user , "Username" );
262+ DRAW_COL (1 , i , t -> cw_share , "Share" );
263+ DRAW_COL (1 , i , t -> cw_desc , "Description" );
264+ DRAW_COL (1 , i , t -> cw_tag , "Tag" );
265+ DRAW_COL (1 , i , t -> cw_mail , "E-Mail" );
266+ DRAW_COL (1 , i , t -> cw_conn , "Connection" );
267+ DRAW_COL (1 , i , t -> cw_ip , "IP" );
294268 attroff (UIC (list_header ));
295269
296270 // rows
0 commit comments