Changeset 6860


Ignore:
Timestamp:
Oct 7, 2008, 12:34:21 AM (13 years ago)
Author:
charles
Message:

(gtk) the last two commits were needlessly complex... here's a simpler fix. (I hope)

File:
1 edited

Legend:

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

    r6859 r6860  
    198198struct spin_idle_data
    199199{
    200     gpointer          core;
    201     char            * key;
    202     int               value;
    203     GTimer          * last_change;
    204     GtkSpinButton   * spin;
     200    gpointer    core;
     201    GTimer *    last_change;
    205202};
    206203
     
    211208
    212209    g_timer_destroy( data->last_change );
    213     g_free( data->key );
    214210    g_free( data );
    215211}
    216212
    217 static void
    218 onSpinDestroyed( gpointer     gdata,
    219                  GObject    * details UNUSED )
    220 {
    221     struct spin_idle_data * data = gdata;
    222     data->spin = NULL;
    223 }
    224 
    225213static gboolean
    226 spun_cb_idle( gpointer gdata )
    227 {
    228     gboolean keep_waiting = TRUE;
    229     struct spin_idle_data * data = gdata;
     214spun_cb_idle( gpointer spin )
     215{
     216    gboolean                keep_waiting = TRUE;
     217    GObject *               o = G_OBJECT( spin );
     218    struct spin_idle_data * data = g_object_get_data( o, IDLE_DATA );
    230219
    231220    /* has the user stopped making changes? */
     
    233222    {
    234223        /* update the core */
    235         tr_core_set_pref_int( TR_CORE( data->core ), data->key, data->value );
     224        const char * key = g_object_get_data( o, PREF_KEY );
     225        const int    value = gtk_spin_button_get_value_as_int(
     226             GTK_SPIN_BUTTON( spin ) );
     227        tr_core_set_pref_int( TR_CORE( data->core ), key, value );
    236228
    237229        /* cleanup */
    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 );
     230        g_object_set_data( o, IDLE_DATA, NULL );
    244231        keep_waiting = FALSE;
     232        g_object_unref( G_OBJECT( o ) );
    245233    }
    246234
     
    254242    /* user may be spinning through many values, so let's hold off
    255243       for a moment to keep from flooding the core with changes */
    256     GObject * o = G_OBJECT( w );
     244    GObject *               o = G_OBJECT( w );
    257245    struct spin_idle_data * data = g_object_get_data( o, IDLE_DATA );
    258246
     
    262250        data->core = core;
    263251        data->last_change = g_timer_new( );
    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 );
     252        g_object_set_data_full( o, IDLE_DATA, data, spin_idle_data_free );
     253        g_object_ref( G_OBJECT( o ) );
     254        g_timeout_add( 100, spun_cb_idle, w );
    269255    }
    270256    g_timer_start( data->last_change );
Note: See TracChangeset for help on using the changeset viewer.