void upload_stats_gui_add(struct ul_stats *us) { GtkCList *clist = clist_ul_stats(); const gchar *rowdata[c_us_num]; enum c_us i; int row; char size_tmp[16]; char attempts_tmp[16]; char complete_tmp[16]; char norm_tmp[16]; char rtime_tmp[64]; char dtime_tmp[64]; g_strlcpy(size_tmp, short_size(us->size, show_metric_units()), sizeof size_tmp); gm_snprintf(attempts_tmp, sizeof attempts_tmp, "%u", us->attempts); gm_snprintf(complete_tmp, sizeof complete_tmp, "%u", us->complete); gm_snprintf(norm_tmp, sizeof norm_tmp, "%.3f", us->norm); if (us->rtime) { timestamp_to_string_buf(us->rtime, rtime_tmp, sizeof rtime_tmp); } else { rtime_tmp[0] = '\0'; } if (us->dtime) { timestamp_to_string_buf(us->dtime, dtime_tmp, sizeof dtime_tmp); } else { dtime_tmp[0] = '\0'; } for (i = 0; i < c_us_num; i++) switch (i) { case c_us_filename: rowdata[i] = lazy_utf8_to_ui_string(us->filename); break; case c_us_size: rowdata[i] = size_tmp; break; case c_us_attempts: rowdata[i] = attempts_tmp; break; case c_us_complete: rowdata[i] = complete_tmp; break; case c_us_norm: rowdata[i] = norm_tmp; break; case c_us_rtime: rowdata[i] = rtime_tmp; break; case c_us_dtime: rowdata[i] = dtime_tmp; break; case c_us_num: g_assert_not_reached(); } row = gtk_clist_append(clist, deconstify_gpointer(rowdata)); g_return_if_fail(row >= 0); ul_stats_set_row(us, row); gtk_clist_set_row_data_full(clist, row, us, on_clist_ul_stats_row_removed); /* FIXME: should use auto_sort? */ if (0 == clist->freeze_count) { gtk_clist_sort(clist); clist_sync_rows(clist, on_clist_ul_stats_row_moved); } }
static void cell_renderer_func(GtkTreeViewColumn *column, GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *iter, gpointer udata) { static const GValue zero_value; const struct upload_data *data; const gchar *text = NULL; gchar buf[64]; GValue value; if (!gtk_tree_view_column_get_visible(column)) return; value = zero_value; gtk_tree_model_get_value(model, iter, 0, &value); data = g_value_get_pointer(&value); switch ((enum c_us) GPOINTER_TO_UINT(udata)) { case c_us_filename: text = data->filename; break; case c_us_size: text = short_size(data->us->size, show_metric_units()); break; case c_us_attempts: text = uint64_to_string(data->us->attempts); break; case c_us_complete: text = uint64_to_string(data->us->attempts); break; case c_us_norm: str_bprintf(buf, sizeof buf, "%1.3f", data->us->norm); text = buf; break; case c_us_rtime: text = data->us->rtime ? timestamp_to_string(data->us->rtime) : NULL; break; case c_us_dtime: text = data->us->dtime ? timestamp_to_string(data->us->dtime) : NULL; break; case c_us_num: g_assert_not_reached(); } g_object_set(cell, "text", text, (void *) 0); }
static void print_upload_info(struct gnutella_shell *sh, const struct gnet_upload_info *info) { char buf[1024]; g_return_if_fail(sh); g_return_if_fail(info); str_bprintf(buf, sizeof buf, "%-3.3s %-16.40s %s %s@%s %s%s%s", info->encrypted ? "(E)" : "", host_addr_to_string(info->addr), iso3166_country_cc(info->country), compact_size(info->range_end - info->range_start, GNET_PROPERTY(display_metric_units)), short_size(info->range_start, GNET_PROPERTY(display_metric_units)), info->name ? "\"" : "<", info->name ? info->name : "none", info->name ? "\"" : ">"); shell_write(sh, buf); shell_write(sh, "\n"); /* Terminate line */ }