Changeset 10380


Ignore:
Timestamp:
Mar 15, 2010, 2:53:31 AM (11 years ago)
Author:
charles
Message:

(trunk gtk) add favicon support to the new filterbar

Location:
trunk/gtk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/Makefile.am

    r10374 r10380  
    4343    details.h \
    4444    dialogs.h \
     45    favicon.h \
    4546    filter.h \
    4647    hig.h \
     
    8081    details.c \
    8182    dialogs.c \
     83    favicon.c \
    8284    file-list.c \
    8385    filter.c \
  • trunk/gtk/filter.c

    r10377 r10380  
    1717#include <libtransmission/utils.h>
    1818
     19#include "favicon.h"
    1920#include "filter.h"
    2021#include "hig.h" /* GUI_PAD */
     
    2324
    2425#define DIRTY_KEY          "tr-filter-dirty"
     26#define SESSION_KEY        "tr-session-key"
    2527#define TEXT_KEY           "tr-filter-text"
    2628#define TEXT_MODE_KEY      "tr-filter-text-mode"
     
    6062    CAT_FILTER_COL_TYPE,
    6163    CAT_FILTER_COL_HOST, /* pattern-matching text; ie, legaltorrents.com */
     64    CAT_FILTER_COL_PIXBUF,
    6265    CAT_FILTER_N_COLS
    6366};
     
    114117    if( n != count )
    115118        gtk_tree_store_set( store, iter, CAT_FILTER_COL_COUNT, n, -1 );
     119}
     120
     121static void
     122favicon_ready_cb( gpointer pixbuf, gpointer vreference )
     123{
     124    GtkTreeIter iter;
     125    GtkTreeRowReference * reference = vreference;
     126
     127    if( pixbuf != NULL )
     128    {
     129        GtkTreePath * path = gtk_tree_row_reference_get_path( reference );
     130        GtkTreeModel * model = gtk_tree_row_reference_get_model( reference );
     131
     132        if( gtk_tree_model_get_iter( model, &iter, path ) )
     133            gtk_tree_store_set( GTK_TREE_STORE( model ), &iter, CAT_FILTER_COL_PIXBUF, pixbuf, -1 );
     134
     135        gtk_tree_path_free( path );
     136
     137        g_object_unref( pixbuf );
     138    }
     139
     140    gtk_tree_row_reference_free( reference );
    116141}
    117142
     
    264289            gtk_tree_store_remove( store, &iter );
    265290        } else if( insert_row ) {
     291            GtkTreeIter child;
     292            GtkTreePath * path;
     293            GtkTreeRowReference * reference;
     294            tr_session * session = g_object_get_data( G_OBJECT( store ), SESSION_KEY );
    266295            const char * host = hosts->pdata[i];
    267296            char * name = get_name_from_host( host );
    268297            const int count = *(int*)g_hash_table_lookup( hosts_hash, host );
    269             gtk_tree_store_insert_with_values( store, NULL, &parent, store_pos,
     298            gtk_tree_store_insert_with_values( store, &child, &parent, store_pos,
    270299                CAT_FILTER_COL_HOST, host,
    271300                CAT_FILTER_COL_NAME, name,
     
    273302                CAT_FILTER_COL_TYPE, CAT_FILTER_TYPE_HOST,
    274303                -1 );
     304            path = gtk_tree_model_get_path( model, &child );
     305            reference = gtk_tree_row_reference_new( model, path );
     306            gtr_get_favicon( session, host, favicon_ready_cb, reference );
     307            gtk_tree_path_free( path );
    275308            g_free( name );
    276309            ++store_pos;
     
    303336                                G_TYPE_INT,
    304337                                G_TYPE_INT,
    305                                 G_TYPE_STRING );
     338                                G_TYPE_STRING,
     339                                GDK_TYPE_PIXBUF );
    306340
    307341    gtk_tree_store_insert_with_values( store, NULL, NULL, -1,
     
    395429
    396430static void
     431render_pixbuf_func( GtkCellLayout    * cell_layout UNUSED,
     432                    GtkCellRenderer  * cell_renderer,
     433                    GtkTreeModel     * tree_model,
     434                    GtkTreeIter      * iter,
     435                    gpointer           data UNUSED )
     436{
     437    int type;
     438    gtk_tree_model_get( tree_model, iter, CAT_FILTER_COL_TYPE, &type, -1 );
     439    g_object_set( cell_renderer, "width", type==CAT_FILTER_TYPE_HOST ? 16 : 0, NULL );
     440}
     441static void
    397442render_hit_count_func( GtkCellLayout    * cell_layout UNUSED,
    398443                       GtkCellRenderer  * cell_renderer,
     
    441486                                          is_it_a_separator, NULL, NULL );
    442487    gtk_combo_box_set_active( GTK_COMBO_BOX( c ), 0 );
     488
     489    r = gtk_cell_renderer_pixbuf_new( );
     490    gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( c ), r, FALSE );
     491    gtk_cell_layout_set_cell_data_func( GTK_CELL_LAYOUT( c ), r, render_pixbuf_func, NULL, NULL );
     492    gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( c ), r,
     493                                    "pixbuf", CAT_FILTER_COL_PIXBUF,
     494                                    NULL );
     495   
    443496
    444497    r = gtk_cell_renderer_text_new( );
     
    889942
    890943GtkWidget *
    891 gtr_filter_bar_new( GtkTreeModel * tmodel, GtkTreeModel ** filter_model )
     944gtr_filter_bar_new( tr_session * session, GtkTreeModel * tmodel, GtkTreeModel ** filter_model )
    892945{
    893946    int i;
     
    914967
    915968    g_object_set( G_OBJECT( data->category ), "width-request", 150, NULL );
     969    g_object_set_data( G_OBJECT( gtk_combo_box_get_model( GTK_COMBO_BOX( data->category ) ) ), SESSION_KEY, session );
    916970
    917971    gtk_tree_model_filter_set_visible_func( GTK_TREE_MODEL_FILTER( data->filter_model ),
  • trunk/gtk/filter.h

    r10374 r10380  
    1515
    1616#include <gtk/gtk.h>
     17#include <libtransmission/transmission.h>
    1718
    18 GtkWidget * gtr_filter_bar_new( GtkTreeModel * torrent_model, GtkTreeModel ** filter_model );
     19GtkWidget * gtr_filter_bar_new( tr_session     * session,
     20                                GtkTreeModel   * torrent_model,
     21                                GtkTreeModel  ** filter_model );
    1922
    2023#endif
  • trunk/gtk/tr-window.c

    r10374 r10380  
    5959#endif
    6060
    61 typedef enum
    62 {
    63     FILTER_TEXT_MODE_NAME,
    64     FILTER_TEXT_MODE_FILES,
    65     FILTER_TEXT_MODE_TRACKER,
    66     FILTER_TEXT_MODE_QTY
    67 }
    68 filter_text_mode_t;
    69 
    70 typedef enum
    71 {
    72     FILTER_MODE_ALL,
    73     FILTER_MODE_ACTIVE,
    74     FILTER_MODE_DOWNLOADING,
    75     FILTER_MODE_SEEDING,
    76     FILTER_MODE_PAUSED,
    77     FILTER_MODE_QTY
    78 }
    79 filter_mode_t;
    80 
    8161typedef struct
    8262{
     
    10484    TrCore *              core;
    10585    gulong                pref_handler_id;
    106     filter_mode_t         filter_mode;
    107     filter_text_mode_t    filter_text_mode;
    108     char *                filter_text;
    109     GtkToggleButton     * filter_toggles[FILTER_MODE_QTY];
    11086}
    11187PrivateData;
     
    242218    PrivateData * p = vprivate;
    243219    g_signal_handler_disconnect( p->core, p->pref_handler_id );
    244     g_free( p->filter_text );
    245220    g_free( p );
    246221}
     
    608583
    609584    p = g_new0( PrivateData, 1 );
    610     p->filter_text_mode = FILTER_TEXT_MODE_NAME;
    611     p->filter_text = NULL;
    612585
    613586    /* make the window */
     
    645618
    646619    /* filter */
    647     h = filter = p->filter = gtr_filter_bar_new( tr_core_model( core ), &p->filter_model );
     620    h = filter = p->filter = gtr_filter_bar_new( tr_core_session( core ),
     621                                                 tr_core_model( core ),
     622                                                 &p->filter_model );
    648623    gtk_container_set_border_width( GTK_CONTAINER( h ), GUI_PAD_SMALL );
    649624
Note: See TracChangeset for help on using the changeset viewer.