Changeset 10388


Ignore:
Timestamp:
Mar 16, 2010, 12:45:12 AM (12 years ago)
Author:
charles
Message:

(trunk gtk) a little more filter/favicon cleanup. remove the submenu headers from the Category combobox, suggested by kklimonda

Location:
trunk/gtk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/favicon.c

    • Property svn:keywords set to Date Rev Author Id
    r10385 r10388  
    88 * the Transmission project.
    99 *
    10  * $Id:$
     10 * $Id$
    1111 */
    1212
     
    5353
    5454static void
    55 favicon_save_cache_file( const char * host, const void * data, size_t len )
     55favicon_save_to_cache( const char * host, const void * data, size_t len )
    5656{
    5757    char * filename = favicon_get_cache_filename( host );
     
    6161
    6262static GdkPixbuf*
    63 favicon_load_from_file( const char * host )
     63favicon_load_from_cache( const char * host )
    6464{
    6565    char * filename = favicon_get_cache_filename( host );
     
    7979    if( fav->len > 0 )
    8080    {
    81         favicon_save_cache_file( fav->host, fav->contents, fav->len );
    82         pixbuf = favicon_load_from_file( fav->host );
     81        favicon_save_to_cache( fav->host, fav->contents, fav->len );
     82        pixbuf = favicon_load_from_cache( fav->host );
    8383    }
    8484
     
    111111                 gpointer      pixbuf_ready_func_data )
    112112{
    113     GdkPixbuf * pixbuf = favicon_load_from_file( host );
     113    GdkPixbuf * pixbuf = favicon_load_from_cache( host );
    114114
    115115    if( pixbuf != NULL )
     
    123123
    124124        g_debug( "trying favicon from \"%s\"", url );
    125         data  = g_new( struct favicon_data, 1 );
     125        data = g_new( struct favicon_data, 1 );
    126126        data->func = pixbuf_ready_func;
    127127        data->data = pixbuf_ready_func_data;
  • trunk/gtk/favicon.h

    • Property svn:keywords set to Date Rev Author Id
    r10380 r10388  
    88 * the Transmission project.
    99 *
    10  * $Id:$
     10 * $Id$
    1111 */
    1212
  • trunk/gtk/filter.c

    • Property svn:keywords set to Date Rev Author Id
    r10385 r10388  
    88 * the Transmission project.
    99 *
    10  * $Id:$
     10 * $Id$
    1111 */
    1212
     
    3030
    3131#if !GTK_CHECK_VERSION( 2,16,0 )
    32  /* FIXME: when 2.16 has been out long enough, it would be really nice to
    33   * get rid of this libsexy usage because of its makefile strangeness */
     32 /* FIXME: when 2.16 has been out long enough, it would be good to
     33  * get rid of libsexy because of its makefile strangeness */
    3434 #define USE_SEXY
    3535 #include "sexy-icon-entry.h"
     
    156156    int private = 0;
    157157    int store_pos;
     158    GtkTreeIter top;
    158159    GtkTreeIter iter;
    159     GtkTreeIter parent;
    160160    GtkTreeModel * model = GTK_TREE_MODEL( store );
    161161    GPtrArray * hosts = g_ptr_array_new( );
     
    231231
    232232    /* update the "all" count */
    233     gtk_tree_model_iter_nth_child( model, &iter, NULL, 0 );
    234     category_model_update_count( store, &iter, all );
     233    gtk_tree_model_iter_children( model, &top, NULL );
     234    category_model_update_count( store, &top, all );
     235
     236    /* skip separator */
     237    gtk_tree_model_iter_next( model, &top );
    235238
    236239    /* update the "public" subtree */
    237     gtk_tree_model_iter_nth_child( model, &parent, NULL, 2 );
    238     gtk_tree_model_iter_nth_child( model, &iter, &parent, 0 );
     240    gtk_tree_model_iter_next( model, &top );
     241    gtk_tree_model_iter_children( model, &iter, &top );
    239242    category_model_update_count( store, &iter, public );
    240     gtk_tree_model_iter_nth_child( model, &iter, &parent, 1 );
     243    gtk_tree_model_iter_next( model, &iter );
    241244    category_model_update_count( store, &iter, private );
    242245
    243246    /* update the "priority" subtree */
    244     gtk_tree_model_iter_nth_child( model, &parent, NULL, 3 );
    245     gtk_tree_model_iter_nth_child( model, &iter, &parent, 0 );
     247    gtk_tree_model_iter_next( model, &top );
     248    gtk_tree_model_iter_children( model, &iter, &top );
    246249    category_model_update_count( store, &iter, high );
    247     gtk_tree_model_iter_nth_child( model, &iter, &parent, 1 );
     250    gtk_tree_model_iter_next( model, &iter );
    248251    category_model_update_count( store, &iter, normal );
    249     gtk_tree_model_iter_nth_child( model, &iter, &parent, 2 );
     252    gtk_tree_model_iter_next( model, &iter );
    250253    category_model_update_count( store, &iter, low );
    251254
    252255    /* update the "hosts" subtree */
    253     gtk_tree_model_iter_nth_child( model, &parent, NULL, 4 );
     256    gtk_tree_model_iter_next( model, &top );
    254257    for( i=store_pos=0, n=hosts->len ; ; )
    255258    {
    256259        const gboolean new_hosts_done = i >= n;
    257         const gboolean old_hosts_done = !gtk_tree_model_iter_nth_child( model, &iter, &parent, store_pos );
     260        const gboolean old_hosts_done = !gtk_tree_model_iter_nth_child( model, &iter, &top, store_pos );
    258261        gboolean remove_row = FALSE;
    259262        gboolean insert_row = FALSE;
     
    264267
    265268        /* decide what to do */
    266         if( new_hosts_done ) {
    267             /* g_message( "new hosts done; remove row" ); */
     269        if( new_hosts_done )
    268270            remove_row = TRUE;
    269         } else if( old_hosts_done ) {
    270             /* g_message( "old hosts done; insert row" ); */
     271        else if( old_hosts_done )
    271272            insert_row = TRUE;
    272         } else {
     273        else {
    273274            int cmp;
    274275            char * host;
    275276            gtk_tree_model_get( model, &iter, CAT_FILTER_COL_HOST, &host,  -1 );
    276277            cmp = strcmp( host, hosts->pdata[i] );
    277             /* g_message( "cmp( %s, %s ) returns %d", host, (char*)hosts->pdata[i], cmp ); */
    278             if( cmp < 0 ) {
    279                 /* g_message( "cmp<0, so remove row" ); */
     278            if( cmp < 0 )
    280279                remove_row = TRUE;
    281             } else if( cmp > 0 ) {
    282                 /* g_message( "cmp>0, so insert row" ); */
     280            else if( cmp > 0 )
    283281                insert_row = TRUE;
    284             }
    285282            g_free( host );
    286283        }
     
    291288            gtk_tree_store_remove( store, &iter );
    292289        } else if( insert_row ) {
    293             GtkTreeIter child;
     290            GtkTreeIter add;
    294291            GtkTreePath * path;
    295292            GtkTreeRowReference * reference;
     
    298295            char * name = get_name_from_host( host );
    299296            const int count = *(int*)g_hash_table_lookup( hosts_hash, host );
    300             gtk_tree_store_insert_with_values( store, &child, &parent, store_pos,
     297            gtk_tree_store_insert_with_values( store, &add, &top, store_pos,
    301298                CAT_FILTER_COL_HOST, host,
    302299                CAT_FILTER_COL_NAME, name,
     
    304301                CAT_FILTER_COL_TYPE, CAT_FILTER_TYPE_HOST,
    305302                -1 );
    306             path = gtk_tree_model_get_path( model, &child );
     303            path = gtk_tree_model_get_path( model, &add );
    307304            reference = gtk_tree_row_reference_new( model, path );
    308305            gtr_get_favicon( session, host, favicon_ready_cb, reference );
     
    331328{
    332329    GtkTreeIter iter;
    333     GtkTreeStore * store;
    334330    const int invisible_number = -1; /* doesn't get rendered */
    335 
    336     store = gtk_tree_store_new( CAT_FILTER_N_COLS,
    337                                 G_TYPE_STRING,
    338                                 G_TYPE_INT,
    339                                 G_TYPE_INT,
    340                                 G_TYPE_STRING,
    341                                 GDK_TYPE_PIXBUF );
     331    GtkTreeStore * store = gtk_tree_store_new( CAT_FILTER_N_COLS,
     332                                               G_TYPE_STRING,
     333                                               G_TYPE_INT,
     334                                               G_TYPE_INT,
     335                                               G_TYPE_STRING,
     336                                               GDK_TYPE_PIXBUF );
    342337
    343338    gtk_tree_store_insert_with_values( store, NULL, NULL, -1,
     
    438433{
    439434    int type;
     435    int width = 0;
     436    const gboolean leaf = !gtk_tree_model_iter_has_child( tree_model, iter );
     437
    440438    gtk_tree_model_get( tree_model, iter, CAT_FILTER_COL_TYPE, &type, -1 );
    441     g_object_set( cell_renderer, "width", type==CAT_FILTER_TYPE_HOST ? 20 : 0, NULL );
    442 }
     439    if( type == CAT_FILTER_TYPE_HOST )
     440        width = 20;
     441
     442    g_object_set( cell_renderer, "width", width,
     443                                 "sensitive", leaf,
     444                                 NULL );
     445}
     446
     447static void
     448is_capital_sensitive( GtkCellLayout   * cell_layout UNUSED,
     449                      GtkCellRenderer * cell_renderer,
     450                      GtkTreeModel    * tree_model,
     451                      GtkTreeIter     * iter,
     452                      gpointer          data UNUSED )
     453{
     454    const gboolean leaf = !gtk_tree_model_iter_has_child( tree_model, iter );
     455
     456    g_object_set( cell_renderer, "sensitive", leaf,
     457                                 NULL );
     458}
     459
    443460static void
    444461render_number_func( GtkCellLayout    * cell_layout UNUSED,
     
    449466{
    450467    int count;
    451     char buf[512];
     468    char buf[32];
     469    const gboolean leaf = !gtk_tree_model_iter_has_child( tree_model, iter );
    452470
    453471    gtk_tree_model_get( tree_model, iter, CAT_FILTER_COL_COUNT, &count, -1 );
     
    458476        *buf = '\0';
    459477
    460     g_object_set( cell_renderer, "text", buf, NULL );
     478    g_object_set( cell_renderer, "text", buf,
     479                                 "sensitive", leaf,
     480                                 NULL );
    461481}
    462482
     
    480500    GtkWidget * c;
    481501    GtkCellRenderer * r;
    482     GtkTreeModel * category_model;
     502    GtkTreeModel * cat_model;
    483503
    484504    /* create the category combobox */
    485     category_model = category_filter_model_new( tmodel );
    486     c = gtk_combo_box_new_with_model( category_model );
     505    cat_model = category_filter_model_new( tmodel );
     506    c = gtk_combo_box_new_with_model( cat_model );
    487507    gtk_combo_box_set_row_separator_func( GTK_COMBO_BOX( c ),
    488508                                          is_it_a_separator, NULL, NULL );
     
    491511    r = gtk_cell_renderer_pixbuf_new( );
    492512    gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( c ), r, FALSE );
    493     gtk_cell_layout_set_cell_data_func( GTK_CELL_LAYOUT( c ), r, render_pixbuf_func, NULL, NULL );
     513    gtk_cell_layout_set_cell_data_func( GTK_CELL_LAYOUT( c ), r,
     514                                        render_pixbuf_func, NULL, NULL );
    494515    gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( c ), r,
    495516                                    "pixbuf", CAT_FILTER_COL_PIXBUF,
     
    502523                                    "text", CAT_FILTER_COL_NAME,
    503524                                    NULL );
     525    gtk_cell_layout_set_cell_data_func( GTK_CELL_LAYOUT( c ), r,
     526                                        is_capital_sensitive,
     527                                        NULL, NULL);
     528
    504529
    505530    r = number_renderer_new( );
    506531    gtk_cell_layout_pack_end( GTK_CELL_LAYOUT( c ), r, TRUE );
    507     gtk_cell_layout_set_cell_data_func( GTK_CELL_LAYOUT( c ), r, render_number_func, NULL, NULL );
     532    gtk_cell_layout_set_cell_data_func( GTK_CELL_LAYOUT( c ), r,
     533                                        render_number_func, NULL, NULL );
    508534
    509535    g_signal_connect( tmodel, "row-changed",
    510                       G_CALLBACK( torrent_model_row_changed ), category_model );
     536                      G_CALLBACK( torrent_model_row_changed ), cat_model );
    511537    g_signal_connect( tmodel, "row-inserted",
    512                       G_CALLBACK( torrent_model_row_changed ), category_model );
     538                      G_CALLBACK( torrent_model_row_changed ), cat_model );
    513539    g_signal_connect( tmodel, "row-deleted",
    514                       G_CALLBACK( torrent_model_row_deleted_cb ), category_model );
     540                      G_CALLBACK( torrent_model_row_deleted_cb ), cat_model );
    515541
    516542    return c;
     
    729755    for( i=0, n=G_N_ELEMENTS(types); i<n; ++i )
    730756        gtk_list_store_insert_with_values( store, NULL, -1,
    731                                            STATE_FILTER_COL_NAME, _( types[i].name ),
    732                                            STATE_FILTER_COL_TYPE, types[i].type,
    733                                            -1 );
     757            STATE_FILTER_COL_NAME, _( types[i].name ),
     758            STATE_FILTER_COL_TYPE, types[i].type,
     759            -1 );
    734760
    735761    g_object_set_data( G_OBJECT( store ), TORRENT_MODEL_KEY, tmodel );
     
    783809    r = gtk_cell_renderer_text_new( );
    784810    gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( c ), r, TRUE );
    785     gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( c ), r, "text", STATE_FILTER_COL_NAME, NULL );
     811    gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( c ), r,
     812                                    "text", STATE_FILTER_COL_NAME,
     813                                    NULL );
    786814
    787815    r = number_renderer_new( );
    788816    gtk_cell_layout_pack_end( GTK_CELL_LAYOUT( c ), r, TRUE );
    789     gtk_cell_layout_set_cell_data_func( GTK_CELL_LAYOUT( c ), r, render_number_func, NULL, NULL );
     817    gtk_cell_layout_set_cell_data_func( GTK_CELL_LAYOUT( c ), r,
     818                                        render_number_func, NULL, NULL );
    790819
    791820    g_signal_connect( tmodel, "row-changed",
     
    920949{
    921950    int mode;
    922     gboolean b;
    923951    const char * text;
    924952    tr_torrent * tor;
     
    931959    mode = GPOINTER_TO_INT( g_object_get_data( o, TEXT_MODE_KEY ) );
    932960
    933     b = ( tor != NULL ) && testCategory( data->category, tor )
    934                         && testState( data->state, tor )
    935                         && testText( tor, text, mode );
    936 
    937     return b;
     961    return ( tor != NULL ) && testCategory( data->category, tor )
     962                           && testState( data->state, tor )
     963                           && testText( tor, text, mode );
    938964}
    939965
  • trunk/gtk/filter.h

    • Property svn:keywords set to Date Rev Author Id
    r10380 r10388  
    88 * the Transmission project.
    99 *
    10  * $Id:$
     10 * $Id$
    1111 */
    1212
Note: See TracChangeset for help on using the changeset viewer.