diff options
author | 2011-09-11 21:44:28 +0000 | |
---|---|---|
committer | 2011-09-11 21:44:28 +0000 | |
commit | 2aacfd5e691a7c8b37c2fc1dbcf001615c205b97 (patch) | |
tree | b594b99f18040d95a7c1b2325f76fc20ebd46e81 /src | |
parent | 70bf14ea3eade947baf6fab49541f3b19c4db099 (diff) |
show progress in percent done column
Diffstat (limited to 'src')
-rw-r--r-- | src/protocol-constants.h | 1 | ||||
-rw-r--r-- | src/requests.c | 1 | ||||
-rw-r--r-- | src/torrent.c | 20 | ||||
-rw-r--r-- | src/torrent.h | 30 | ||||
-rw-r--r-- | src/trg-state-selector.c | 5 | ||||
-rw-r--r-- | src/trg-torrent-model.c | 9 | ||||
-rw-r--r-- | src/util.c | 14 | ||||
-rw-r--r-- | src/util.h | 1 |
8 files changed, 48 insertions, 33 deletions
diff --git a/src/protocol-constants.h b/src/protocol-constants.h index 09faab0..ff9b7ed 100644 --- a/src/protocol-constants.h +++ b/src/protocol-constants.h @@ -101,6 +101,7 @@ #define FIELD_LEECHERCOUNT "leecherCount" #define FIELD_HOST "host" #define FIELD_LAST_ANNOUNCE_RESULT "lastAnnounceResult" +#define FIELD_RECHECK_PROGRESS "recheckProgress" /* methods */ diff --git a/src/requests.c b/src/requests.c index 6732bd7..23528f8 100644 --- a/src/requests.c +++ b/src/requests.c @@ -193,6 +193,7 @@ JsonNode *torrent_get(gint64 id) json_array_add_string_element(fields, FIELD_ERRORSTR); json_array_add_string_element(fields, FIELD_WANTED); json_array_add_string_element(fields, FIELD_PRIORITIES); + json_array_add_string_element(fields, FIELD_RECHECK_PROGRESS); json_object_set_array_member(args, PARAM_FIELDS, fields); return root; } diff --git a/src/torrent.c b/src/torrent.c index 7b7ad07..7376c15 100644 --- a/src/torrent.c +++ b/src/torrent.c @@ -169,17 +169,12 @@ gboolean torrent_get_is_finished(JsonObject * t) gdouble torrent_get_percent_done(JsonObject * t) { - JsonNode *percentDone = json_object_get_member(t, FIELD_PERCENTDONE); - GValue a = { 0 }; - json_node_get_value(percentDone, &a); - switch (G_VALUE_TYPE(&a)) { - case G_TYPE_INT64: - return (gdouble) g_value_get_int64(&a) * 100.0; - case G_TYPE_DOUBLE: - return g_value_get_double(&a) * 100.0; - default: - return 0.0; - } + return json_int_or_double_to_double(json_object_get_member(t, FIELD_PERCENTDONE)); +} + +gdouble torrent_get_recheck_progress(JsonObject * t) +{ + return json_int_or_double_to_double(json_object_get_member(t, FIELD_RECHECK_PROGRESS)); } guint32 torrent_get_flags(JsonObject * t, gint64 rpcv, gint64 status, gint64 downRate, gint64 upRate) @@ -192,10 +187,11 @@ guint32 torrent_get_flags(JsonObject * t, gint64 rpcv, gint64 status, gint64 dow break; case TR_STATUS_CHECK_WAIT: flags |= TORRENT_FLAG_WAITING_CHECK; - flags |= TORRENT_FLAG_CHECKING; + flags |= TORRENT_FLAG_CHECKING_ANY; break; case TR_STATUS_CHECK: flags |= TORRENT_FLAG_CHECKING; + flags |= TORRENT_FLAG_CHECKING_ANY; break; case TR_STATUS_DOWNLOAD_WAIT: flags |= TORRENT_FLAG_DOWNLOADING_WAIT; diff --git a/src/torrent.h b/src/torrent.h index 2e3ca16..03e3b7c 100644 --- a/src/torrent.h +++ b/src/torrent.h @@ -24,20 +24,21 @@ #include "trg-client.h" -#define TORRENT_FLAG_ERROR (1 << 0) /* 0x01 */ -#define TORRENT_FLAG_COMPLETE (1 << 1) /* 0x02 */ -#define TORRENT_FLAG_INCOMPLETE (1 << 2) /* 0x04 */ -#define TORRENT_FLAG_SEEDING (1 << 3) /* 0x08 */ -#define TORRENT_FLAG_SEEDING_WAIT (1 << 4) /* 0x16 */ -#define TORRENT_FLAG_CHECKING (1 << 5) /* 0x32 */ -#define TORRENT_FLAG_WAITING_CHECK (1 << 6) /* 0x64 */ -#define TORRENT_FLAG_DOWNLOADING (1 << 7) /* 0x128 */ -#define TORRENT_FLAG_DOWNLOADING_WAIT (1 << 8) /* 0x256 */ -#define TORRENT_FLAG_PAUSED (1 << 10) /* 0x512 */ -#define TORRENT_FLAG_QUEUED (1 << 11) /* 0x1024 */ -#define TORRENT_FLAG_ACTIVE (1 << 12) /* 0x2048 */ -#define FILTER_FLAG_TRACKER (1 << 13) /* 0x4096 */ -#define FILTER_FLAG_DIR (1 << 14) /* 0x8192 */ +#define TORRENT_FLAG_ERROR (1 << 0) +#define TORRENT_FLAG_COMPLETE (1 << 1) +#define TORRENT_FLAG_INCOMPLETE (1 << 2) +#define TORRENT_FLAG_SEEDING (1 << 3) +#define TORRENT_FLAG_SEEDING_WAIT (1 << 4) +#define TORRENT_FLAG_CHECKING (1 << 5) +#define TORRENT_FLAG_WAITING_CHECK (1 << 6) +#define TORRENT_FLAG_CHECKING_ANY (1 << 7) +#define TORRENT_FLAG_DOWNLOADING (1 << 8) +#define TORRENT_FLAG_DOWNLOADING_WAIT (1 << 9) +#define TORRENT_FLAG_PAUSED (1 << 10) +#define TORRENT_FLAG_QUEUED (1 << 11) +#define TORRENT_FLAG_ACTIVE (1 << 12) +#define FILTER_FLAG_TRACKER (1 << 13) +#define FILTER_FLAG_DIR (1 << 14) #define TORRENT_ADD_FLAG_PAUSED (1 << 0) /* 0x01 */ #define TORRENT_ADD_FLAG_DELETE (1 << 1) /* 0x02 */ @@ -68,6 +69,7 @@ gint64 torrent_get_peers_getting_from_us(JsonObject *args); gint64 torrent_get_peers_sending_to_us(JsonObject *args); gint64 torrent_get_peers_connected(JsonObject *args); gdouble torrent_get_percent_done(JsonObject * t); +gdouble torrent_get_recheck_progress(JsonObject * t); gint64 torrent_get_left_until_done(JsonObject * t); gboolean torrent_get_is_finished(JsonObject * t); gboolean torrent_get_honors_session_limits(JsonObject * t); diff --git a/src/trg-state-selector.c b/src/trg-state-selector.c index 5b2fdd2..4b7f035 100644 --- a/src/trg-state-selector.c +++ b/src/trg-state-selector.c @@ -424,8 +424,6 @@ static GObject *trg_state_selector_constructor(GType type, selector = TRG_STATE_SELECTOR(object); priv = TRG_STATE_SELECTOR_GET_PRIVATE(object); - priv->flag = 0; - priv->urlHostRegex = trg_uri_host_regex_new(); priv->trackers = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify) remove_row_ref_and_free); @@ -488,7 +486,7 @@ static GObject *trg_state_selector_constructor(GType type, gtk_list_store_append(store, &iter); trg_state_selector_add_state(selector, &iter, GTK_STOCK_REFRESH, - _("Checking"), TORRENT_FLAG_CHECKING); + _("Checking"), TORRENT_FLAG_CHECKING_ANY); gtk_list_store_append(store, &iter); trg_state_selector_add_state(selector, &iter, GTK_STOCK_DIALOG_WARNING, @@ -551,7 +549,6 @@ void trg_state_selector_set_queues_enabled(TrgStateSelector *s, gboolean enabled gtk_list_store_remove(GTK_LIST_STORE(model), &iter); priv->n_categories -= 2; - g_debug("now categories %d", priv->n_categories); } } diff --git a/src/trg-torrent-model.c b/src/trg-torrent-model.c index c4b29d0..a40f2b0 100644 --- a/src/trg-torrent-model.c +++ b/src/trg-torrent-model.c @@ -267,7 +267,9 @@ update_torrent_iter(TrgTorrentModel * model, gint64 rpcv, gint64 serial, gtk_list_store_set(ls, iter, TORRENT_COLUMN_SIZE, torrent_get_size(t), -1); gtk_list_store_set(ls, iter, - TORRENT_COLUMN_DONE, torrent_get_percent_done(t), + TORRENT_COLUMN_DONE, (newFlags & TORRENT_FLAG_CHECKING) ? + torrent_get_recheck_progress(t) + : torrent_get_percent_done(t), -1); gtk_list_store_set(ls, iter, TORRENT_COLUMN_STATUS, statusString, -1); gtk_list_store_set(ls, iter, TORRENT_COLUMN_DOWNSPEED, downRate, -1); @@ -315,8 +317,9 @@ update_torrent_iter(TrgTorrentModel * model, gint64 rpcv, gint64 serial, TORRENT_COLUMN_DONE_DATE, torrent_get_done_date(t), TORRENT_COLUMN_NAME, torrent_get_name(t), TORRENT_COLUMN_SIZE, torrent_get_size(t), - TORRENT_COLUMN_DONE, - torrent_get_percent_done(t), + TORRENT_COLUMN_DONE, (newFlags & TORRENT_FLAG_CHECKING) ? + torrent_get_recheck_progress(t) + : torrent_get_percent_done(t), TORRENT_COLUMN_STATUS, statusString, TORRENT_COLUMN_DOWNSPEED, downRate, TORRENT_COLUMN_FLAGS, newFlags, @@ -367,3 +367,17 @@ void trg_widget_set_visible(GtkWidget * w, gboolean visible) { else gtk_widget_hide(w); } + +gdouble json_int_or_double_to_double(JsonNode *n) +{ + GValue a = { 0 }; + json_node_get_value(n, &a); + switch (G_VALUE_TYPE(&a)) { + case G_TYPE_INT64: + return (gdouble) g_value_get_int64(&a) * 100.0; + case G_TYPE_DOUBLE: + return g_value_get_double(&a) * 100.0; + default: + return 0.0; + } +} @@ -67,5 +67,6 @@ int evutil_vsnprintf(char *buf, size_t buflen, const char *format, va_list ap); void rm_trailing_slashes(gchar *str); void trg_widget_set_visible(GtkWidget * w, gboolean visible); +gdouble json_int_or_double_to_double(JsonNode *n); #endif /* UTIL_H_ */ |