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,
|
char * buf,
|
||||||
size_t buflen)
|
size_t buflen)
|
||||||
{
|
{
|
||||||
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 (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 */
|
char dnStr[32], upStr[32];
|
||||||
g_snprintf (buf, buflen, _("%1$s %2$s %3$s %4$s"),
|
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,
|
upStr,
|
||||||
gtr_get_unicode_string (GTR_UNICODE_UP),
|
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)
|
else if (haveUp)
|
||||||
{
|
{
|
||||||
/* unicode up arrow + bandwidth speed */
|
char upStr[32];
|
||||||
g_snprintf (buf, buflen, _("%1$s %2$s"),
|
tr_formatter_speed_KBps (upStr, uploadSpeed_KBps, sizeof (upStr));
|
||||||
|
|
||||||
|
/* up speed, up symbol */
|
||||||
|
g_snprintf (buf, buflen, _("%1$s %2$s"),
|
||||||
upStr,
|
upStr,
|
||||||
gtr_get_unicode_string (GTR_UNICODE_UP));
|
gtr_get_unicode_string (GTR_UNICODE_UP));
|
||||||
}
|
}
|
||||||
|
@ -190,10 +184,6 @@ getShortTransferString (const tr_torrent * tor,
|
||||||
{
|
{
|
||||||
g_strlcpy (buf, _("Stalled"), buflen);
|
g_strlcpy (buf, _("Stalled"), buflen);
|
||||||
}
|
}
|
||||||
else if (haveMeta)
|
|
||||||
{
|
|
||||||
g_strlcpy (buf, _("Idle"), buflen);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*buf = '\0';
|
*buf = '\0';
|
||||||
|
@ -232,14 +222,12 @@ getShortStatusString (GString * gstr,
|
||||||
case TR_STATUS_DOWNLOAD:
|
case TR_STATUS_DOWNLOAD:
|
||||||
case TR_STATUS_SEED:
|
case TR_STATUS_SEED:
|
||||||
{
|
{
|
||||||
char buf[512];
|
char speedStr[64];
|
||||||
if (st->activity != TR_STATUS_DOWNLOAD)
|
char ratioStr[64];
|
||||||
{
|
tr_strlratio (ratioStr, st->ratio, sizeof (ratioStr));
|
||||||
tr_strlratio (buf, st->ratio, sizeof (buf));
|
getShortTransferString (tor, st, uploadSpeed_KBps, downloadSpeed_KBps, speedStr, sizeof (speedStr));
|
||||||
g_string_append_printf (gstr, _("Ratio: %s, "), buf);
|
/* download/upload speed, ratio */
|
||||||
}
|
g_string_append_printf (gstr, "%1$s Ratio: %2$s", speedStr, ratioStr);
|
||||||
getShortTransferString (tor, st, uploadSpeed_KBps, downloadSpeed_KBps, buf, sizeof (buf));
|
|
||||||
g_string_append (gstr, buf);
|
|
||||||
break;
|
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);
|
gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
|
||||||
sibling = w;
|
sibling = w;
|
||||||
|
|
||||||
/* ratio */
|
/* download */
|
||||||
w = gtk_label_new (NULL);
|
w = dl_lb = gtk_label_new (NULL);
|
||||||
p->stats_lb = GTK_LABEL (w);
|
p->dl_lb = GTK_LABEL (w);
|
||||||
gtk_label_set_single_line_mode (p->stats_lb, TRUE);
|
gtk_label_set_single_line_mode (p->dl_lb, TRUE);
|
||||||
gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
|
gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
|
||||||
sibling = w;
|
sibling = w;
|
||||||
w = gtk_button_new ();
|
w = gtk_image_new_from_stock (GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_MENU);
|
||||||
gtk_widget_set_tooltip_text (w, _("Statistics"));
|
g_object_set (G_OBJECT(w), "margin-left", GUI_PAD, NULL);
|
||||||
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);
|
gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
|
||||||
sibling = w;
|
sibling = w;
|
||||||
|
|
||||||
/* upload */
|
/* upload */
|
||||||
w = ul_lb = gtk_label_new (NULL);
|
w = ul_lb = gtk_label_new (NULL);
|
||||||
|
g_object_set (G_OBJECT(w), "margin-left", GUI_PAD, NULL);
|
||||||
p->ul_lb = GTK_LABEL (w);
|
p->ul_lb = GTK_LABEL (w);
|
||||||
gtk_label_set_single_line_mode (p->ul_lb, TRUE);
|
gtk_label_set_single_line_mode (p->ul_lb, TRUE);
|
||||||
gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
|
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);
|
gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
|
||||||
sibling = w;
|
sibling = w;
|
||||||
|
|
||||||
/* download */
|
/* ratio */
|
||||||
w = dl_lb = gtk_label_new (NULL);
|
w = gtk_label_new (NULL);
|
||||||
p->dl_lb = GTK_LABEL (w);
|
g_object_set (G_OBJECT(w), "margin-left", GUI_PAD_BIG, NULL);
|
||||||
gtk_label_set_single_line_mode (p->dl_lb, TRUE);
|
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);
|
gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
|
||||||
sibling = w;
|
sibling = w;
|
||||||
w = gtk_image_new_from_stock (GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_MENU);
|
w = gtk_button_new ();
|
||||||
g_object_set (G_OBJECT(w), "margin-left", GUI_PAD, NULL);
|
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);
|
gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
|
||||||
sibling = w;
|
sibling = w;
|
||||||
|
|
||||||
|
|
|
@ -61,8 +61,8 @@ gtr_get_unicode_string (int i)
|
||||||
{
|
{
|
||||||
switch (i)
|
switch (i)
|
||||||
{
|
{
|
||||||
case GTR_UNICODE_UP: return "\xE2\x86\x91";
|
case GTR_UNICODE_UP: return "\xE2\x96\xB4";
|
||||||
case GTR_UNICODE_DOWN: return "\xE2\x86\x93";
|
case GTR_UNICODE_DOWN: return "\xE2\x96\xBE";
|
||||||
case GTR_UNICODE_INF: return "\xE2\x88\x9E";
|
case GTR_UNICODE_INF: return "\xE2\x88\x9E";
|
||||||
case GTR_UNICODE_BULLET: return "\xE2\x88\x99";
|
case GTR_UNICODE_BULLET: return "\xE2\x88\x99";
|
||||||
default: return "err";
|
default: return "err";
|
||||||
|
|
|
@ -122,13 +122,9 @@ Formatter :: sizeToString( int64_t bytes )
|
||||||
QString
|
QString
|
||||||
Formatter :: speedToString( const Speed& speed )
|
Formatter :: speedToString( const Speed& speed )
|
||||||
{
|
{
|
||||||
if( speed.isZero( ) )
|
char buf[128];
|
||||||
return tr( "None" );
|
tr_formatter_speed_KBps( buf, speed.KBps( ), sizeof( buf ) );
|
||||||
else {
|
return QString::fromUtf8( buf );
|
||||||
char buf[128];
|
|
||||||
tr_formatter_speed_KBps( buf, speed.KBps( ), sizeof( buf ) );
|
|
||||||
return QString::fromUtf8( buf );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
|
|
|
@ -410,6 +410,27 @@ TrMainWindow :: createStatusBar ()
|
||||||
|
|
||||||
h->addStretch (1);
|
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);
|
l = myStatsLabel = new QLabel (this);
|
||||||
h->addWidget (l);
|
h->addWidget (l);
|
||||||
a = new QActionGroup (this);
|
a = new QActionGroup (this);
|
||||||
|
@ -433,27 +454,6 @@ TrMainWindow :: createStatusBar ()
|
||||||
p->setMenu (m);
|
p->setMenu (m);
|
||||||
h->addWidget (p);
|
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;
|
return top;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -168,38 +168,33 @@ TorrentDelegate :: progressString( const Torrent& tor ) const
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
TorrentDelegate :: shortTransferString( const Torrent& tor ) const
|
TorrentDelegate :: shortTransferString (const Torrent& tor) const
|
||||||
{
|
{
|
||||||
static const QChar upArrow( 0x2191 );
|
QString str;
|
||||||
static const QChar downArrow( 0x2193 );
|
static const QChar uploadSymbol (0x25B4);
|
||||||
const bool haveMeta( tor.hasMetadata( ) );
|
static const QChar downloadSymbol (0x25BE);
|
||||||
const bool haveDown( haveMeta && ((tor.webseedsWeAreDownloadingFrom()>0) || (tor.peersWeAreDownloadingFrom( )>0)) );
|
const bool haveMeta (tor.hasMetadata());
|
||||||
const bool haveUp( haveMeta && tor.peersWeAreUploadingTo( ) > 0 );
|
const bool haveDown (haveMeta && ((tor.webseedsWeAreDownloadingFrom()>0) || (tor.peersWeAreDownloadingFrom()>0)));
|
||||||
QString downStr, upStr, str;
|
const bool haveUp (haveMeta && tor.peersWeAreUploadingTo()>0);
|
||||||
|
|
||||||
if( haveDown )
|
if (haveDown)
|
||||||
downStr = Formatter::speedToString( tor.downloadSpeed( ) );
|
str = tr( "%1 %2 %3 %4" ).arg(Formatter::speedToString(tor.downloadSpeed()))
|
||||||
if( haveUp )
|
.arg(downloadSymbol)
|
||||||
upStr = Formatter::speedToString( tor.uploadSpeed( ) );
|
.arg(Formatter::speedToString(tor.uploadSpeed()))
|
||||||
|
.arg(uploadSymbol);
|
||||||
|
|
||||||
if( haveDown && haveUp )
|
else if (haveUp)
|
||||||
str = tr( "%1%2, %3%4" ).arg(upStr).arg(upArrow).arg(downStr).arg(downArrow);
|
str = tr( "%1 %2" ).arg(Formatter::speedToString(tor.uploadSpeed()))
|
||||||
else if( haveDown )
|
.arg(uploadSymbol);
|
||||||
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" );
|
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
TorrentDelegate :: shortStatusString( const Torrent& tor ) const
|
TorrentDelegate :: shortStatusString( const Torrent& tor ) const
|
||||||
{
|
{
|
||||||
QString str;
|
QString str;
|
||||||
|
static const QChar ratioSymbol (0x262F);
|
||||||
|
|
||||||
switch( tor.getActivity( ) )
|
switch( tor.getActivity( ) )
|
||||||
{
|
{
|
||||||
|
@ -209,9 +204,9 @@ 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( ) )
|
str = tr("%1 %2 %3").arg(shortTransferString(tor))
|
||||||
str = tr( "Ratio: %1, " ).arg( Formatter::ratioToString( tor.ratio( ) ) );
|
.arg(tr("Ratio:"))
|
||||||
str += shortTransferString( tor );
|
.arg(Formatter::ratioToString(tor.ratio()));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in a new issue