Changeset 12602


Ignore:
Timestamp:
Jul 30, 2011, 1:28:03 PM (10 years ago)
Author:
jordan
Message:

(trunk gtk) when N torrents change their state at the same time, use an idle timer so that the UI refreshes once instead of N times.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/main.c

    r12580 r12602  
    7878    gboolean                    is_iconified;
    7979    guint                       timer;
     80    guint                       update_model_soon_tag;
    8081    guint                       refresh_actions_tag;
    8182    gpointer                    icon;
     
    322323
    323324static void
    324 on_selection_changed( GtkTreeSelection * s UNUSED, gpointer gdata )
     325refresh_actions_soon( gpointer gdata )
    325326{
    326327    struct cbdata * data = gdata;
     
    328329    if( data->refresh_actions_tag == 0 )
    329330        data->refresh_actions_tag = gtr_idle_add( refresh_actions, data );
     331}
     332
     333static void
     334on_selection_changed( GtkTreeSelection * s UNUSED, gpointer gdata )
     335{
     336    refresh_actions_soon( gdata );
    330337}
    331338
     
    351358static void on_prefs_changed( TrCore * core, const char * key, gpointer );
    352359
    353 static gboolean update_model( gpointer gdata );
     360static gboolean update_model_loop( gpointer gdata );
     361static gboolean update_model_once( gpointer gdata );
    354362
    355363/***
     
    829837
    830838    /* start model update timer */
    831     cbdata->timer = gtr_timeout_add_seconds( MAIN_WINDOW_REFRESH_INTERVAL_SECONDS, update_model, cbdata );
    832     update_model( cbdata );
     839    cbdata->timer = gtr_timeout_add_seconds( MAIN_WINDOW_REFRESH_INTERVAL_SECONDS, update_model_loop, cbdata );
     840    update_model_once( cbdata );
    833841
    834842    /* either show the window or iconify it */
     
    913921{
    914922    struct cbdata * data = gdata;
     923
    915924    if( gtk_tree_selection_path_is_selected ( data->sel, path ) )
    916         refresh_actions( gdata );
     925        refresh_actions_soon( data );
    917926}
    918927
     
    13791388
    13801389static gboolean
    1381 update_model( gpointer gdata )
     1390update_model_once( gpointer gdata )
    13821391{
    13831392    struct cbdata *data = gdata;
     1393
     1394    /* update the torrent data in the model */
     1395    gtr_core_update( data->core );
     1396
     1397    /* refresh the main window's statusbar and toolbar buttons */
     1398    if( data->wind != NULL )
     1399        gtr_window_refresh( data->wind );
     1400
     1401    /* update the actions */
     1402        refresh_actions( data );
     1403
     1404    /* update the status tray icon */
     1405    if( data->icon != NULL )
     1406        gtr_icon_refresh( data->icon );
     1407
     1408    data->update_model_soon_tag = 0;
     1409    return FALSE;
     1410}
     1411
     1412static void
     1413update_model_soon( gpointer gdata )
     1414{
     1415    struct cbdata *data = gdata;
     1416
     1417    if( data->update_model_soon_tag == 0 )
     1418        data->update_model_soon_tag = gtr_idle_add( update_model_once, data );
     1419}
     1420
     1421static gboolean
     1422update_model_loop( gpointer gdata )
     1423{
    13841424    const gboolean done = global_sigcount;
    13851425
    13861426    if( !done )
    1387     {
    1388         /* update the torrent data in the model */
    1389         gtr_core_update( data->core );
    1390 
    1391         /* refresh the main window's statusbar and toolbar buttons */
    1392         if( data->wind != NULL )
    1393             gtr_window_refresh( data->wind );
    1394 
    1395         /* update the actions */
    1396         refresh_actions( data );
    1397 
    1398         /* update the status tray icon */
    1399         if( data->icon != NULL )
    1400             gtr_icon_refresh( data->icon );
    1401     }
     1427        update_model_once( gdata );
    14021428
    14031429    return !done;
     
    17251751
    17261752    if( changed )
    1727         update_model( data );
    1728 }
     1753        update_model_soon( data );
     1754}
Note: See TracChangeset for help on using the changeset viewer.