synchronize the Qt and GTK+ client's statusbars, including the new freespace indicator. Make the up/down speed ordering consistent between statusbar and torrent list.

This commit is contained in:
Jordan Lee
2013-01-27 23:05:47 +00:00
parent e85ece214e
commit 1d3bf93618
5 changed files with 207 additions and 108 deletions

View File

@@ -2,6 +2,6 @@
export G_SLICE=always-malloc export G_SLICE=always-malloc
export G_DEBUG=gc-friendly export G_DEBUG=gc-friendly
export GLIBCXX_FORCE_NEW=1 export GLIBCXX_FORCE_NEW=1
valgrind --tool=cachegrind ./transmission-gtk 2>&1 | tee runlog #valgrind --tool=cachegrind ./transmission-gtk 2>&1 | tee runlog
#valgrind --tool=cachegrind ./transmission-gtk -p -g /tmp/transmission-test 2>&1 | tee runlog #valgrind --tool=cachegrind ./transmission-gtk -p -g /tmp/transmission-test 2>&1 | tee runlog
#valgrind --tool=memcheck --leak-check=full --leak-resolution=high --num-callers=48 --log-file=x-valgrind --show-reachable=no ./transmission-gtk -p 2>&1 | tee runlog valgrind --tool=memcheck --leak-check=full --leak-resolution=high --num-callers=48 --log-file=x-valgrind --show-reachable=no ./transmission-gtk -p 2>&1 | tee runlog

View File

