From 15274c4ebe9140da33863a3db99b4123d29de71a Mon Sep 17 00:00:00 2001 From: Alan Fitton Date: Sun, 27 May 2012 19:26:14 +0100 Subject: issue 184 - calculate ratio from have valid instead of downloaded, as Transmission does. --- src/requests.c | 4 ++-- src/trg-general-panel.c | 10 +++++----- src/trg-torrent-model.c | 17 +++++++++++------ src/trg-torrent-model.h | 1 + 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/requests.c b/src/requests.c index 3da3e9b..e5ec04d 100644 --- a/src/requests.c +++ b/src/requests.c @@ -169,8 +169,8 @@ JsonNode *torrent_get(gint64 id) json_array_add_string_element(fields, FIELD_PEERS_SENDING_TO_US); json_array_add_string_element(fields, FIELD_PEERS_GETTING_FROM_US); json_array_add_string_element(fields, FIELD_PEERS_CONNECTED); - /*json_array_add_string_element(fields, FIELD_HAVEVALID); - json_array_add_string_element(fields, FIELD_HAVEUNCHECKED); */ + json_array_add_string_element(fields, FIELD_HAVEVALID); + /* json_array_add_string_element(fields, FIELD_HAVEUNCHECKED); */ json_array_add_string_element(fields, FIELD_RATEUPLOAD); json_array_add_string_element(fields, FIELD_RATEDOWNLOAD); json_array_add_string_element(fields, FIELD_STATUS); diff --git a/src/trg-general-panel.c b/src/trg-general-panel.c index 827d9ef..d3e72e5 100644 --- a/src/trg-general-panel.c +++ b/src/trg-general-panel.c @@ -115,7 +115,7 @@ trg_general_panel_update(TrgGeneralPanel * panel, JsonObject * t, gint sizeOfBuf; gchar *statusString, *fullStatusString, *completedAtString, *comment; const gchar *errorStr; - gint64 eta, uploaded, downloaded, completedAt; + gint64 eta, uploaded, haveValid, completedAt; GtkLabel *keyLabel; gint64 seeders = 0, leechers = 0; @@ -141,12 +141,12 @@ trg_general_panel_update(TrgGeneralPanel * panel, JsonObject * t, trg_strlsize(buf, uploaded); gtk_label_set_text(GTK_LABEL(priv->gen_uploaded_label), buf); - downloaded = torrent_get_downloaded(t); - trg_strlsize(buf, downloaded); + haveValid = torrent_get_have_valid(t); + trg_strlsize(buf, torrent_get_downloaded(t)); gtk_label_set_text(GTK_LABEL(priv->gen_downloaded_label), buf); - if (uploaded > 0 && downloaded > 0) { - trg_strlratio(buf, (double) uploaded / (double) downloaded); + if (uploaded > 0 && haveValid > 0) { + trg_strlratio(buf, (double) uploaded / (double) haveValid); gtk_label_set_text(GTK_LABEL(priv->gen_ratio_label), buf); } else { gtk_label_set_text(GTK_LABEL(priv->gen_ratio_label), _("N/A")); diff --git a/src/trg-torrent-model.c b/src/trg-torrent-model.c index 4788977..32fbbb5 100644 --- a/src/trg-torrent-model.c +++ b/src/trg-torrent-model.c @@ -211,6 +211,7 @@ static void trg_torrent_model_init(TrgTorrentModel * self) column_types[TORRENT_COLUMN_ETA] = G_TYPE_INT64; column_types[TORRENT_COLUMN_UPLOADED] = G_TYPE_INT64; column_types[TORRENT_COLUMN_DOWNLOADED] = G_TYPE_INT64; + column_types[TORRENT_COLUMN_HAVE_VALID] = G_TYPE_INT64; column_types[TORRENT_COLUMN_RATIO] = G_TYPE_DOUBLE; column_types[TORRENT_COLUMN_ID] = G_TYPE_INT64; column_types[TORRENT_COLUMN_JSON] = G_TYPE_POINTER; @@ -408,7 +409,7 @@ update_torrent_iter(TrgTorrentModel * model, JsonObject *lastJson, *pf; JsonArray *trackerStats; gchar *statusString, *statusIcon, *downloadDir; - gint64 downRate, upRate, downloaded, uploaded, id, status, lpd; + gint64 downRate, upRate, haveValid, uploaded, id, status, lpd; gchar *firstTrackerHost = NULL; gchar *peerSources = NULL; gchar *lastDownloadDir = NULL; @@ -420,7 +421,7 @@ update_torrent_iter(TrgTorrentModel * model, stats->upRateTotal += upRate; uploaded = torrent_get_uploaded(t); - downloaded = torrent_get_downloaded(t); + haveValid = torrent_get_have_valid(t); downloadDir = (gchar *) torrent_get_download_dir(t); rm_trailing_slashes(downloadDir); @@ -486,7 +487,7 @@ update_torrent_iter(TrgTorrentModel * model, gtk_list_store_set(ls, iter, TORRENT_COLUMN_ETA, torrent_get_eta(t), -1); gtk_list_store_set(ls, iter, TORRENT_COLUMN_UPLOADED, uploaded, -1); - gtk_list_store_set(ls, iter, TORRENT_COLUMN_DOWNLOADED, downloaded, + gtk_list_store_set(ls, iter, TORRENT_COLUMN_DOWNLOADED, torrent_get_downloaded(t), -1); gtk_list_store_set(ls, iter, TORRENT_COLUMN_RATIO, uploaded > 0 && downloaded > @@ -530,6 +531,9 @@ update_torrent_iter(TrgTorrentModel * model, torrent_get_queue_position(t), -1); gtk_list_store_set(ls, iter, TORRENT_COLUMN_LASTACTIVE, torrent_get_activity_date(t), -1); + gtk_list_store_set(ls, iter, TORRENT_COLUMN_HAVE_VALID, + haveValid, -1); + #else gtk_list_store_set(ls, iter, TORRENT_COLUMN_ICON, statusIcon, TORRENT_COLUMN_ADDED, torrent_get_added_date(t), @@ -545,7 +549,8 @@ update_torrent_iter(TrgTorrentModel * model, TORRENT_COLUMN_FLAGS, newFlags, TORRENT_COLUMN_UPSPEED, upRate, TORRENT_COLUMN_ETA, torrent_get_eta(t), TORRENT_COLUMN_UPLOADED, - uploaded, TORRENT_COLUMN_DOWNLOADED, downloaded, + uploaded, TORRENT_COLUMN_DOWNLOADED, torrent_get_downloaded(t), + TORRENT_COLUMN_HAVE_VALID, haveValid, TORRENT_COLUMN_FROMPEX, peerfrom_get_pex(pf), TORRENT_COLUMN_FROMDHT, peerfrom_get_dht(pf), TORRENT_COLUMN_FROMTRACKERS, @@ -566,8 +571,8 @@ update_torrent_iter(TrgTorrentModel * model, TORRENT_COLUMN_LASTACTIVE, torrent_get_activity_date(t), TORRENT_COLUMN_RATIO, uploaded > 0 - && downloaded > - 0 ? (double) uploaded / (double) downloaded : 0, + && haveValid > + 0 ? (double) uploaded / (double) haveValid : 0, TORRENT_COLUMN_DOWNLOADDIR, downloadDir, TORRENT_COLUMN_BANDWIDTH_PRIORITY, torrent_get_bandwidth_priority(t), diff --git a/src/trg-torrent-model.h b/src/trg-torrent-model.h index f245455..9711fda 100644 --- a/src/trg-torrent-model.h +++ b/src/trg-torrent-model.h @@ -118,6 +118,7 @@ enum { TORRENT_COLUMN_ETA, TORRENT_COLUMN_UPLOADED, TORRENT_COLUMN_DOWNLOADED, + TORRENT_COLUMN_HAVE_VALID, TORRENT_COLUMN_RATIO, TORRENT_COLUMN_ADDED, TORRENT_COLUMN_ID, -- cgit v1.2.3