Changeset 10382


Ignore:
Timestamp:
Mar 15, 2010, 2:35:43 PM (11 years ago)
Author:
charles
Message:

(trunk gtk) small filter/favicon code cleanups

Location:
trunk/gtk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/favicon.c

    r10380 r10382  
    1111 */
    1212
    13 #include <glib/gstdio.h> /* g_remove */
     13#include <glib/gstdio.h> /* g_remove() */
    1414#include <gtk/gtk.h>
    1515
    1616#include <libtransmission/transmission.h>
    17 #include <libtransmission/web.h> /* tr_webRun */
     17#include <libtransmission/web.h> /* tr_webRun() */
    1818
    1919#include "favicon.h"
     
    3636    if( dir == NULL )
    3737    {
    38         dir = g_build_filename( g_get_user_cache_dir(), "transmission", "favicons", NULL );
     38        dir = g_build_filename( g_get_user_cache_dir(),
     39                                "transmission",
     40                                "favicons",
     41                                NULL );
    3942        gtr_mkdir_with_parents( dir, 0777 );
    4043    }
     
    6467    if( len > 0 )
    6568    {
    66         GInputStream * input_stream = g_memory_input_stream_new_from_data( data, len, NULL );
    67         pixbuf = gdk_pixbuf_new_from_stream_at_scale( input_stream, 16, 16, TRUE, NULL, NULL );
    68         g_object_unref( input_stream );
     69        GInputStream * i = g_memory_input_stream_new_from_data( data, len, NULL );
     70        pixbuf = gdk_pixbuf_new_from_stream_at_scale( i, 16, 16, TRUE, NULL, NULL );
     71        g_object_unref( i );
    6972    }
    7073
     
    124127   
    125128void
    126 gtr_get_favicon( tr_session * session,
    127                  const char * host,
    128                  GFunc pixbuf_ready_func,
    129                  gpointer pixbuf_ready_func_data )
     129gtr_get_favicon( tr_session  * session,
     130                 const char  * host,
     131                 GFunc         pixbuf_ready_func,
     132                 gpointer      pixbuf_ready_func_data )
    130133{
    131134    GdkPixbuf * pixbuf = favicon_load_from_file( host );
  • trunk/gtk/filter.c

    r10381 r10382  
    1717#include <libtransmission/utils.h>
    1818
    19 #include "favicon.h"
     19#include "favicon.h" /* gtr_get_favicon() */
    2020#include "filter.h"
    2121#include "hig.h" /* GUI_PAD */
    22 #include "tr-core.h"
     22#include "tr-core.h" /* MC_TORRENT_RAW */
    2323#include "util.h" /* gtr_idle_add() */
    2424
    25 #define DIRTY_KEY          "tr-filter-dirty"
     25#define DIRTY_KEY          "tr-filter-dirty-key"
    2626#define SESSION_KEY        "tr-session-key"
    27 #define TEXT_KEY           "tr-filter-text"
    28 #define TEXT_MODE_KEY      "tr-filter-text-mode"
     27#define TEXT_KEY           "tr-filter-text-key"
     28#define TEXT_MODE_KEY      "tr-filter-text-mode-key"
    2929#define TORRENT_MODEL_KEY  "tr-filter-torrent-model-key"
    3030
     
    7272}
    7373
     74/* pattern-matching text; ie, legaltorrents.com */
    7475static char*
    7576get_host_from_url( const char * url )
     
    9394}
    9495
     96/* human-readable name; ie, Legaltorrents */
    9597static char*
    9698get_name_from_host( const char * host )
     
    131133
    132134        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 );
     135            gtk_tree_store_set( GTK_TREE_STORE( model ), &iter,
     136                                CAT_FILTER_COL_PIXBUF, pixbuf,
     137                                -1 );
    134138
    135139        gtk_tree_path_free( path );
     
    156160    GtkTreeModel * model = GTK_TREE_MODEL( store );
    157161    GPtrArray * hosts = g_ptr_array_new( );
    158     GHashTable * hosts_hash = g_hash_table_new_full( g_str_hash, g_str_equal, g_free, g_free );
     162    GHashTable * hosts_hash = g_hash_table_new_full( g_str_hash, g_str_equal,
     163                                                     g_free, g_free );
    159164    GObject * o = G_OBJECT( store );
    160165    GtkTreeModel * tmodel = GTK_TREE_MODEL(
     
    229234    category_model_update_count( store, &iter, all );
    230235
    231     /* update the "public" count */
     236    /* update the "public" subtree */
    232237    gtk_tree_model_iter_nth_child( model, &parent, NULL, 2 );
    233238    gtk_tree_model_iter_nth_child( model, &iter, &parent, 0 );
     
    247252    /* update the "hosts" subtree */
    248253    gtk_tree_model_iter_nth_child( model, &parent, NULL, 4 );
    249     i = 0;
    250     n = hosts->len;
    251     store_pos = 0;
    252     for( ;; )
     254    for( i=store_pos=0, n=hosts->len ; ; )
    253255    {
    254256        const gboolean new_hosts_done = i >= n;
     
    391393
    392394static gboolean
    393 is_it_a_separator( GtkTreeModel * model, GtkTreeIter * iter, gpointer data UNUSED )
     395is_it_a_separator( GtkTreeModel * m, GtkTreeIter * iter, gpointer data UNUSED )
    394396{
    395397    int type;
    396     gtk_tree_model_get( model, iter, CAT_FILTER_COL_TYPE, &type, -1 );
     398    gtk_tree_model_get( m, iter, CAT_FILTER_COL_TYPE, &type, -1 );
    397399    return type == CAT_FILTER_TYPE_SEPARATOR;
    398400}
     
    402404{
    403405    GObject * o = G_OBJECT( category_model );
    404     gboolean pending = GPOINTER_TO_INT( g_object_get_data( o, DIRTY_KEY ) );
     406    const gboolean pending = g_object_get_data( o, DIRTY_KEY ) != NULL;
    405407    if( !pending )
    406408    {
     
    440442}
    441443static void
    442 render_hit_count_func( GtkCellLayout    * cell_layout UNUSED,
    443                        GtkCellRenderer  * cell_renderer,
    444                        GtkTreeModel     * tree_model,
    445                        GtkTreeIter      * iter,
    446                        gpointer           data UNUSED )
     444render_number_func( GtkCellLayout    * cell_layout UNUSED,
     445                    GtkCellRenderer  * cell_renderer,
     446                    GtkTreeModel     * tree_model,
     447                    GtkTreeIter      * iter,
     448                    gpointer           data UNUSED )
    447449{
    448450    int count;
     
    503505    r = number_renderer_new( );
    504506    gtk_cell_layout_pack_end( GTK_CELL_LAYOUT( c ), r, TRUE );
    505     gtk_cell_layout_set_cell_data_func( GTK_CELL_LAYOUT( c ), r, render_hit_count_func, NULL, NULL );
     507    gtk_cell_layout_set_cell_data_func( GTK_CELL_LAYOUT( c ), r, render_number_func, NULL, NULL );
    506508
    507509    g_signal_connect( tmodel, "row-changed",
     
    514516    return c;
    515517}
    516 
    517 /***
    518 ****
    519 ***/
    520518
    521519static gboolean
     
    627625        case STATE_FILTER_ACTIVE:
    628626            return ( st->peersSendingToUs > 0 )
    629                 || ( st->peersGettingFromUs > 0 );
     627                || ( st->peersGettingFromUs > 0 )
    630628                || ( st->activity == TR_STATUS_CHECK );
    631629
     
    668666{
    669667    int count;
    670     gtk_tree_model_get( GTK_TREE_MODEL( store ), iter, STATE_FILTER_COL_COUNT, &count, -1 );
     668    GtkTreeModel * model = GTK_TREE_MODEL( store );
     669    gtk_tree_model_get( model, iter, STATE_FILTER_COL_COUNT, &count, -1 );
    671670    if( n != count )
    672671        gtk_list_store_set( store, iter, STATE_FILTER_COL_COUNT, n, -1 );
     
    719718        { STATE_FILTER_PAUSED, N_( "Paused" ) },
    720719        { STATE_FILTER_QUEUED, N_( "Queued" ) },
    721         { STATE_FILTER_CHECKING, N_( "Verifying" ) },
     720        { STATE_FILTER_VERIFYING, N_( "Verifying" ) },
    722721        { STATE_FILTER_ERROR, N_( "Error" ) }
    723722    };
    724723    GtkListStore * store;
    725724
    726     store = gtk_list_store_new( STATE_FILTER_N_COLS, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT );
     725    store = gtk_list_store_new( STATE_FILTER_N_COLS,
     726                                G_TYPE_STRING,
     727                                G_TYPE_INT,
     728                                G_TYPE_INT );
    727729    for( i=0, n=G_N_ELEMENTS(types); i<n; ++i )
    728730        gtk_list_store_insert_with_values( store, NULL, -1,
     
    740742{
    741743    GObject * o = G_OBJECT( state_model );
    742     gboolean pending = GPOINTER_TO_INT( g_object_get_data( o, DIRTY_KEY ) );
     744    const gboolean pending = g_object_get_data( o, DIRTY_KEY ) != NULL;
    743745    if( !pending )
    744746    {
     
    785787    r = number_renderer_new( );
    786788    gtk_cell_layout_pack_end( GTK_CELL_LAYOUT( c ), r, TRUE );
    787     gtk_cell_layout_set_cell_data_func( GTK_CELL_LAYOUT( c ), r, render_hit_count_func, NULL, NULL );
     789    gtk_cell_layout_set_cell_data_func( GTK_CELL_LAYOUT( c ), r, render_number_func, NULL, NULL );
    788790
    789791    g_signal_connect( tmodel, "row-changed",
     
    971973    g_object_set_data( G_OBJECT( gtk_combo_box_get_model( GTK_COMBO_BOX( data->category ) ) ), SESSION_KEY, session );
    972974
    973     gtk_tree_model_filter_set_visible_func( GTK_TREE_MODEL_FILTER( data->filter_model ),
    974                                             is_row_visible, data, g_free );
     975    gtk_tree_model_filter_set_visible_func(
     976        GTK_TREE_MODEL_FILTER( data->filter_model ),
     977        is_row_visible, data, g_free );
    975978
    976979    g_signal_connect( data->category, "changed", G_CALLBACK( selection_changed_cb ), data );
Note: See TracChangeset for help on using the changeset viewer.