From 1d3bf936180ec0cc46b9f4964a289db8223d1263 Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Sun, 27 Jan 2013 23:05:47 +0000 Subject: [PATCH] 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. --- gtk/my-valgrind.sh | 4 +- gtk/torrent-cell-renderer.c | 80 ++++++++------ gtk/tr-window.c | 215 +++++++++++++++++++++++++----------- qt/mainwin.cc | 12 +- qt/torrent-delegate.cc | 8 +- 5 files changed, 209 insertions(+), 110 deletions(-) diff --git a/gtk/my-valgrind.sh b/gtk/my-valgrind.sh index cd5ff98fa..87d960b8e 100755 --- a/gtk/my-valgrind.sh +++ b/gtk/my-valgrind.sh @@ -2,6 +2,6 @@ export G_SLICE=always-malloc export G_DEBUG=gc-friendly 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=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 diff --git a/gtk/torrent-cell-renderer.c b/gtk/torrent-cell-renderer.c index e6ef9b266..64e2943a1 100644 --- a/gtk/torrent-cell-renderer.c +++ b/gtk/torrent-cell-renderer.c @@ -152,37 +152,54 @@ getShortTransferString (const tr_torrent * tor, char * buf, size_t buflen) { - char downStr[32], upStr[32]; - const int haveMeta = tr_torrentHasMetadata (tor); - const int haveUp = haveMeta && st->peersGettingFromUs > 0; - const int haveDown = haveMeta && ((st->peersSendingToUs > 0) || (st->webseedsSendingToUs > 0)); - - if (haveDown) - tr_formatter_speed_KBps (downStr, downloadSpeed_KBps, sizeof (downStr)); - if (haveUp) - tr_formatter_speed_KBps (upStr, uploadSpeed_KBps, sizeof (upStr)); - - if (haveDown && haveUp) - /* 1==down arrow, 2==down speed, 3==up arrow, 4==down speed */ - 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'; + char dnStr[32], upStr[32]; + const int haveMeta = tr_torrentHasMetadata (tor); + const int haveUp = haveMeta && st->peersGettingFromUs > 0; + const int haveDown = haveMeta && ((st->peersSendingToUs > 0) || (st->webseedsSendingToUs > 0)); + + if (haveDown) + tr_formatter_speed_KBps (dnStr, downloadSpeed_KBps, sizeof (dnStr)); + + if (haveUp) + tr_formatter_speed_KBps (upStr, uploadSpeed_KBps, sizeof (upStr)); + + 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; + return buf; } static void @@ -219,8 +236,7 @@ getShortStatusString (GString * gstr, if (st->activity != TR_STATUS_DOWNLOAD) { tr_strlratio (buf, st->ratio, sizeof (buf)); - g_string_append_printf (gstr, _("Ratio %s"), buf); - g_string_append (gstr, ", "); + g_string_append_printf (gstr, _("Ratio: %s, "), buf); } getShortTransferString (tor, st, uploadSpeed_KBps, downloadSpeed_KBps, buf, sizeof (buf)); g_string_append (gstr, buf); diff --git a/gtk/tr-window.c b/gtk/tr-window.c index 972c923cf..def57bd6e 100644 --- a/gtk/tr-window.c +++ b/gtk/tr-window.c @@ -54,7 +54,9 @@ typedef struct GtkLabel * ul_lb; GtkLabel * dl_lb; GtkLabel * stats_lb; - GtkLabel * gutter_lb; + GtkLabel * freespace_lb; + GtkWidget * freespace_icon; + GtkLabel * count_lb; GtkWidget * alt_speed_image; GtkWidget * alt_speed_button; GtkWidget * options_menu; @@ -607,12 +609,15 @@ gtr_window_new (GtkApplication * app, GtkUIManager * ui_mgr, TrCore * core) int i, n; const char * pch, * style; PrivateData * p; + GtkWidget * sibling = NULL; GtkWidget * ul_lb, * dl_lb; GtkWidget * mainmenu, *toolbar, *filter, *list, *status; - GtkWidget * vbox, *w, *self, *h, *hbox, *menu; + GtkWidget * vbox, *w, *self, *menu; + GtkWidget * grid_w; GtkWindow * win; GtkCssProvider * css_provider; GSList * l; + GtkGrid * grid; 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); /* 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), &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 */ 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); } - /* status */ - h = status = p->status = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD_BIG); - gtk_container_set_border_width (GTK_CONTAINER (h), GUI_PAD_SMALL); + /** + *** Statusbar + **/ + 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 (); gtk_container_add (GTK_CONTAINER (w), gtk_image_new_from_stock ("utilities", -1)); 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); p->options_menu = createOptionsMenu (p); g_signal_connect (w, "clicked", G_CALLBACK (onOptionsClicked), p); + sibling = w; + /* turtle */ p->alt_speed_image = gtk_image_new (); w = p->alt_speed_button = gtk_toggle_button_new (); gtk_button_set_image (GTK_BUTTON (w), p->alt_speed_image); gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE); 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; - w = gtk_label_new ("N Torrents"); - p->gutter_lb = GTK_LABEL (w); - gtk_label_set_single_line_mode (p->gutter_lb, TRUE); - gtk_box_pack_start (GTK_BOX (h), w, 1, 1, GUI_PAD); - - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD); - w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f); - gtk_widget_set_size_request (w, GUI_PAD, 0u); - gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); - w = ul_lb = gtk_label_new (NULL); - p->ul_lb = GTK_LABEL (w); - gtk_label_set_single_line_mode (p->ul_lb, TRUE); - gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); - w = gtk_image_new_from_stock (GTK_STOCK_GO_UP, 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); - w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f); - gtk_widget_set_size_request (w, GUI_PAD, 0u); - gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); - w = dl_lb = gtk_label_new (NULL); - 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); - w = gtk_button_new (); - gtk_widget_set_tooltip_text (w, _("Statistics")); - gtk_container_add (GTK_CONTAINER (w), gtk_image_new_from_stock ("ratio", -1)); - gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE); - g_signal_connect (w, "clicked", G_CALLBACK (onYinYangReleased), p); - gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); - w = gtk_label_new (NULL); - p->stats_lb = GTK_LABEL (w); - gtk_label_set_single_line_mode (p->stats_lb, TRUE); - gtk_box_pack_end (GTK_BOX (hbox), w, FALSE, FALSE, 0); - gtk_box_pack_end (GTK_BOX (h), hbox, FALSE, FALSE, 0); + /* 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"); + p->count_lb = GTK_LABEL (w); + gtk_label_set_single_line_mode (p->count_lb, TRUE); + gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1); + sibling = w; + + /* freespace */ + w = gtk_label_new (NULL); + g_object_set (G_OBJECT(w), "margin-left", GUI_PAD_BIG*2, NULL); + p->freespace_lb = GTK_LABEL (w); + gtk_label_set_single_line_mode (p->freespace_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_HARDDISK, GTK_ICON_SIZE_MENU); + p->freespace_icon = w; + 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; + + /* 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; + + /* ratio */ + w = gtk_label_new (NULL); + p->stats_lb = GTK_LABEL (w); + gtk_label_set_single_line_mode (p->stats_lb, TRUE); + gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1); + sibling = w; + w = gtk_button_new (); + gtk_widget_set_tooltip_text (w, _("Statistics")); + gtk_container_add (GTK_CONTAINER (w), gtk_image_new_from_stock ("ratio", -1)); + gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE); + g_signal_connect (w, "clicked", G_CALLBACK (onYinYangReleased), p); + 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 */ p->view = makeview (p); @@ -792,27 +830,71 @@ gtr_window_new (GtkApplication * app, GtkUIManager * ui_mgr, TrCore * core) static void 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 visibleCount = gtk_tree_model_iter_n_children (p->filter_model, NULL); - if (!torrentCount) - *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); + visible = torrentCount > 0; + + 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 @@ -907,6 +989,7 @@ gtr_window_refresh (GtkWindow * self) updateSpeeds (p); updateTorrentCount (p); updateStats (p); + updateFreeSpace (p); } } diff --git a/qt/mainwin.cc b/qt/mainwin.cc index 803d39694..96ecefca9 100644 --- a/qt/mainwin.cc +++ b/qt/mainwin.cc @@ -435,23 +435,23 @@ TrMainWindow :: createStatusBar () h->addSpacing (HIG::PAD); - l = myDownloadSpeedLabel = new QLabel (this); + l = myUploadSpeedLabel = new QLabel; 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)); + l = new QLabel; + l->setPixmap (getStockIcon ("go-up", QStyle::SP_ArrowUp).pixmap (smallIconSize)); h->addWidget (l); h->addSpacing (HIG::PAD); - l = myUploadSpeedLabel = new QLabel; + l = myDownloadSpeedLabel = new QLabel (this); l->setMinimumWidth (minimumSpeedWidth); l->setAlignment (Qt::AlignRight|Qt::AlignVCenter); h->addWidget (l); - l = new QLabel; - l->setPixmap (getStockIcon ("go-up", QStyle::SP_ArrowUp).pixmap (smallIconSize)); + l = new QLabel (this); + l->setPixmap (getStockIcon ("go-down", QStyle::SP_ArrowDown).pixmap (smallIconSize)); h->addWidget (l); return top; diff --git a/qt/torrent-delegate.cc b/qt/torrent-delegate.cc index 82f7d43d5..d7312186c 100644 --- a/qt/torrent-delegate.cc +++ b/qt/torrent-delegate.cc @@ -183,11 +183,11 @@ TorrentDelegate :: shortTransferString( const Torrent& tor ) const upStr = Formatter::speedToString( tor.uploadSpeed( ) ); 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 ) - str = tr( "%1 %2" ).arg(downArrow).arg(downStr); + str = tr( "%1%2" ).arg(downStr).arg(downArrow); else if( haveUp ) - str = tr( "%1 %2" ).arg(upArrow).arg(upStr); + str = tr( "%1%2" ).arg(upStr).arg(upArrow); else if( tor.isStalled( ) ) str = tr( "Stalled" ); else if( tor.hasMetadata( ) ) @@ -210,7 +210,7 @@ TorrentDelegate :: shortStatusString( const Torrent& tor ) const case TR_STATUS_DOWNLOAD: case TR_STATUS_SEED: if( !tor.isDownloading( ) ) - str = tr( "Ratio: %1, " ).arg( Formatter::ratioToString( tor.ratio( ) ) ); + str = tr( "Ratio: %1, " ).arg( Formatter::ratioToString( tor.ratio( ) ) ); str += shortTransferString( tor ); break; -- 2.40.0