Changeset 13897


Ignore:
Timestamp:
Jan 30, 2013, 12:22:52 AM (8 years ago)
Author:
jordan
Message:

more experimentation with the shortTransferString

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/torrent-cell-renderer.c

    r13891 r13897  
    153153                        size_t              buflen)
    154154{
    155   char dnStr[32], upStr[32];
    156155  const int haveMeta = tr_torrentHasMetadata (tor);
    157156  const int haveUp = haveMeta && st->peersGettingFromUs > 0;
    158157  const int haveDown = haveMeta && ((st->peersSendingToUs > 0) || (st->webseedsSendingToUs > 0));
    159158
     159
    160160  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),
     161    {
     162      char dnStr[32], upStr[32];
     163      tr_formatter_speed_KBps (dnStr, downloadSpeed_KBps, sizeof (dnStr));
     164      tr_formatter_speed_KBps (upStr, uploadSpeed_KBps, sizeof (upStr));
     165
     166      /* down speed, down symbol, up speed, up symbol */
     167      g_snprintf (buf, buflen, _("%1$s %2$s  %3$s %4$s"),
    172168                  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"),
     169                  gtr_get_unicode_string (GTR_UNICODE_DOWN),
    186170                  upStr,
    187171                  gtr_get_unicode_string (GTR_UNICODE_UP));
    188172    }
     173  else if (haveUp)
     174    {
     175      char upStr[32];
     176      tr_formatter_speed_KBps (upStr, uploadSpeed_KBps, sizeof (upStr));
     177
     178      /* up speed, up symbol */
     179      g_snprintf (buf, buflen, _("%1$s  %2$s"),
     180                  upStr,
     181                  gtr_get_unicode_string (GTR_UNICODE_UP));
     182    }
    189183  else if (st->isStalled)
    190184    {
    191185      g_strlcpy (buf, _("Stalled"), buflen);
    192     }
    193   else if (haveMeta)
    194     {
    195       g_strlcpy (buf, _("Idle"), buflen);
    196186    }
    197187  else
     
    233223        case TR_STATUS_SEED:
    234224        {
    235             char buf[512];
    236             if (st->activity != TR_STATUS_DOWNLOAD)
    237             {
    238                 tr_strlratio (buf, st->ratio, sizeof (buf));
    239                 g_string_append_printf (gstr, _("Ratio: %s,   "), buf);
    240             }
    241             getShortTransferString (tor, st, uploadSpeed_KBps, downloadSpeed_KBps, buf, sizeof (buf));
    242             g_string_append (gstr, buf);
     225            char speedStr[64];
     226            char ratioStr[64];
     227            tr_strlratio (ratioStr, st->ratio, sizeof (ratioStr));
     228            getShortTransferString (tor, st, uploadSpeed_KBps, downloadSpeed_KBps, speedStr, sizeof (speedStr));
     229            /* download/upload speed, ratio */
     230            g_string_append_printf (gstr, "%1$s  Ratio: %2$s", speedStr, ratioStr);
    243231            break;
    244232        }
  • trunk/gtk/tr-window.c

    r13891 r13897  
    743743  sibling = w;
    744744
     745  /* download */
     746  w = dl_lb = gtk_label_new (NULL);
     747  p->dl_lb = GTK_LABEL (w);
     748  gtk_label_set_single_line_mode (p->dl_lb, TRUE);
     749  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     750  sibling = w;
     751  w = gtk_image_new_from_stock (GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_MENU);
     752  g_object_set (G_OBJECT(w), "margin-left", GUI_PAD, NULL);
     753  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     754  sibling = w;
     755
     756  /* upload */
     757  w = ul_lb = gtk_label_new (NULL);
     758  g_object_set (G_OBJECT(w), "margin-left", GUI_PAD, NULL);
     759  p->ul_lb = GTK_LABEL (w);
     760  gtk_label_set_single_line_mode (p->ul_lb, TRUE);
     761  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     762  sibling = w;
     763  w = gtk_image_new_from_stock (GTK_STOCK_GO_UP, GTK_ICON_SIZE_MENU);
     764  g_object_set (G_OBJECT(w), "margin-left", GUI_PAD, NULL);
     765  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
     766  sibling = w;
     767
    745768  /* ratio */
    746769  w = gtk_label_new (NULL);
     770  g_object_set (G_OBJECT(w), "margin-left", GUI_PAD_BIG, NULL);
    747771  p->stats_lb = GTK_LABEL (w);
    748772  gtk_label_set_single_line_mode (p->stats_lb, TRUE);
     
    754778  gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE);
    755779  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);
    778780  gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
    779781  sibling = w;
  • trunk/gtk/util.c

    r13761 r13897  
    6262  switch (i)
    6363    {
    64       case GTR_UNICODE_UP:      return "\xE2\x86\x91";
    65       case GTR_UNICODE_DOWN:    return "\xE2\x86\x93";
     64      case GTR_UNICODE_UP:      return "\xE2\x96\xB4";
     65      case GTR_UNICODE_DOWN:    return "\xE2\x96\xBE";
    6666      case GTR_UNICODE_INF:     return "\xE2\x88\x9E";
    6767      case GTR_UNICODE_BULLET:  return "\xE2\x88\x99";
  • trunk/qt/formatter.cc

    r13799 r13897  
    123123Formatter :: speedToString( const Speed& speed )
    124124{
    125     if( speed.isZero( ) )
    126         return tr( "None" );
    127     else {
    128         char buf[128];
    129         tr_formatter_speed_KBps( buf, speed.KBps( ), sizeof( buf ) );
    130         return QString::fromUtf8( buf );
    131     }
     125  char buf[128];
     126  tr_formatter_speed_KBps( buf, speed.KBps( ), sizeof( buf ) );
     127  return QString::fromUtf8( buf );
    132128}
    133129
  • trunk/qt/mainwin.cc

    r13891 r13897  
    411411  h->addStretch (1);
    412412
     413    l = myDownloadSpeedLabel = new QLabel (this);
     414    const int minimumSpeedWidth = l->fontMetrics ().width (Formatter::speedToString (Speed::fromKBps (999.99)));
     415    l->setMinimumWidth (minimumSpeedWidth);
     416    l->setAlignment (Qt::AlignRight|Qt::AlignVCenter);
     417    h->addWidget (l);
     418    l = new QLabel (this);
     419    l->setPixmap (getStockIcon ("go-down", QStyle::SP_ArrowDown).pixmap (smallIconSize));
     420    h->addWidget (l);
     421
     422  h->addSpacing (HIG::PAD);
     423
     424    l = myUploadSpeedLabel = new QLabel;
     425    l->setMinimumWidth (minimumSpeedWidth);
     426    l->setAlignment (Qt::AlignRight|Qt::AlignVCenter);
     427    h->addWidget (l);
     428    l = new QLabel;
     429    l->setPixmap (getStockIcon ("go-up", QStyle::SP_ArrowUp).pixmap (smallIconSize));
     430    h->addWidget (l);
     431
     432  h->addSpacing (HIG::PAD);
     433
    413434    l = myStatsLabel = new QLabel (this);
    414435    h->addWidget (l);
     
    434455    h->addWidget (p);
    435456
    436   h->addSpacing (HIG::PAD);
    437 
    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 
    449     l = myDownloadSpeedLabel = new QLabel (this);
    450     l->setMinimumWidth (minimumSpeedWidth);
    451     l->setAlignment (Qt::AlignRight|Qt::AlignVCenter);
    452     h->addWidget (l);
    453     l = new QLabel (this);
    454     l->setPixmap (getStockIcon ("go-down", QStyle::SP_ArrowDown).pixmap (smallIconSize));
    455     h->addWidget (l);
    456 
    457457  return top;
    458458}
  • trunk/qt/torrent-delegate.cc

    r13891 r13897  
    169169
    170170QString
    171 TorrentDelegate :: shortTransferString( const Torrent& tor ) const
    172 {
    173     static const QChar upArrow( 0x2191 );
    174     static const QChar downArrow( 0x2193 );
    175     const bool haveMeta( tor.hasMetadata( ) );
    176     const bool haveDown( haveMeta && ((tor.webseedsWeAreDownloadingFrom()>0) || (tor.peersWeAreDownloadingFrom( )>0)) );
    177     const bool haveUp( haveMeta && tor.peersWeAreUploadingTo( ) > 0 );
    178     QString downStr, upStr, str;
    179 
    180     if( haveDown )
    181         downStr = Formatter::speedToString( tor.downloadSpeed( ) );
    182     if( haveUp )
    183         upStr = Formatter::speedToString( tor.uploadSpeed( ) );
    184 
    185     if( haveDown && haveUp )
    186         str = tr( "%1%2,   %3%4" ).arg(upStr).arg(upArrow).arg(downStr).arg(downArrow);
    187     else if( haveDown )
    188         str = tr( "%1%2" ).arg(downStr).arg(downArrow);
    189     else if( haveUp )
    190         str = tr( "%1%2" ).arg(upStr).arg(upArrow);
    191     else if( tor.isStalled( ) )
    192         str = tr( "Stalled" );
    193     else if( tor.hasMetadata( ) )
    194         str = tr( "Idle" );
    195 
    196     return str;
     171TorrentDelegate :: shortTransferString (const Torrent& tor) const
     172{
     173  QString str;
     174  static const QChar uploadSymbol (0x25B4);
     175  static const QChar downloadSymbol (0x25BE);
     176  const bool haveMeta (tor.hasMetadata());
     177  const bool haveDown (haveMeta && ((tor.webseedsWeAreDownloadingFrom()>0) || (tor.peersWeAreDownloadingFrom()>0)));
     178  const bool haveUp (haveMeta && tor.peersWeAreUploadingTo()>0);
     179
     180  if (haveDown)
     181    str = tr( "%1 %2   %3 %4" ).arg(Formatter::speedToString(tor.downloadSpeed()))
     182                               .arg(downloadSymbol)
     183                               .arg(Formatter::speedToString(tor.uploadSpeed()))
     184                               .arg(uploadSymbol);
     185
     186  else if (haveUp)
     187    str = tr( "%1 %2" ).arg(Formatter::speedToString(tor.uploadSpeed()))
     188                       .arg(uploadSymbol);
     189
     190  return str;
    197191}
    198192
     
    201195{
    202196    QString str;
     197    static const QChar ratioSymbol (0x262F);
    203198
    204199    switch( tor.getActivity( ) )
     
    210205        case TR_STATUS_DOWNLOAD:
    211206        case TR_STATUS_SEED:
    212             if( !tor.isDownloading( ) )
    213               str = tr( "Ratio: %1,   " ).arg( Formatter::ratioToString( tor.ratio( ) ) );
    214             str += shortTransferString( tor );
     207            str = tr("%1    %2 %3").arg(shortTransferString(tor))
     208                                   .arg(tr("Ratio:"))
     209                                   .arg(Formatter::ratioToString(tor.ratio()));
    215210            break;
    216211
Note: See TracChangeset for help on using the changeset viewer.