mirror of
https://github.com/transmission/transmission
synced 2025-03-03 10:15:45 +00:00
more experimentation with the shortTransferString
This commit is contained in:
parent
4a059b79b8
commit
20fe66bccf
6 changed files with 84 additions and 103 deletions
|
@ -152,37 +152,31 @@ getShortTransferString (const tr_torrent * tor,
|
|||
char * buf,
|
||||
size_t buflen)
|
||||
{
|
||||
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"),
|
||||
char dnStr[32], upStr[32];
|
||||
tr_formatter_speed_KBps (dnStr, downloadSpeed_KBps, sizeof (dnStr));
|
||||
tr_formatter_speed_KBps (upStr, uploadSpeed_KBps, sizeof (upStr));
|
||||
|
||||
/* down speed, down symbol, up speed, up symbol */
|
||||
g_snprintf (buf, buflen, _("%1$s %2$s %3$s %4$s"),
|
||||
dnStr,
|
||||
gtr_get_unicode_string (GTR_UNICODE_DOWN),
|
||||
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));
|
||||
gtr_get_unicode_string (GTR_UNICODE_UP));
|
||||
}
|
||||
else if (haveUp)
|
||||
{
|
||||
/* unicode up arrow + bandwidth speed */
|
||||
g_snprintf (buf, buflen, _("%1$s %2$s"),
|
||||
char upStr[32];
|
||||
tr_formatter_speed_KBps (upStr, uploadSpeed_KBps, sizeof (upStr));
|
||||
|
||||
/* up speed, up symbol */
|
||||
g_snprintf (buf, buflen, _("%1$s %2$s"),
|
||||
upStr,
|
||||
gtr_get_unicode_string (GTR_UNICODE_UP));
|
||||
}
|
||||
|
@ -190,10 +184,6 @@ getShortTransferString (const tr_torrent * tor,
|
|||
{
|
||||
g_strlcpy (buf, _("Stalled"), buflen);
|
||||
}
|
||||
else if (haveMeta)
|
||||
{
|
||||
g_strlcpy (buf, _("Idle"), buflen);
|
||||
}
|
||||
else
|
||||
{
|
||||
*buf = '\0';
|
||||
|
@ -232,14 +222,12 @@ getShortStatusString (GString * gstr,
|
|||
case TR_STATUS_DOWNLOAD:
|
||||
case TR_STATUS_SEED:
|
||||
{
|
||||
char buf[512];
|
||||
if (st->activity != TR_STATUS_DOWNLOAD)
|
||||
{
|
||||
tr_strlratio (buf, st->ratio, sizeof (buf));
|
||||
g_string_append_printf (gstr, _("Ratio: %s, "), buf);
|
||||
}
|
||||
getShortTransferString (tor, st, uploadSpeed_KBps, downloadSpeed_KBps, buf, sizeof (buf));
|
||||
g_string_append (gstr, buf);
|
||||
char speedStr[64];
|
||||
char ratioStr[64];
|
||||
tr_strlratio (ratioStr, st->ratio, sizeof (ratioStr));
|
||||
getShortTransferString (tor, st, uploadSpeed_KBps, downloadSpeed_KBps, speedStr, sizeof (speedStr));
|
||||
/* download/upload speed, ratio */
|
||||
g_string_append_printf (gstr, "%1$s Ratio: %2$s", speedStr, ratioStr);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -742,22 +742,20 @@ gtr_window_new (GtkApplication * app, GtkUIManager * ui_mgr, TrCore * core)
|
|||
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);
|
||||
/* 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_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);
|
||||
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);
|
||||
g_object_set (G_OBJECT(w), "margin-left", GUI_PAD, 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);
|
||||
|
@ -767,14 +765,18 @@ gtr_window_new (GtkApplication * app, GtkUIManager * ui_mgr, TrCore * core)
|
|||
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);
|
||||
/* ratio */
|
||||
w = gtk_label_new (NULL);
|
||||
g_object_set (G_OBJECT(w), "margin-left", GUI_PAD_BIG, 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_image_new_from_stock (GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_MENU);
|
||||
g_object_set (G_OBJECT(w), "margin-left", GUI_PAD, NULL);
|
||||
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;
|
||||
|
||||
|
|
|
@ -61,8 +61,8 @@ gtr_get_unicode_string (int i)
|
|||
{
|
||||
switch (i)
|
||||
{
|
||||
case GTR_UNICODE_UP: return "\xE2\x86\x91";
|
||||
case GTR_UNICODE_DOWN: return "\xE2\x86\x93";
|
||||
case GTR_UNICODE_UP: return "\xE2\x96\xB4";
|
||||
case GTR_UNICODE_DOWN: return "\xE2\x96\xBE";
|
||||
case GTR_UNICODE_INF: return "\xE2\x88\x9E";
|
||||
case GTR_UNICODE_BULLET: return "\xE2\x88\x99";
|
||||
default: return "err";
|
||||
|
|
|
@ -122,13 +122,9 @@ Formatter :: sizeToString( int64_t bytes )
|
|||
QString
|
||||
Formatter :: speedToString( const Speed& speed )
|
||||
{
|
||||
if( speed.isZero( ) )
|
||||
return tr( "None" );
|
||||
else {
|
||||
char buf[128];
|
||||
tr_formatter_speed_KBps( buf, speed.KBps( ), sizeof( buf ) );
|
||||
return QString::fromUtf8( buf );
|
||||
}
|
||||
char buf[128];
|
||||
tr_formatter_speed_KBps( buf, speed.KBps( ), sizeof( buf ) );
|
||||
return QString::fromUtf8( buf );
|
||||
}
|
||||
|
||||
QString
|
||||
|
|
|
@ -410,6 +410,27 @@ TrMainWindow :: createStatusBar ()
|
|||
|
||||
h->addStretch (1);
|
||||
|
||||
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);
|
||||
|
||||
l = myUploadSpeedLabel = new QLabel;
|
||||
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));
|
||||
h->addWidget (l);
|
||||
|
||||
h->addSpacing (HIG::PAD);
|
||||
|
||||
l = myStatsLabel = new QLabel (this);
|
||||
h->addWidget (l);
|
||||
a = new QActionGroup (this);
|
||||
|
@ -433,27 +454,6 @@ TrMainWindow :: createStatusBar ()
|
|||
p->setMenu (m);
|
||||
h->addWidget (p);
|
||||
|
||||
h->addSpacing (HIG::PAD);
|
||||
|
||||
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;
|
||||
l->setPixmap (getStockIcon ("go-up", QStyle::SP_ArrowUp).pixmap (smallIconSize));
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -168,38 +168,33 @@ TorrentDelegate :: progressString( const Torrent& tor ) const
|
|||
}
|
||||
|
||||
QString
|
||||
TorrentDelegate :: shortTransferString( const Torrent& tor ) const
|
||||
TorrentDelegate :: shortTransferString (const Torrent& tor) const
|
||||
{
|
||||
static const QChar upArrow( 0x2191 );
|
||||
static const QChar downArrow( 0x2193 );
|
||||
const bool haveMeta( tor.hasMetadata( ) );
|
||||
const bool haveDown( haveMeta && ((tor.webseedsWeAreDownloadingFrom()>0) || (tor.peersWeAreDownloadingFrom( )>0)) );
|
||||
const bool haveUp( haveMeta && tor.peersWeAreUploadingTo( ) > 0 );
|
||||
QString downStr, upStr, str;
|
||||
QString str;
|
||||
static const QChar uploadSymbol (0x25B4);
|
||||
static const QChar downloadSymbol (0x25BE);
|
||||
const bool haveMeta (tor.hasMetadata());
|
||||
const bool haveDown (haveMeta && ((tor.webseedsWeAreDownloadingFrom()>0) || (tor.peersWeAreDownloadingFrom()>0)));
|
||||
const bool haveUp (haveMeta && tor.peersWeAreUploadingTo()>0);
|
||||
|
||||
if( haveDown )
|
||||
downStr = Formatter::speedToString( tor.downloadSpeed( ) );
|
||||
if( haveUp )
|
||||
upStr = Formatter::speedToString( tor.uploadSpeed( ) );
|
||||
if (haveDown)
|
||||
str = tr( "%1 %2 %3 %4" ).arg(Formatter::speedToString(tor.downloadSpeed()))
|
||||
.arg(downloadSymbol)
|
||||
.arg(Formatter::speedToString(tor.uploadSpeed()))
|
||||
.arg(uploadSymbol);
|
||||
|
||||
if( haveDown && haveUp )
|
||||
str = tr( "%1%2, %3%4" ).arg(upStr).arg(upArrow).arg(downStr).arg(downArrow);
|
||||
else if( haveDown )
|
||||
str = tr( "%1%2" ).arg(downStr).arg(downArrow);
|
||||
else if( haveUp )
|
||||
str = tr( "%1%2" ).arg(upStr).arg(upArrow);
|
||||
else if( tor.isStalled( ) )
|
||||
str = tr( "Stalled" );
|
||||
else if( tor.hasMetadata( ) )
|
||||
str = tr( "Idle" );
|
||||
else if (haveUp)
|
||||
str = tr( "%1 %2" ).arg(Formatter::speedToString(tor.uploadSpeed()))
|
||||
.arg(uploadSymbol);
|
||||
|
||||
return str;
|
||||
return str;
|
||||
}
|
||||
|
||||
QString
|
||||
TorrentDelegate :: shortStatusString( const Torrent& tor ) const
|
||||
{
|
||||
QString str;
|
||||
static const QChar ratioSymbol (0x262F);
|
||||
|
||||
switch( tor.getActivity( ) )
|
||||
{
|
||||
|
@ -209,9 +204,9 @@ 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 += shortTransferString( tor );
|
||||
str = tr("%1 %2 %3").arg(shortTransferString(tor))
|
||||
.arg(tr("Ratio:"))
|
||||
.arg(Formatter::ratioToString(tor.ratio()));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
Loading…
Reference in a new issue