@@ -152,37 +152,54 @@ getShortTransferString (const tr_torrent * tor,
char * buf, char * buf,
size_t buflen) size_t buflen)
{ {
char downStr[32], upStr[32]; char dnStr[32], upStr[32];
const int haveMeta = tr_torrentHasMetadata (tor); const int haveMeta = tr_torrentHasMetadata (tor);
const int haveUp = haveMeta && st->peersGettingFromUs > 0; const int haveUp = haveMeta && st->peersGettingFromUs > 0;
const int haveDown = haveMeta && ((st->peersSendingToUs > 0) || (st->webseedsSendingToUs > 0)); const int haveDown = haveMeta && ((st->peersSendingToUs > 0) || (st->webseedsSendingToUs > 0));
if (haveDown) if (haveDown)
tr_formatter_speed_KBps (downStr, downloadSpeed_KBps, sizeof (downStr)); tr_formatter_speed_KBps (dnStr, downloadSpeed_KBps, sizeof (dnStr));
if (haveUp)
tr_formatter_speed_KBps (upStr, uploadSpeed_KBps, sizeof (upStr));
if (haveDown && haveUp) if (haveUp)
/* 1==down arrow, 2==down speed, 3==up arrow, 4==down speed */ tr_formatter_speed_KBps (upStr, uploadSpeed_KBps, sizeof (upStr));
g_snprintf (buf, buflen, _("%1$s %2$s, %3$s %4$s"),
gtr_get_unicode_string (GTR_UNICODE_DOWN), downStr,
gtr_get_unicode_string (GTR_UNICODE_UP), upStr);
else if (haveDown)
/* bandwidth speed + unicode arrow */
g_snprintf (buf, buflen, _("%1$s %2$s"),
gtr_get_unicode_string (GTR_UNICODE_DOWN), downStr);
else if (haveUp)
/* bandwidth speed + unicode arrow */
g_snprintf (buf, buflen, _("%1$s %2$s"),
gtr_get_unicode_string (GTR_UNICODE_UP), upStr);
else if (st->isStalled)
g_strlcpy (buf, _("Stalled"), buflen);
else if (haveMeta)
g_strlcpy (buf, _("Idle"), buflen);
else
*buf = '\0';
return buf; if (haveDown && haveUp)
{
/* 1==up speed, 2==up arrow, 3==down speed, 4==down arrow */
g_snprintf (buf, buflen, _("%1$s %2$s %3$s %4$s"),
upStr,
gtr_get_unicode_string (GTR_UNICODE_UP),
dnStr,
gtr_get_unicode_string (GTR_UNICODE_DOWN));
}
else if (haveDown)
{
/* unicode down arrow + bandwidth speed */
g_snprintf (buf, buflen, _("%1$s %2$s"),
dnStr,
gtr_get_unicode_string (GTR_UNICODE_DOWN));
}
else if (haveUp)
{
/* unicode up arrow + bandwidth speed */
g_snprintf (buf, buflen, _("%1$s %2$s"),
upStr,
gtr_get_unicode_string (GTR_UNICODE_UP));
}
else if (st->isStalled)
{
g_strlcpy (buf, _("Stalled"), buflen);
}
else if (haveMeta)
{
g_strlcpy (buf, _("Idle"), buflen);
}
else
{
*buf = '\0';
}
return buf;
} }
static void static void
@@ -219,8 +236,7 @@ getShortStatusString (GString * gstr,
if (st->activity != TR_STATUS_DOWNLOAD) if (st->activity != TR_STATUS_DOWNLOAD)
{ {
tr_strlratio (buf, st->ratio, sizeof (buf)); tr_strlratio (buf, st->ratio, sizeof (buf));
g_string_append_printf (gstr, _("Ratio %s"), buf); g_string_append_printf (gstr, _("Ratio: %s, "), buf);
g_string_append (gstr, ", ");
} }
getShortTransferString (tor, st, uploadSpeed_KBps, downloadSpeed_KBps, buf, sizeof (buf)); getShortTransferString (tor, st, uploadSpeed_KBps, downloadSpeed_KBps, buf, sizeof (buf));
g_string_append (gstr, buf); g_string_append (gstr, buf);

View File

@@ -54,7 +54,9 @@ typedef struct
GtkLabel * ul_lb; GtkLabel * ul_lb;
GtkLabel * dl_lb; GtkLabel * dl_lb;
GtkLabel * stats_lb; GtkLabel * stats_lb;
GtkLabel * gutter_lb; GtkLabel * freespace_lb;
GtkWidget * freespace_icon;
GtkLabel * count_lb;
GtkWidget * alt_speed_image; GtkWidget * alt_speed_image;
GtkWidget * alt_speed_button; GtkWidget * alt_speed_button;
GtkWidget * options_menu; GtkWidget * options_menu;
@@ -607,12 +609,15 @@ gtr_window_new (GtkApplication * app, GtkUIManager * ui_mgr, TrCore * core)
int i, n; int i, n;
const char * pch, * style; const char * pch, * style;
PrivateData * p; PrivateData * p;
GtkWidget * sibling = NULL;
GtkWidget * ul_lb, * dl_lb; GtkWidget * ul_lb, * dl_lb;
GtkWidget * mainmenu, *toolbar, *filter, *list, *status; GtkWidget * mainmenu, *toolbar, *filter, *list, *status;
GtkWidget * vbox, *w, *self, *h, *hbox, *menu; GtkWidget * vbox, *w, *self, *menu;
GtkWidget * grid_w;
GtkWindow * win; GtkWindow * win;
GtkCssProvider * css_provider; GtkCssProvider * css_provider;
GSList * l; GSList * l;
GtkGrid * grid;
p = g_new0 (PrivateData, 1); p = g_new0 (PrivateData, 1);
@@ -657,10 +662,10 @@ gtr_window_new (GtkApplication * app, GtkUIManager * ui_mgr, TrCore * core)
gtr_action_set_important ("show-torrent-properties", TRUE); gtr_action_set_important ("show-torrent-properties", TRUE);
/* filter */ /* filter */
h = filter = p->filter = gtr_filter_bar_new (gtr_core_session (core), w = filter = p->filter = gtr_filter_bar_new (gtr_core_session (core),
gtr_core_model (core), gtr_core_model (core),
&p->filter_model); &p->filter_model);
gtk_container_set_border_width (GTK_CONTAINER (h), GUI_PAD_SMALL); gtk_container_set_border_width (GTK_CONTAINER (w), GUI_PAD_SMALL);
/* status menu */ /* status menu */
menu = p->status_menu = gtk_menu_new (); menu = p->status_menu = gtk_menu_new ();
@@ -678,67 +683,100 @@ gtr_window_new (GtkApplication * app, GtkUIManager * ui_mgr, TrCore * core)
gtk_widget_show (w); gtk_widget_show (w);
} }
/* status */ /**
h = status = p->status = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD_BIG); *** Statusbar
gtk_container_set_border_width (GTK_CONTAINER (h), GUI_PAD_SMALL); **/
grid_w = status = p->status = gtk_grid_new ();
grid = GTK_GRID (grid_w);
gtk_container_set_border_width (GTK_CONTAINER (grid), GUI_PAD_SMALL);
/* gear */
w = gtk_button_new (); w = gtk_button_new ();
gtk_container_add (GTK_CONTAINER (w), gtk_image_new_from_stock ("utilities", -1)); gtk_container_add (GTK_CONTAINER (w), gtk_image_new_from_stock ("utilities", -1));
gtk_widget_set_tooltip_text (w, _("Options")); gtk_widget_set_tooltip_text (w, _("Options"));
gtk_box_pack_start (GTK_BOX (h), w, 0, 0, 0); gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE); gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE);
p->options_menu = createOptionsMenu (p); p->options_menu = createOptionsMenu (p);
g_signal_connect (w, "clicked", G_CALLBACK (onOptionsClicked), p); g_signal_connect (w, "clicked", G_CALLBACK (onOptionsClicked), p);
sibling = w;
/* turtle */
p->alt_speed_image = gtk_image_new (); p->alt_speed_image = gtk_image_new ();
w = p->alt_speed_button = gtk_toggle_button_new (); w = p->alt_speed_button = gtk_toggle_button_new ();
gtk_button_set_image (GTK_BUTTON (w), p->alt_speed_image); gtk_button_set_image (GTK_BUTTON (w), p->alt_speed_image);
gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE); gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE);
g_signal_connect (w, "toggled", G_CALLBACK (alt_speed_toggled_cb), p); g_signal_connect (w, "toggled", G_CALLBACK (alt_speed_toggled_cb), p);
gtk_box_pack_start (GTK_BOX (h), w, 0, 0, 0); gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
sibling = w;
/* spacer */
w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f);
gtk_widget_set_hexpand (w, TRUE);
gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
sibling = w;
/* torrent count */
w = gtk_label_new ("N Torrents"); w = gtk_label_new ("N Torrents");
p->gutter_lb = GTK_LABEL (w); p->count_lb = GTK_LABEL (w);
gtk_label_set_single_line_mode (p->gutter_lb, TRUE); gtk_label_set_single_line_mode (p->count_lb, TRUE);
gtk_box_pack_start (GTK_BOX (h), w, 1, 1, GUI_PAD); gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
sibling = w;
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD); /* freespace */
w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f); w = gtk_label_new (NULL);
gtk_widget_set_size_request (w, GUI_PAD, 0u); g_object_set (G_OBJECT(w), "margin-left", GUI_PAD_BIG*2, NULL);
gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); p->freespace_lb = GTK_LABEL (w);
w = ul_lb = gtk_label_new (NULL); gtk_label_set_single_line_mode (p->freespace_lb, TRUE);
p->ul_lb = GTK_LABEL (w); gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
gtk_label_set_single_line_mode (p->ul_lb, TRUE); sibling = w;
gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); w = gtk_image_new_from_stock (GTK_STOCK_HARDDISK, GTK_ICON_SIZE_MENU);
w = gtk_image_new_from_stock (GTK_STOCK_GO_UP, GTK_ICON_SIZE_MENU); p->freespace_icon = w;
gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); g_object_set (G_OBJECT(w), "margin-left", GUI_PAD, NULL);
gtk_box_pack_end (GTK_BOX (h), hbox, FALSE, FALSE, 0); gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
sibling = w;
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD); /* spacer */
w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f); w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f);
gtk_widget_set_size_request (w, GUI_PAD, 0u); gtk_widget_set_hexpand (w, TRUE);
gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
w = dl_lb = gtk_label_new (NULL); sibling = w;
p->dl_lb = GTK_LABEL (w);
gtk_label_set_single_line_mode (p->dl_lb, TRUE);
gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
w = gtk_image_new_from_stock (GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_MENU);
gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
gtk_box_pack_end (GTK_BOX (h), hbox, FALSE, FALSE, 0);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD); /* ratio */
w = gtk_button_new (); w = gtk_label_new (NULL);
gtk_widget_set_tooltip_text (w, _("Statistics")); p->stats_lb = GTK_LABEL (w);
gtk_container_add (GTK_CONTAINER (w), gtk_image_new_from_stock ("ratio", -1)); gtk_label_set_single_line_mode (p->stats_lb, TRUE);
gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE); gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
g_signal_connect (w, "clicked", G_CALLBACK (onYinYangReleased), p); sibling = w;
gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); w = gtk_button_new ();
w = gtk_label_new (NULL); gtk_widget_set_tooltip_text (w, _("Statistics"));
p->stats_lb = GTK_LABEL (w); gtk_container_add (GTK_CONTAINER (w), gtk_image_new_from_stock ("ratio", -1));
gtk_label_set_single_line_mode (p->stats_lb, TRUE); gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE);
gtk_box_pack_end (GTK_BOX (hbox), w, FALSE, FALSE, 0); g_signal_connect (w, "clicked", G_CALLBACK (onYinYangReleased), p);
gtk_box_pack_end (GTK_BOX (h), hbox, FALSE, FALSE, 0); gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
sibling = w;
/* upload */
w = ul_lb = gtk_label_new (NULL);
p->ul_lb = GTK_LABEL (w);
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;
/* download */
w = dl_lb = gtk_label_new (NULL);
p->dl_lb = GTK_LABEL (w);
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;
/* workarea */ /* workarea */
p->view = makeview (p); p->view = makeview (p);
@@ -792,27 +830,71 @@ gtr_window_new (GtkApplication * app, GtkUIManager * ui_mgr, TrCore * core)
static void static void
updateTorrentCount (PrivateData * p) updateTorrentCount (PrivateData * p)
{ {
if (p && p->core) bool visible = false;
g_return_if_fail (p != NULL);
if (p->core != NULL)
{ {
char buf[512];
const int torrentCount = gtk_tree_model_iter_n_children (gtr_core_model (p->core), NULL); const int torrentCount = gtk_tree_model_iter_n_children (gtr_core_model (p->core), NULL);
const int visibleCount = gtk_tree_model_iter_n_children (p->filter_model, NULL); const int visibleCount = gtk_tree_model_iter_n_children (p->filter_model, NULL);
if (!torrentCount) visible = torrentCount > 0;
*buf = '\0';
else if (torrentCount != visibleCount)
g_snprintf (buf, sizeof (buf),
ngettext ("%1$'d of %2$'d Torrent",
"%1$'d of %2$'d Torrents",
torrentCount),
visibleCount, torrentCount);
else
g_snprintf (buf, sizeof (buf),
ngettext ("%'d Torrent", "%'d Torrents", torrentCount),
torrentCount);
gtr_label_set_text (p->gutter_lb, buf); if (visible)
{
char countStr[512];
if (torrentCount != visibleCount)
g_snprintf (countStr, sizeof (countStr),
ngettext ("%1$'d of %2$'d Torrent",
"%1$'d of %2$'d Torrents",
torrentCount),
visibleCount, torrentCount);
else
g_snprintf (countStr, sizeof (countStr),
ngettext ("%'d Torrent", "%'d Torrents", torrentCount),
torrentCount);
gtr_label_set_text (p->count_lb, countStr);
}
} }
gtk_widget_set_visible (GTK_WIDGET(p->count_lb), visible);
}
static void
updateFreeSpace (PrivateData * p)
{
GtkWidget * w;
bool visible = false;
g_return_if_fail (p != NULL);
w = GTK_WIDGET (p->freespace_lb);
if (p->core != NULL)
{
tr_session * session = gtr_core_session (p->core);
const int64_t n = tr_sessionGetDownloadDirFreeSpace (session);
const char * downloadDir = tr_sessionGetDownloadDir (session);
visible = n >= 0;
if (visible)
{
char * tip;
char sizeStr[32];
tr_strlsize (sizeStr, n, sizeof(sizeStr));
gtk_label_set_text (p->freespace_lb, sizeStr);
tip = tr_strdup_printf (_("Download folder \"%1$s\" has %2$s free"), downloadDir, sizeStr);
gtk_widget_set_tooltip_text (w, tip);
g_free (tip);
}
}
gtk_widget_set_visible (w, visible);
gtk_widget_set_visible (p->freespace_icon, visible);
} }
static void static void
@@ -907,6 +989,7 @@ gtr_window_refresh (GtkWindow * self)
updateSpeeds (p); updateSpeeds (p);
updateTorrentCount (p); updateTorrentCount (p);
updateStats (p); updateStats (p);
updateFreeSpace (p);
} }
} }

