Changeset 12464


Ignore:
Timestamp:
May 28, 2011, 12:09:15 AM (10 years ago)
Author:
jordan
Message:

(trunk, GTK+/Qt) #4281 "Visualize seed progress like the web client does" -- done, with a modified patch & suggestion from mag

Location:
trunk
Files:
4 edited

Legend:

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

    r12412 r12464  
    539539}
    540540
     541static double
     542get_percent_done( const tr_torrent * tor, const tr_stat * st, bool * seed )
     543{
     544    double d;
     545
     546    if( ( st->activity == TR_STATUS_SEED ) && tr_torrentGetSeedRatio( tor, &d ) )
     547    {
     548        *seed = true;
     549        d = MAX( 0.0, st->seedRatioPercentDone );
     550    }
     551    else
     552    {
     553        *seed = false;
     554        d = MAX( 0.0, st->percentDone );
     555    }
     556
     557    return d;
     558}
     559
    541560static void
    542561render_compact( TorrentCellRenderer   * cell,
     
    557576    GdkPixbuf * icon;
    558577    GdkColor text_color;
     578    bool seed;
    559579
    560580    struct TorrentCellRendererPrivate * p = cell->priv;
     
    562582    const tr_stat * st = tr_torrentStatCached( (tr_torrent*)tor );
    563583    const gboolean active = st->activity != TR_STATUS_STOPPED;
    564     const double percentDone = MAX( 0.0, st->percentDone );
     584    const double percentDone = get_percent_done( tor, st, &seed );
    565585    const gboolean sensitive = active || st->error;
    566586    GString * gstr_stat = p->gstr1;
     
    601621    g_object_set( p->icon_renderer, "pixbuf", icon, "sensitive", sensitive, NULL );
    602622    gtk_cell_renderer_render( p->icon_renderer, window, widget, &icon_area, &icon_area, &icon_area, flags );
    603     g_object_set( p->progress_renderer, "value", (int)(percentDone*100.0), "text", NULL, "sensitive", sensitive, NULL );
     623    g_object_set( p->progress_renderer, "value", (int)(percentDone*100.0), "text", NULL, "sensitive", sensitive,
     624#if GTK_CHECK_VERSION( 3,0,0 )
     625        "inverted", seed,
     626#elif GTK_CHECK_VERSION( 2,6,0 )
     627        "orientation", (seed ? GTK_PROGRESS_RIGHT_TO_LEFT : GTK_PROGRESS_LEFT_TO_RIGHT),
     628#endif
     629        NULL );
    604630    gtk_cell_renderer_render( p->progress_renderer, window, widget, &prog_area, &prog_area, &prog_area, flags );
    605631    g_object_set( p->text_renderer, "text", gstr_stat->str, "scale", SMALL_SCALE, "ellipsize", PANGO_ELLIPSIZE_END, "foreground-gdk", &text_color, NULL );
     
    632658    GdkPixbuf * icon;
    633659    GdkColor text_color;
     660    bool seed;
    634661
    635662    struct TorrentCellRendererPrivate * p = cell->priv;
     
    638665    const tr_info * inf = tr_torrentInfo( tor );
    639666    const gboolean active = st->activity != TR_STATUS_STOPPED;
    640     const double percentDone = MAX( 0.0, st->percentDone );
     667    const double percentDone = get_percent_done( tor, st, &seed );
    641668    const gboolean sensitive = active || st->error;
    642669    GString * gstr_prog = p->gstr1;
     
    715742    g_object_set( p->text_renderer, "text", gstr_prog->str, "scale", SMALL_SCALE, "weight", PANGO_WEIGHT_NORMAL, NULL );
    716743    gtk_cell_renderer_render( p->text_renderer, window, widget, &prog_area, &prog_area, &prog_area, flags );
    717     g_object_set( p->progress_renderer, "value", (int)(percentDone*100.0), "text", "", "sensitive", sensitive, NULL );
     744    g_object_set( p->progress_renderer, "value", (int)(percentDone*100.0), "text", "", "sensitive", sensitive,
     745#if GTK_CHECK_VERSION( 3,0,0 )
     746        "inverted", seed,
     747#elif GTK_CHECK_VERSION( 2,6,0 )
     748        "orientation", (seed ? GTK_PROGRESS_RIGHT_TO_LEFT : GTK_PROGRESS_LEFT_TO_RIGHT),
     749#endif
     750        NULL );
    718751    gtk_cell_renderer_render( p->progress_renderer, window, widget, &prct_area, &prct_area, &prct_area, flags );
    719752    g_object_set( p->text_renderer, "text", gstr_stat->str, NULL );
  • trunk/qt/torrent-delegate-min.cc

    r11097 r12464  
    163163    myProgressBarStyle->text = buf;
    164164    myProgressBarStyle->textVisible = true;
    165     myProgressBarStyle->progress = int(myProgressBarStyle->minimum + (((isMagnet ? tor.metadataPercentDone() : tor.percentDone()) * (myProgressBarStyle->maximum - myProgressBarStyle->minimum))));
     165    setProgressBarPercentDone( option, tor );
    166166    style->drawControl( QStyle::CE_ProgressBar, myProgressBarStyle, painter );
    167167
  • trunk/qt/torrent-delegate.cc

    r11198 r12464  
    318318
    319319void
     320TorrentDelegate :: setProgressBarPercentDone( const QStyleOptionViewItem& option, const Torrent& tor ) const
     321{
     322    double seedRatioLimit;
     323    if (tor.isSeeding() && tor.getSeedRatio(seedRatioLimit))
     324    {
     325        const double seedRateRatio = tor.ratio() / seedRatioLimit;
     326        const double invertedRatio = 1. - seedRateRatio;
     327        const int scaledProgress = invertedRatio * (myProgressBarStyle->maximum - myProgressBarStyle->minimum);
     328        myProgressBarStyle->progress = myProgressBarStyle->minimum + scaledProgress;
     329        myProgressBarStyle->direction = (option.direction == Qt::RightToLeft ? Qt::LeftToRight : Qt::RightToLeft);
     330    }
     331    else
     332    {
     333        const bool isMagnet( !tor.hasMetadata( ) );
     334        myProgressBarStyle->direction = option.direction;
     335        myProgressBarStyle->progress = int(myProgressBarStyle->minimum + (((isMagnet ? tor.metadataPercentDone() : tor.percentDone()) * (myProgressBarStyle->maximum - myProgressBarStyle->minimum))));
     336    }
     337}
     338
     339void
    320340TorrentDelegate :: drawTorrent( QPainter * painter, const QStyleOptionViewItem& option, const Torrent& tor ) const
    321341{
     
    396416    painter->setFont( progressFont );
    397417    painter->drawText( progArea, 0, progressFM.elidedText( progressStr, Qt::ElideRight, progArea.width( ) ) );
    398     const bool isMagnet( !tor.hasMetadata( ) );
    399418    myProgressBarStyle->rect = barArea;
    400     myProgressBarStyle->direction = option.direction;
    401419    myProgressBarStyle->palette = option.palette;
    402420    myProgressBarStyle->palette.setCurrentColorGroup( cg );
    403421    myProgressBarStyle->state = progressBarState;
    404     myProgressBarStyle->progress = int(myProgressBarStyle->minimum + (((isMagnet ? tor.metadataPercentDone() : tor.percentDone()) * (myProgressBarStyle->maximum - myProgressBarStyle->minimum))));
     422    setProgressBarPercentDone( option, tor );
     423
    405424    style->drawControl( QStyle::CE_ProgressBar, myProgressBarStyle, painter );
    406425
  • trunk/qt/torrent-delegate.h

    r11092 r12464  
    3939        QSize margin( const QStyle& style ) const;
    4040        virtual QSize sizeHint( const QStyleOptionViewItem&, const Torrent& ) const;
     41        virtual void setProgressBarPercentDone( const QStyleOptionViewItem& option, const Torrent& ) const;
    4142        virtual void drawTorrent( QPainter* painter, const QStyleOptionViewItem& option, const Torrent& ) const;
    4243
Note: See TracChangeset for help on using the changeset viewer.