Changeset 6859


Ignore:
Timestamp:
Oct 6, 2008, 8:54:18 PM (13 years ago)
Author:
charles
Message:

(gtk) better fix for the bug described in r6858

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/tr-prefs.c

    r6858 r6859  
    198198struct spin_idle_data
    199199{
    200     guint       tag;
    201     gpointer    core;
    202     GTimer *    last_change;
     200    gpointer          core;
     201    char            * key;
     202    int               value;
     203    GTimer          * last_change;
     204    GtkSpinButton   * spin;
    203205};
    204206
     
    209211
    210212    g_timer_destroy( data->last_change );
     213    g_free( data->key );
    211214    g_free( data );
    212215}
    213216
    214217static void
    215 onSpinDestroyed( gpointer     tag,
     218onSpinDestroyed( gpointer     gdata,
    216219                 GObject    * details UNUSED )
    217220{
    218     g_source_remove( GPOINTER_TO_UINT( tag ) );
     221    struct spin_idle_data * data = gdata;
     222    data->spin = NULL;
    219223}
    220224
    221225static gboolean
    222 spun_cb_idle( gpointer spin )
     226spun_cb_idle( gpointer gdata )
    223227{
    224228    gboolean keep_waiting = TRUE;
    225     GObject * o = G_OBJECT( spin );
    226     struct spin_idle_data * data = g_object_get_data( o, IDLE_DATA );
     229    struct spin_idle_data * data = gdata;
    227230
    228231    /* has the user stopped making changes? */
     
    230233    {
    231234        /* update the core */
    232         const char * key = g_object_get_data( o, PREF_KEY );
    233         const int    value = gtk_spin_button_get_value_as_int(
    234              GTK_SPIN_BUTTON( spin ) );
    235         tr_core_set_pref_int( TR_CORE( data->core ), key, value );
     235        tr_core_set_pref_int( TR_CORE( data->core ), data->key, data->value );
    236236
    237237        /* cleanup */
    238         g_object_weak_unref( o, onSpinDestroyed, GUINT_TO_POINTER( data->tag ) );
    239         g_object_set_data( o, IDLE_DATA, NULL );
     238        if( data->spin ) {
     239            GObject * o = G_OBJECT( data->spin );
     240            g_object_weak_unref( o, onSpinDestroyed, data );
     241            g_object_set_data( o, IDLE_DATA, NULL );
     242        }
     243        spin_idle_data_free( data );
    240244        keep_waiting = FALSE;
    241245    }
     
    250254    /* user may be spinning through many values, so let's hold off
    251255       for a moment to keep from flooding the core with changes */
    252     GObject *               o = G_OBJECT( w );
     256    GObject * o = G_OBJECT( w );
    253257    struct spin_idle_data * data = g_object_get_data( o, IDLE_DATA );
    254258
     
    258262        data->core = core;
    259263        data->last_change = g_timer_new( );
    260         data->tag = g_timeout_add( 100, spun_cb_idle, w );
    261         g_object_set_data_full( o, IDLE_DATA, data, spin_idle_data_free );
    262         g_object_weak_ref( o, onSpinDestroyed, GUINT_TO_POINTER( data->tag ) );
     264        data->key = g_strdup( g_object_get_data( o, PREF_KEY ) );
     265        data->value = gtk_spin_button_get_value_as_int( w );
     266        g_timeout_add( 100, spun_cb_idle, data );
     267        g_object_set_data( o, IDLE_DATA, data );
     268        g_object_weak_ref( o, onSpinDestroyed, data );
    263269    }
    264270    g_timer_start( data->last_change );
Note: See TracChangeset for help on using the changeset viewer.