1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-01-31 03:12:44 +00:00

(gtk) match transmission-qt's way of showing up & down speeds in the statusbar

This commit is contained in:
Jordan Lee 2013-02-08 01:34:59 +00:00
parent 716a2f2c5c
commit d76d2a34d9
3 changed files with 42 additions and 19 deletions

View file

@ -197,6 +197,8 @@ tr_core_init (TrCore * core)
G_TYPE_INT, /* torrent id */
G_TYPE_DOUBLE, /* tr_stat.pieceUploadSpeed_KBps */
G_TYPE_DOUBLE, /* tr_stat.pieceDownloadSpeed_KBps */
G_TYPE_INT, /* tr_stat.peersGettingFromUs */
G_TYPE_INT, /* tr_stat.peersSendingToUs + webseedsSendingToUs */
G_TYPE_DOUBLE, /* tr_stat.recheckProgress */
G_TYPE_BOOLEAN, /* filter.c:ACTIVITY_FILTER_ACTIVE */
G_TYPE_INT, /* tr_stat.activity */
@ -1078,6 +1080,8 @@ gtr_core_add_torrent (TrCore * core, tr_torrent * tor, gboolean do_notify)
MC_TORRENT_ID, tr_torrentId (tor),
MC_SPEED_UP, st->pieceUploadSpeed_KBps,
MC_SPEED_DOWN, st->pieceDownloadSpeed_KBps,
MC_ACTIVE_PEERS_UP, st->peersGettingFromUs,
MC_ACTIVE_PEERS_DOWN, st->peersSendingToUs + st->webseedsSendingToUs,
MC_RECHECK_PROGRESS, st->recheckProgress,
MC_ACTIVE, is_torrent_active (st),
MC_ACTIVITY, st->activity,
@ -1428,6 +1432,8 @@ update_foreach (GtkTreeModel * model, GtkTreeIter * iter)
int oldError, newError;
bool oldFinished, newFinished;
int oldQueuePosition, newQueuePosition;
int oldDownloadPeerCount, newDownloadPeerCount;
int oldUploadPeerCount, newUploadPeerCount;
tr_priority_t oldPriority, newPriority;
unsigned int oldTrackers, newTrackers;
double oldUpSpeed, newUpSpeed;
@ -1442,6 +1448,8 @@ update_foreach (GtkTreeModel * model, GtkTreeIter * iter)
MC_TORRENT, &tor,
MC_ACTIVE, &oldActive,
MC_ACTIVE_PEER_COUNT, &oldActivePeerCount,
MC_ACTIVE_PEERS_UP, &oldUploadPeerCount,
MC_ACTIVE_PEERS_DOWN, &oldDownloadPeerCount,
MC_ERROR, &oldError,
MC_ACTIVITY, &oldActivity,
MC_FINISHED, &oldFinished,
@ -1465,6 +1473,8 @@ update_foreach (GtkTreeModel * model, GtkTreeIter * iter)
newDownSpeed = st->pieceDownloadSpeed_KBps;
newRecheckProgress = st->recheckProgress;
newActivePeerCount = st->peersSendingToUs + st->peersGettingFromUs + st->webseedsSendingToUs;
newDownloadPeerCount = st->peersSendingToUs;
newUploadPeerCount = st->peersGettingFromUs + st->webseedsSendingToUs;
newError = st->error;
/* updating the model triggers off resort/refresh,
@ -1476,6 +1486,8 @@ update_foreach (GtkTreeModel * model, GtkTreeIter * iter)
|| (newQueuePosition != oldQueuePosition)
|| (newError != oldError)
|| (newActivePeerCount != oldActivePeerCount)
|| (newDownloadPeerCount != oldDownloadPeerCount)
|| (newUploadPeerCount != oldUploadPeerCount)
|| (newTrackers != oldTrackers)
|| gtr_compare_double (newUpSpeed, oldUpSpeed, 2)
|| gtr_compare_double (newDownSpeed, oldDownSpeed, 2)
@ -1484,6 +1496,8 @@ update_foreach (GtkTreeModel * model, GtkTreeIter * iter)
gtk_list_store_set (GTK_LIST_STORE (model), iter,
MC_ACTIVE, newActive,
MC_ACTIVE_PEER_COUNT, newActivePeerCount,
MC_ACTIVE_PEERS_UP, newUploadPeerCount,
MC_ACTIVE_PEERS_DOWN, newDownloadPeerCount,
MC_ERROR, newError,
MC_ACTIVITY, newActivity,
MC_FINISHED, newFinished,

View file

@ -173,6 +173,8 @@ enum
MC_TORRENT_ID,
MC_SPEED_UP,
MC_SPEED_DOWN,
MC_ACTIVE_PEERS_UP,
MC_ACTIVE_PEERS_DOWN,
MC_RECHECK_PROGRESS,
MC_ACTIVE,
MC_ACTIVITY,

View file

@ -740,10 +740,6 @@ gtr_window_new (GtkApplication * app, GtkUIManager * ui_mgr, TrCore * core)
gtk_label_set_single_line_mode (p->dl_lb, TRUE);
gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
sibling = w;
w = gtk_image_new_from_stock (GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_MENU);
g_object_set (G_OBJECT(w), "margin-left", GUI_PAD, NULL);
gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
sibling = w;
/* upload */
w = ul_lb = gtk_label_new (NULL);
@ -752,10 +748,6 @@ gtr_window_new (GtkApplication * app, GtkUIManager * ui_mgr, TrCore * core)
gtk_label_set_single_line_mode (p->ul_lb, TRUE);
gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
sibling = w;
w = gtk_image_new_from_stock (GTK_STOCK_GO_UP, GTK_ICON_SIZE_MENU);
g_object_set (G_OBJECT(w), "margin-left", GUI_PAD, NULL);
gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
sibling = w;
/* ratio */
w = gtk_label_new (NULL);
@ -818,6 +810,7 @@ gtr_window_new (GtkApplication * app, GtkUIManager * ui_mgr, TrCore * core)
tr_sessionSetAltSpeedFunc (gtr_core_session (core), onAltSpeedToggled, p);
gtr_window_refresh (GTK_WINDOW(self));
return self;
}
@ -918,27 +911,41 @@ updateSpeeds (PrivateData * p)
if (session != NULL)
{
char buf[128];
double up=0, down=0;
char text_str[256];
char speed_str[128];
double upSpeed = 0;
double downSpeed = 0;
int upCount = 0;
int downCount = 0;
GtkTreeIter iter;
GtkTreeModel * model = gtr_core_model (p->core);
if (gtk_tree_model_iter_nth_child (model, &iter, NULL, 0)) do
{
double u, d;
gtk_tree_model_get (model, &iter, MC_SPEED_UP, &u,
MC_SPEED_DOWN, &d,
int uc, dc;
double us, ds;
gtk_tree_model_get (model, &iter, MC_SPEED_UP, &us,
MC_SPEED_DOWN, &ds,
MC_ACTIVE_PEERS_UP, &uc,
MC_ACTIVE_PEERS_DOWN, &dc,
-1);
up += u;
down += d;
upSpeed += us;
upCount += uc;
downSpeed += ds;
downCount += dc;
}
while (gtk_tree_model_iter_next (model, &iter));
tr_formatter_speed_KBps (buf, down, sizeof (buf));
gtr_label_set_text (p->dl_lb, buf);
tr_formatter_speed_KBps (speed_str, downSpeed, sizeof (speed_str));
g_snprintf (text_str, sizeof(text_str), "%s %s", speed_str, gtr_get_unicode_string (GTR_UNICODE_DOWN));
gtr_label_set_text (p->dl_lb, text_str);
gtk_widget_set_visible (GTK_WIDGET (p->dl_lb), (downCount>0));
tr_formatter_speed_KBps (buf, up, sizeof (buf));
gtr_label_set_text (p->ul_lb, buf);
tr_formatter_speed_KBps (speed_str, upSpeed, sizeof (speed_str));
g_snprintf (text_str, sizeof(text_str), "%s %s", speed_str, gtr_get_unicode_string (GTR_UNICODE_UP));
gtr_label_set_text (p->ul_lb, text_str);
gtk_widget_set_visible (GTK_WIDGET (p->ul_lb), ((downCount>0) || (upCount>0)));
}
}