Changeset 13891


Ignore:
Timestamp:
Jan 27, 2013, 11:05:47 PM (8 years ago)
Author:
jordan
Message:

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.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/my-valgrind.sh

    r13670 r13891  
    33export G_DEBUG=gc-friendly
    44export GLIBCXX_FORCE_NEW=1
    5 valgrind --tool=cachegrind ./transmission-gtk 2>&1 | tee runlog
     5#valgrind --tool=cachegrind ./transmission-gtk 2>&1 | tee runlog
    66#valgrind --tool=cachegrind ./transmission-gtk -p -g /tmp/transmission-test 2>&1 | tee runlog
    7 #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
     7valgrind --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
  • trunk/gtk/torrent-cell-renderer.c

    r13817 r13891  
    153153                        size_t              buflen)
    154154{
    155     char downStr[32], upStr[32];
    156     const int haveMeta = tr_torrentHasMetadata (tor);
    157     const int haveUp = haveMeta && st->peersGettingFromUs > 0;
    158     const int haveDown = haveMeta && ((st->peersSendingToUs > 0) || (st->webseedsSendingToUs > 0));
    159 
    160     if (haveDown)
    161         tr_formatter_speed_KBps (downStr, downloadSpeed_KBps, sizeof (downStr));
    162     if (haveUp)
    163         tr_formatter_speed_KBps (upStr, uploadSpeed_KBps, sizeof (upStr));
    164 
    165     if (haveDown && haveUp)
    166         /* 1==down arrow, 2==down speed, 3==up arrow, 4==down speed */
    167         g_snprintf (buf, buflen, _("%1$s %2$s, %3$s %4$s"),
    168                     gtr_get_unicode_string (GTR_UNICODE_DOWN), downStr,
    169                     gtr_get_unicode_string (GTR_UNICODE_UP), upStr);
    170     else if (haveDown)
    171         /* bandwidth speed + unicode arrow */
    172         g_snprintf (buf, buflen, _("%1$s %2$s"),
    173                     gtr_get_unicode_string (GTR_UNICODE_DOWN), downStr);
    174     else if (haveUp)
    175         /* bandwidth speed + unicode arrow */
    176         g_snprintf (buf, buflen, _("%1$s %2$s"),
    177                     gtr_get_unicode_string (GTR_UNICODE_UP), upStr);
    178     else if (st->isStalled)
    179         g_strlcpy (buf, _("Stalled"), buflen);
    180     else if (haveMeta)
    181         g_strlcpy (buf, _("Idle"), buflen);
    182     else
    183         *buf = '\0';
    184 
    185     return buf;
     155  char dnStr[32], upStr[32];
     156  const int haveMeta = tr_torrentHasMetadata (tor);
     157  const int haveUp = haveMeta && st->peersGettingFromUs > 0;
     158  const int haveDown = haveMeta && ((st->peersSendingToUs > 0) || (st->webseedsSendingToUs > 0));
     159
     160  if (haveDown)
     161    tr_formatter_speed_KBps (dnStr, downloadSpeed_KBps, sizeof (dnStr));
     162
     163  if (haveUp)
     164    tr_formatter_speed_KBps (upStr, uploadSpeed_KBps, sizeof (upStr));
     165
     166  if (haveDown && haveUp)
     167    {
     168      /* 1==up speed, 2==up arrow, 3==down speed, 4==down arrow */
     169      g_snprintf (buf, buflen, _("%1$s %2$s    %3$s %4$s"),
     170                  upStr,
     171                  gtr_get_unicode_string (GTR_UNICODE_UP),
     172                  dnStr,
     173                  gtr_get_unicode_string (GTR_UNICODE_DOWN));
     174    }
     175  else if (haveDown)
     176    {
     177      /* unicode down arrow + bandwidth speed */
     178      g_snprintf (buf, buflen, _("%1$s %2$s"),
     179                  dnStr,
     180                  gtr_get_unicode_string (GTR_UNICODE_DOWN));
     181    }
     182  else if (haveUp)
     183    {
     184      /* unicode up arrow + bandwidth speed */
     185      g_snprintf (buf, buflen, _("%1$s %2$s"),
     186                  upStr,
     187                  gtr_get_unicode_string (GTR_UNICODE_UP));
     188    }
     189  else if (st->isStalled)
     190    {
     191      g_strlcpy (buf, _("Stalled"), buflen);
     192    }
     193  else if (haveMeta)
     194    {
     195      g_strlcpy (buf, _("Idle"), buflen);
     196    }
     197  else
     198    {
     199      *buf = '\0';
     200    }
     201
     202  return buf;
    186203}
    187204
     
    220237            {
    221238                tr_strlratio (buf, st->ratio, sizeof (buf));
    222                 g_string_append_printf (gstr, _("Ratio %s"), buf);
    223                 g_string_append (gstr, ", ");
     239                g_string_append_printf (gstr, _("Ratio: %s,   "), buf);
    224240            }
    225241            getShortTransferString (tor, st, uploadSpeed_KBps, downloadSpeed_KBps, buf, sizeof (buf));
  • trunk/gtk/tr-window.c

    r13822 r13891  
    5555    GtkLabel           * dl_lb;
    5656    GtkLabel           * stats_lb;
    57     GtkLabel           * gutter_lb;
     57    GtkLabel           * freespace_lb;
     58    GtkWidget          * freespace_icon;
     59    GtkLabel           * count_lb;
    5860    GtkWidget          * alt_speed_image;
    5961    GtkWidget          * alt_speed_button;
     
    608610  const char     * pch, * style;
    609611  PrivateData    * p;
     612  GtkWidget      * sibling = NULL;
    610613  GtkWidget      * ul_lb, * dl_lb;
    611614  GtkWidget      * mainmenu, *toolbar, *filter, *list, *status;
    612   GtkWidget      * vbox, *w, *self, *h, *hbox, *menu;
     615  GtkWidget      * vbox, *w, *self, *menu;
     616  GtkWidget      * grid_w;
    613617  GtkWindow      * win;
    614618  GtkCssProvider * css_provider;
    615619  GSList         * l;
     620  GtkGrid        * grid;
    616621
    617622  p = g_new0 (PrivateData, 1);
     
    658663
    659664  /* filter */
    660   h = filter = p->filter = gtr_filter_bar_new (gtr_core_session (core),
     665  w = filter = p->filter = gtr_filter_bar_new (gtr_core_session (core),
    661666                                               gtr_core_model (core),
    662667                                               &p->filter_model);
    663   gtk_container_set_border_width (GTK_CONTAINER (h), GUI_PAD_SMALL);
     668  gtk_container_set_border_width (GTK_CONTAINER (w), GUI_PAD_SMALL);
    664669
    665670  /* status menu */
     
    679684    }
    680685
    681   /* status */
    682   h = status = p->status = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD_BIG);
    683   gtk_container_set_border_width (GTK_CONTAINER (h), GUI_PAD_SMALL);
    684 
     686  /**
     687  *** Statusbar
     688  **/
     689
     690  grid_w = status = p->status = gtk_grid_new ();
     691  grid = GTK_GRID (grid_w);
     692  gtk_container_set_border_width (GTK_CONTAINER (grid), GUI_PAD_SMALL);
     693
     694  /* gear */
    685695  w = gtk_button_new ();
    686696  gtk_container_add (GTK_CONTAINER (w), gtk_image_new_from_stock ("utilities", -1));
    687697  gtk_widget_set_tooltip_text (w, _("Options"));
    688   gtk_box_pack_start (GTK_BOX (h), w, 0, 0, 0);
     698  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
    689699  gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE);
    690700  p->options_menu = createOptionsMenu (p);
    691701  g_signal_connect (w, "clicked", G_CALLBACK (onOptionsClicked), p);
    692 
     702  sibling = w;
     703
     704  /* turtle */
    693705  p->alt_speed_image = gtk_image_new ();
    694706  w = p->alt_speed_button = gtk_toggle_button_new ();
     
    696708  gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE);
    697709  g_signal_connect (w, "toggled", G_CALLBACK (alt_speed_toggled_cb), p);
    698   gtk_box_pack_start (GTK_BOX (h), w, 0, 0, 0);
    699 
     710  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     711  sibling = w;
     712
     713  /* spacer */
     714  w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f);
     715  gtk_widget_set_hexpand (w, TRUE);
     716  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     717  sibling = w;
     718
     719  /* torrent count */
    700720  w = gtk_label_new ("N Torrents");
    701   p->gutter_lb = GTK_LABEL (w);
    702   gtk_label_set_single_line_mode (p->gutter_lb, TRUE);
    703   gtk_box_pack_start (GTK_BOX (h), w, 1, 1, GUI_PAD);
    704 
    705   hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD);
    706     w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f);
    707     gtk_widget_set_size_request (w, GUI_PAD, 0u);
    708     gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    709     w = ul_lb = gtk_label_new (NULL);
    710     p->ul_lb = GTK_LABEL (w);
    711     gtk_label_set_single_line_mode (p->ul_lb, TRUE);
    712     gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    713     w = gtk_image_new_from_stock (GTK_STOCK_GO_UP, GTK_ICON_SIZE_MENU);
    714     gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    715   gtk_box_pack_end (GTK_BOX (h), hbox, FALSE, FALSE, 0);
    716 
    717   hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD);
    718     w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f);
    719     gtk_widget_set_size_request (w, GUI_PAD, 0u);
    720     gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    721     w = dl_lb = gtk_label_new (NULL);
    722     p->dl_lb = GTK_LABEL (w);
    723     gtk_label_set_single_line_mode (p->dl_lb, TRUE);
    724     gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    725     w = gtk_image_new_from_stock (GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_MENU);
    726     gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    727   gtk_box_pack_end (GTK_BOX (h), hbox, FALSE, FALSE, 0);
    728 
    729   hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, GUI_PAD);
    730     w = gtk_button_new ();
    731     gtk_widget_set_tooltip_text (w, _("Statistics"));
    732     gtk_container_add (GTK_CONTAINER (w), gtk_image_new_from_stock ("ratio", -1));
    733     gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE);
    734     g_signal_connect (w, "clicked", G_CALLBACK (onYinYangReleased), p);
    735     gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    736     w = gtk_label_new (NULL);
    737     p->stats_lb = GTK_LABEL (w);
    738     gtk_label_set_single_line_mode (p->stats_lb, TRUE);
    739     gtk_box_pack_end (GTK_BOX (hbox), w, FALSE, FALSE, 0);
    740   gtk_box_pack_end (GTK_BOX (h), hbox, FALSE, FALSE, 0);
    741 
     721  p->count_lb = GTK_LABEL (w);
     722  gtk_label_set_single_line_mode (p->count_lb, TRUE);
     723  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     724  sibling = w;
     725
     726  /* freespace */
     727  w = gtk_label_new (NULL);
     728  g_object_set (G_OBJECT(w), "margin-left", GUI_PAD_BIG*2, NULL);
     729  p->freespace_lb = GTK_LABEL (w);
     730  gtk_label_set_single_line_mode (p->freespace_lb, TRUE);
     731  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     732  sibling = w;
     733  w = gtk_image_new_from_stock (GTK_STOCK_HARDDISK, GTK_ICON_SIZE_MENU);
     734  p->freespace_icon = w;
     735  g_object_set (G_OBJECT(w), "margin-left", GUI_PAD, NULL);
     736  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     737  sibling = w;
     738
     739  /* spacer */
     740  w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f);
     741  gtk_widget_set_hexpand (w, TRUE);
     742  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     743  sibling = w;
     744
     745  /* ratio */
     746  w = gtk_label_new (NULL);
     747  p->stats_lb = GTK_LABEL (w);
     748  gtk_label_set_single_line_mode (p->stats_lb, TRUE);
     749  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     750  sibling = w;
     751  w = gtk_button_new ();
     752  gtk_widget_set_tooltip_text (w, _("Statistics"));
     753  gtk_container_add (GTK_CONTAINER (w), gtk_image_new_from_stock ("ratio", -1));
     754  gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE);
     755  g_signal_connect (w, "clicked", G_CALLBACK (onYinYangReleased), p);
     756  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     757  sibling = w;
     758
     759  /* upload */
     760  w = ul_lb = gtk_label_new (NULL);
     761  p->ul_lb = GTK_LABEL (w);
     762  gtk_label_set_single_line_mode (p->ul_lb, TRUE);
     763  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     764  sibling = w;
     765  w = gtk_image_new_from_stock (GTK_STOCK_GO_UP, GTK_ICON_SIZE_MENU);
     766  g_object_set (G_OBJECT(w), "margin-left", GUI_PAD, NULL);
     767  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     768  sibling = w;
     769
     770  /* download */
     771  w = dl_lb = gtk_label_new (NULL);
     772  p->dl_lb = GTK_LABEL (w);
     773  gtk_label_set_single_line_mode (p->dl_lb, TRUE);
     774  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     775  sibling = w;
     776  w = gtk_image_new_from_stock (GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_MENU);
     777  g_object_set (G_OBJECT(w), "margin-left", GUI_PAD, NULL);
     778  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     779  sibling = w;
    742780
    743781  /* workarea */
     
    793831updateTorrentCount (PrivateData * p)
    794832{
    795   if (p && p->core)
    796     {
    797       char buf[512];
     833  bool visible = false;
     834
     835  g_return_if_fail (p != NULL);
     836
     837  if (p->core != NULL)
     838    {
    798839      const int torrentCount = gtk_tree_model_iter_n_children (gtr_core_model (p->core), NULL);
    799840      const int visibleCount = gtk_tree_model_iter_n_children (p->filter_model, NULL);
    800841
    801       if (!torrentCount)
    802         *buf = '\0';
    803       else if (torrentCount != visibleCount)
    804         g_snprintf (buf, sizeof (buf),
    805                     ngettext ("%1$'d of %2$'d Torrent",
    806                               "%1$'d of %2$'d Torrents",
    807                               torrentCount),
    808                     visibleCount, torrentCount);
    809       else
    810         g_snprintf (buf, sizeof (buf),
    811                     ngettext ("%'d Torrent", "%'d Torrents", torrentCount),
    812                     torrentCount);
    813 
    814       gtr_label_set_text (p->gutter_lb, buf);
    815     }
     842      visible = torrentCount > 0;
     843
     844      if (visible)
     845        {
     846          char countStr[512];
     847
     848          if (torrentCount != visibleCount)
     849            g_snprintf (countStr, sizeof (countStr),
     850                        ngettext ("%1$'d of %2$'d Torrent",
     851                                  "%1$'d of %2$'d Torrents",
     852                                  torrentCount),
     853                        visibleCount, torrentCount);
     854          else
     855            g_snprintf (countStr, sizeof (countStr),
     856                        ngettext ("%'d Torrent", "%'d Torrents", torrentCount),
     857                        torrentCount);
     858
     859          gtr_label_set_text (p->count_lb, countStr);
     860        }
     861    }
     862
     863  gtk_widget_set_visible (GTK_WIDGET(p->count_lb), visible);
     864}
     865
     866static void
     867updateFreeSpace (PrivateData * p)
     868{
     869  GtkWidget * w;
     870  bool visible = false;
     871
     872  g_return_if_fail (p != NULL);
     873
     874  w = GTK_WIDGET (p->freespace_lb);
     875
     876  if (p->core != NULL)
     877    {
     878      tr_session * session = gtr_core_session (p->core);
     879      const int64_t n = tr_sessionGetDownloadDirFreeSpace (session);
     880      const char * downloadDir = tr_sessionGetDownloadDir (session);
     881
     882      visible = n >= 0;
     883
     884      if (visible)
     885        {
     886          char * tip;
     887          char sizeStr[32];
     888          tr_strlsize (sizeStr, n, sizeof(sizeStr));
     889          gtk_label_set_text (p->freespace_lb, sizeStr);
     890          tip = tr_strdup_printf (_("Download folder \"%1$s\" has %2$s free"), downloadDir, sizeStr);
     891          gtk_widget_set_tooltip_text (w, tip);
     892          g_free (tip);
     893        }
     894    }
     895
     896  gtk_widget_set_visible (w, visible);
     897  gtk_widget_set_visible (p->freespace_icon, visible);
    816898}
    817899
     
    908990      updateTorrentCount (p);
    909991      updateStats (p);
     992      updateFreeSpace (p);
    910993    }
    911994}
  • trunk/qt/mainwin.cc

    r13888 r13891  
    436436  h->addSpacing (HIG::PAD);
    437437
     438    l = myUploadSpeedLabel = new QLabel;
     439    const int minimumSpeedWidth = l->fontMetrics ().width (Formatter::speedToString (Speed::fromKBps (999.99)));
     440    l->setMinimumWidth (minimumSpeedWidth);
     441    l->setAlignment (Qt::AlignRight|Qt::AlignVCenter);
     442    h->addWidget (l);
     443    l = new QLabel;
     444    l->setPixmap (getStockIcon ("go-up", QStyle::SP_ArrowUp).pixmap (smallIconSize));
     445    h->addWidget (l);
     446
     447  h->addSpacing (HIG::PAD);
     448
    438449    l = myDownloadSpeedLabel = new QLabel (this);
    439     const int minimumSpeedWidth = l->fontMetrics ().width (Formatter::speedToString (Speed::fromKBps (999.99)));
    440450    l->setMinimumWidth (minimumSpeedWidth);
    441451    l->setAlignment (Qt::AlignRight|Qt::AlignVCenter);
     
    443453    l = new QLabel (this);
    444454    l->setPixmap (getStockIcon ("go-down", QStyle::SP_ArrowDown).pixmap (smallIconSize));
    445     h->addWidget (l);
    446 
    447   h->addSpacing (HIG::PAD);
    448 
    449     l = myUploadSpeedLabel = new QLabel;
    450     l->setMinimumWidth (minimumSpeedWidth);
    451     l->setAlignment (Qt::AlignRight|Qt::AlignVCenter);
    452     h->addWidget (l);
    453     l = new QLabel;
    454     l->setPixmap (getStockIcon ("go-up", QStyle::SP_ArrowUp).pixmap (smallIconSize));
    455455    h->addWidget (l);
    456456
  • trunk/qt/torrent-delegate.cc

    r13553 r13891  
    184184
    185185    if( haveDown && haveUp )
    186         str = tr( "%1 %2, %3 %4" ).arg(downArrow).arg(downStr).arg(upArrow).arg(upStr);
     186        str = tr( "%1%2,   %3%4" ).arg(upStr).arg(upArrow).arg(downStr).arg(downArrow);
    187187    else if( haveDown )
    188         str = tr( "%1 %2" ).arg(downArrow).arg(downStr);
     188        str = tr( "%1%2" ).arg(downStr).arg(downArrow);
    189189    else if( haveUp )
    190         str = tr( "%1 %2" ).arg(upArrow).arg(upStr);
     190        str = tr( "%1%2" ).arg(upStr).arg(upArrow);
    191191    else if( tor.isStalled( ) )
    192192        str = tr( "Stalled" );
     
    211211        case TR_STATUS_SEED:
    212212            if( !tor.isDownloading( ) )
    213                 str = tr( "Ratio: %1, " ).arg( Formatter::ratioToString( tor.ratio( ) ) );
     213              str = tr( "Ratio: %1,  " ).arg( Formatter::ratioToString( tor.ratio( ) ) );
    214214            str += shortTransferString( tor );
    215215            break;
Note: See TracChangeset for help on using the changeset viewer.