Changeset 5097


Ignore:
Timestamp:
Feb 23, 2008, 5:02:42 PM (14 years ago)
Author:
charles
Message:

(gtk) experimental: use native gtk progress bars

File:
1 edited

Legend:

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

    r5050 r5097  
    1414#include <gtk/gtk.h>
    1515#include <gtk/gtkcellrenderertext.h>
     16#include <gtk/gtkcellrendererprogress.h>
    1617#include <glib/gi18n.h>
    1718#include <libtransmission/transmission.h>
     
    3031    P_SHOW_UNAVAILABLE,
    3132    P_GRADIENT,
     33    P_NATIVE_PROGRESS,
    3234    P_COLOR_VERIFIED,
    3335    P_COLOR_VERIFIED_2,
     
    252254    GtkCellRenderer * text_renderer;
    253255    GtkCellRenderer * text_renderer_err;
     256    GtkCellRenderer * progress_renderer;
    254257    int bar_height;
    255258    gboolean minimal;
    256259    gboolean show_unavailable;
    257260    gboolean gradient;
     261    gboolean use_native_progress;
    258262    GdkColor color_paused[2];
    259263    GdkColor color_verified[2];
     
    539543            ? p->text_renderer_err
    540544            : p->text_renderer;
     545        const gboolean isActive = torStat->status != TR_STATUS_STOPPED;
    541546
    542547        g_object_get( self, "xpad", &xpad, "ypad", &ypad, NULL );
     
    547552        my_bg.width -= xpad*2;
    548553        my_cell = my_expose = my_bg;
     554
     555        g_object_set( text_renderer, "sensitive", isActive, NULL );
     556        g_object_set( p->progress_renderer, "sensitive", isActive, NULL );
    549557
    550558        /* above the progressbar */
     
    631639        /* the progressbar */
    632640        my_cell.height = p->bar_height;
    633         drawRegularBar( self, info, torStat, window, widget, &my_cell );
     641        if( p->use_native_progress )
     642        {
     643            const double havePercent = ( torStat->haveValid + torStat->haveUnchecked )
     644                                                              / (double)info->totalSize;
     645            g_object_set( p->progress_renderer, "value", (int)(havePercent*100.0),
     646                                                "text", "",
     647                                                NULL );
     648            gtk_cell_renderer_render( p->progress_renderer,
     649                                      window, widget,
     650                                      &my_cell, &my_cell, &my_cell, flags );
     651 
     652        }
     653        else
     654        {
     655            drawRegularBar( self, info, torStat, window, widget, &my_cell );
     656        }
    634657        my_bg.y     += my_cell.height;
    635658        my_cell.y   += my_cell.height;
     
    699722        case P_MINIMAL:     p->minimal  = g_value_get_boolean( v ); break;
    700723        case P_GRADIENT:    p->gradient = g_value_get_boolean( v ); break;
     724        case P_NATIVE_PROGRESS: p->use_native_progress = g_value_get_boolean( v ); break;
    701725        case P_SHOW_UNAVAILABLE:
    702726                            p->show_unavailable = g_value_get_boolean( v ); break;
     
    747771        case P_MINIMAL:     g_value_set_boolean( v, p->minimal ); break;
    748772        case P_GRADIENT:    g_value_set_boolean( v, p->gradient ); break;
     773        case P_NATIVE_PROGRESS: g_value_set_boolean( v, p->use_native_progress ); break;
    749774        case P_SHOW_UNAVAILABLE:
    750775                            g_value_set_boolean( v, p->show_unavailable ); break;
     
    765790        g_object_unref( G_OBJECT( r->priv->text_renderer ) );
    766791        g_object_unref( G_OBJECT( r->priv->text_renderer_err ) );
     792        g_object_unref( G_OBJECT( r->priv->progress_renderer ) );
    767793        r->priv = NULL;
    768794    }
     
    803829    g_object_class_install_property( gobject_class, P_GRADIENT,
    804830        g_param_spec_boolean( "gradient", NULL, "Render Progress as a Gradient",
     831                              TRUE, G_PARAM_READWRITE ) );
     832
     833    g_object_class_install_property( gobject_class, P_NATIVE_PROGRESS,
     834        g_param_spec_boolean( "use-native-progress", NULL, "Use Native GtkProgressBars",
    805835                              TRUE, G_PARAM_READWRITE ) );
    806836
     
    879909    p->text_renderer = gtk_cell_renderer_text_new( );
    880910    p->text_renderer_err = gtk_cell_renderer_text_new(  );
     911    p->progress_renderer = gtk_cell_renderer_progress_new(  );
    881912    g_object_set( p->text_renderer_err, "foreground", "red", NULL );
    882913    tr_object_ref_sink( p->text_renderer );
    883914    tr_object_ref_sink( p->text_renderer_err );
     915    tr_object_ref_sink( p->progress_renderer );
    884916
    885917    p->gradient = TRUE;
    886918    p->show_unavailable = TRUE;
     919    p->use_native_progress = TRUE;
    887920    p->bar_height = DEFAULT_BAR_HEIGHT;
    888921
Note: See TracChangeset for help on using the changeset viewer.