View File

@@ -433,20 +433,10 @@ TrMainWindow :: createStatusBar ()
p->setMenu (m); p->setMenu (m);
h->addWidget (p); h->addWidget (p);
h->addSpacing (HIG::PAD);
l = myDownloadSpeedLabel = new QLabel (this);
const int minimumSpeedWidth = l->fontMetrics ().width (Formatter::speedToString (Speed::fromKBps (999.99)));
l->setMinimumWidth (minimumSpeedWidth);
l->setAlignment (Qt::AlignRight|Qt::AlignVCenter);
h->addWidget (l);
l = new QLabel (this);
l->setPixmap (getStockIcon ("go-down", QStyle::SP_ArrowDown).pixmap (smallIconSize));
h->addWidget (l);
h->addSpacing (HIG::PAD); h->addSpacing (HIG::PAD);
l = myUploadSpeedLabel = new QLabel; l = myUploadSpeedLabel = new QLabel;
const int minimumSpeedWidth = l->fontMetrics ().width (Formatter::speedToString (Speed::fromKBps (999.99)));
l->setMinimumWidth (minimumSpeedWidth); l->setMinimumWidth (minimumSpeedWidth);
l->setAlignment (Qt::AlignRight|Qt::AlignVCenter); l->setAlignment (Qt::AlignRight|Qt::AlignVCenter);
h->addWidget (l); h->addWidget (l);
@@ -454,6 +444,16 @@ TrMainWindow :: createStatusBar ()
l->setPixmap (getStockIcon ("go-up", QStyle::SP_ArrowUp).pixmap (smallIconSize)); l->setPixmap (getStockIcon ("go-up", QStyle::SP_ArrowUp).pixmap (smallIconSize));
h->addWidget (l); h->addWidget (l);
h->addSpacing (HIG::PAD);
l = myDownloadSpeedLabel = new QLabel (this);
l->setMinimumWidth (minimumSpeedWidth);
l->setAlignment (Qt::AlignRight|Qt::AlignVCenter);
h->addWidget (l);
l = new QLabel (this);
l->setPixmap (getStockIcon ("go-down", QStyle::SP_ArrowDown).pixmap (smallIconSize));
h->addWidget (l);
return top; return top;
} }

