Changeset 6693


Ignore:
Timestamp:
Sep 3, 2008, 5:50:31 PM (14 years ago)
Author:
charles
Message:

(gtk) #1244: Crashing while scrolling up used port

File:
1 edited

Legend:

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

    r6692 r6693  
    11621162}
    11631163
    1164 static void
    1165 testing_port_cb( GtkWidget * unused UNUSED, gpointer l )
    1166 {
    1167     struct test_port_data * data;
    1168 
    1169     gtk_label_set_markup( GTK_LABEL( l ), _( "<i>Testing port...</i>" ) );
    1170 
    1171     /* wait three seconds to give the port forwarding time to kick in */
    1172     data = g_new0( struct test_port_data, 1 );
    1173     data->label = l;
    1174     data->alive = g_object_get_data( G_OBJECT( l ), "alive" );
    1175     g_timeout_add( 3000, testing_port_begin, data );
    1176 }
    1177 
    1178 static void
    1179 dialogDestroyed( gpointer alive, GObject * dialog UNUSED )
    1180 {
    1181     *(gboolean*)alive = FALSE;
     1164struct network_page_data
     1165{
     1166    gboolean * alive;
     1167    GtkWidget * label;
     1168    guint id;
     1169    TrCore * core;
     1170};
     1171
     1172static void
     1173onCorePrefsChanged( TrCore * core UNUSED, const char * key, gpointer gdata )
     1174{
     1175    if( !strcmp( key, PREF_KEY_PORT ) )
     1176    {
     1177        struct network_page_data * ndata = gdata;
     1178        struct test_port_data * data;
     1179
     1180        gtk_label_set_markup( GTK_LABEL( ndata->label ), _( "<i>Testing port...</i>" ) );
     1181
     1182        /* wait three seconds to give the port forwarding time to kick in */
     1183        data = g_new0( struct test_port_data, 1 );
     1184        data->label = ndata->label;
     1185        data->alive = ndata->alive;
     1186        g_timeout_add( 3000, testing_port_begin, data );
     1187    }
     1188}
     1189
     1190static void
     1191networkPageDestroyed( gpointer gdata, GObject * dead UNUSED )
     1192{
     1193    struct network_page_data * data = gdata;
     1194    *data->alive = FALSE;
     1195    g_signal_handler_disconnect( data->core, data->id );
     1196    g_free( data );
    11821197}
    11831198
    11841199static GtkWidget*
    1185 networkPage( GObject * core, gboolean * alive )
     1200networkPage( GObject * core )
    11861201{
    11871202    int row = 0;
     
    11921207    GtkWidget * h;
    11931208    GtkWidget * l;
    1194     struct blocklist_data * data;
    1195 
    1196     data = g_new0( struct blocklist_data, 1 );
     1209    struct network_page_data * data;
     1210
     1211    /* register to stop listening to core prefs changes when the page is destroyed */
     1212    data = g_new0( struct network_page_data, 1 );
    11971213    data->core = TR_CORE( core );
    11981214
     1215    /* we leak this gboolean* s.t. we know it will still be alive when the port
     1216       check is done, whether the dialog was destroyed or not.  kind of clumsy... */
     1217    data->alive = g_new( gboolean, 1 );
     1218    *data->alive = TRUE;
     1219
     1220    /* build the page */
    11991221    t = hig_workarea_create( );
    12001222    hig_workarea_add_section_title( t, &row, _( "Incoming Peers" ) );
     
    12031225        w2 = new_spin_button( PREF_KEY_PORT, core, 1, 65535, 1 );
    12041226        gtk_box_pack_start( GTK_BOX(h), w2, FALSE, FALSE, 0 );
    1205         l = gtk_label_new( NULL );
     1227        data->label = l = gtk_label_new( NULL );
    12061228        gtk_misc_set_alignment( GTK_MISC(l), 0.0f, 0.5f );
    12071229        gtk_box_pack_start( GTK_BOX(h), l, FALSE, FALSE, 0 );
     
    12091231
    12101232        g_object_set_data( G_OBJECT(l), "tr-port-spin", w2 );
    1211         g_object_set_data( G_OBJECT(l), "alive", alive );
    12121233        g_object_set_data( G_OBJECT(l), "handle", tr_core_handle( TR_CORE( core ) ) );
    1213         testing_port_cb( NULL, l );
    1214         g_signal_connect( w2, "value-changed", G_CALLBACK(testing_port_cb), l );
     1234        data->id = g_signal_connect( TR_CORE( core ), "prefs-changed", G_CALLBACK( onCorePrefsChanged ), data );
     1235        onCorePrefsChanged( NULL, PREF_KEY_PORT, data );
    12151236
    12161237        s = _("Use UPnP or NAT-PMP port _forwarding from my router" );
     
    12191240
    12201241    hig_workarea_finish( t, &row );
     1242    g_object_weak_ref( G_OBJECT( t ), networkPageDestroyed, data );
     1243
    12211244    return t;
    12221245}
     
    12311254    GtkWidget * d;
    12321255    GtkWidget * n;
    1233     gboolean * alive;
    1234 
    1235     alive = g_new( gboolean, 1 );
    1236     *alive = TRUE;
    12371256
    12381257    d = gtk_dialog_new_with_buttons( _( "Transmission Preferences" ), parent,
     
    12441263    gtk_dialog_set_has_separator( GTK_DIALOG( d ), FALSE );
    12451264    gtk_container_set_border_width( GTK_CONTAINER( d ), GUI_PAD );
    1246     g_object_weak_ref( G_OBJECT( d ), dialogDestroyed, alive );
    12471265
    12481266    n = gtk_notebook_new( );
     
    12621280                              gtk_label_new (_("Bandwidth")) );
    12631281    gtk_notebook_append_page( GTK_NOTEBOOK( n ),
    1264                               networkPage( core, alive ),
     1282                              networkPage( core ),
    12651283                              gtk_label_new (_("Network")) );
    12661284    gtk_notebook_append_page( GTK_NOTEBOOK( n ),
Note: See TracChangeset for help on using the changeset viewer.