View File

@@ -183,11 +183,11 @@ TorrentDelegate :: shortTransferString( const Torrent& tor ) const
upStr = Formatter::speedToString( tor.uploadSpeed( ) ); upStr = Formatter::speedToString( tor.uploadSpeed( ) );
if( haveDown && haveUp ) if( haveDown && haveUp )
str = tr( "%1 %2, %3 %4" ).arg(downArrow).arg(downStr).arg(upArrow).arg(upStr); str = tr( "%1%2, %3%4" ).arg(upStr).arg(upArrow).arg(downStr).arg(downArrow);
else if( haveDown ) else if( haveDown )
str = tr( "%1 %2" ).arg(downArrow).arg(downStr); str = tr( "%1%2" ).arg(downStr).arg(downArrow);
else if( haveUp ) else if( haveUp )
str = tr( "%1 %2" ).arg(upArrow).arg(upStr); str = tr( "%1%2" ).arg(upStr).arg(upArrow);
else if( tor.isStalled( ) ) else if( tor.isStalled( ) )
str = tr( "Stalled" ); str = tr( "Stalled" );
else if( tor.hasMetadata( ) ) else if( tor.hasMetadata( ) )
@@ -210,7 +210,7 @@ TorrentDelegate :: shortStatusString( const Torrent& tor ) const
case TR_STATUS_DOWNLOAD: case TR_STATUS_DOWNLOAD:
case TR_STATUS_SEED: case TR_STATUS_SEED:
if( !tor.isDownloading( ) ) if( !tor.isDownloading( ) )
str = tr( "Ratio: %1, " ).arg( Formatter::ratioToString( tor.ratio( ) ) ); str = tr( "Ratio: %1, " ).arg( Formatter::ratioToString( tor.ratio( ) ) );
str += shortTransferString( tor ); str += shortTransferString( tor );
break; break;