diff --git a/gtk/makemeta-ui.c b/gtk/makemeta-ui.c index 9a196f6a5..00450f65e 100644 --- a/gtk/makemeta-ui.c +++ b/gtk/makemeta-ui.c @@ -24,8 +24,6 @@ #include "tracker-list.h" #include "util.h" -#define UPDATE_INTERVAL_MSEC 200 - #define UI_KEY "ui" #define ANNOUNCE_KEY "recent-announce-url" @@ -230,7 +228,7 @@ response_cb( GtkDialog* d, gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( ui-> private_check ) ) ); - tag = g_timeout_add ( UPDATE_INTERVAL_MSEC, refresh_cb, ui ); + tag = gtr_timeout_add_seconds( 1, refresh_cb, ui ); g_object_set_data_full ( G_OBJECT( d ), "tag", GUINT_TO_POINTER( tag ), remove_tag ); diff --git a/gtk/tr-core.c b/gtk/tr-core.c index 9befb91ba..56f31d0a2 100644 --- a/gtk/tr-core.c +++ b/gtk/tr-core.c @@ -1372,7 +1372,7 @@ readResponse( tr_session * session UNUSED, g_message( "response: [%*.*s]", (int)response_len, (int)response_len, response ); #endif g_byte_array_append( bytes, (const uint8_t*)response, response_len ); - g_idle_add( readResponseIdle, bytes ); + gtr_idle_add( readResponseIdle, bytes ); } static void diff --git a/gtk/tr-prefs.c b/gtk/tr-prefs.c index 04593d7ef..09970680f 100644 --- a/gtk/tr-prefs.c +++ b/gtk/tr-prefs.c @@ -146,7 +146,7 @@ spun_cb( GtkSpinButton * w, data->isDouble = isDouble; g_object_set_data_full( o, IDLE_DATA, data, spin_idle_data_free ); g_object_ref( G_OBJECT( o ) ); - g_timeout_add( 100, spun_cb_idle, w ); + gtr_timeout_add_seconds( 1, spun_cb_idle, w ); } g_timer_start( data->last_change ); } diff --git a/gtk/tr-torrent.c b/gtk/tr-torrent.c index 183d7b10c..2255efe75 100644 --- a/gtk/tr-torrent.c +++ b/gtk/tr-torrent.c @@ -167,7 +167,7 @@ completenessChangedCallback( tr_torrent * tor, void * user_data ) { if( ( completeness != TR_LEECH ) && ( tr_torrentStat( tor )->sizeWhenDone != 0 ) ) - g_idle_add( notifyInMainThread, user_data ); + gtr_idle_add( notifyInMainThread, user_data ); } static TrTorrent * diff --git a/gtk/tr-window.c b/gtk/tr-window.c index 02d3012e1..711b96066 100644 --- a/gtk/tr-window.c +++ b/gtk/tr-window.c @@ -606,7 +606,7 @@ onAltSpeedToggledIdle( gpointer vp ) static void onAltSpeedToggled( tr_session * s UNUSED, tr_bool isEnabled UNUSED, tr_bool byUser UNUSED, void * p ) { - g_idle_add( onAltSpeedToggledIdle, p ); + gtr_idle_add( onAltSpeedToggledIdle, p ); } /*** diff --git a/gtk/util.c b/gtk/util.c index d8712ab3d..607ed0ada 100644 --- a/gtk/util.c +++ b/gtk/util.c @@ -667,16 +667,6 @@ gtr_button_new_from_stock( const char * stock, **** ***/ -guint -gtr_timeout_add_seconds( guint seconds, GSourceFunc function, gpointer data ) -{ -#if GLIB_CHECK_VERSION( 2,14,0 ) - return g_timeout_add_seconds( seconds, function, data ); -#else - return g_timeout_add( seconds*1000, function, data ); -#endif -} - void gtr_widget_set_tooltip_text( GtkWidget * w, const char * tip ) { @@ -700,3 +690,59 @@ gtr_toolbar_set_orientation( GtkToolbar * toolbar, gtk_toolbar_set_orientation( toolbar, orientation ); #endif } + +/*** +**** +***/ + +#if !GTK_CHECK_VERSION( 2,12,0 ) +struct gtr_func_data +{ + GSourceFunc function; + gpointer data; +}; + +static gboolean +gtr_thread_func( gpointer data ) +{ + struct gtr_func_data * idle_data = data; + gboolean more; + + gdk_threads_enter( ); + more = idle_data->function( idle_data->data ); + gdk_threads_leave( ); + + if( !more ) + g_free( data ); + + return more; +} +#endif + +void +gtr_idle_add( GSourceFunc function, gpointer data ) +{ +#if GTK_CHECK_VERSION( 2,12,0 ) + gdk_threads_add_idle( func, data ); +#else + struct gtr_func_data * d = g_new( struct gtr_func_data, 1 ); + d->function = function; + d->data = data; + g_idle_add( gtr_thread_func, d ); +#endif +} + +guint +gtr_timeout_add_seconds( guint seconds, GSourceFunc function, gpointer data ) +{ +#if GTK_CHECK_VERSION( 2,14,0 ) + return gdk_threads_add_timeout_seconds( seconds, function, data ); +#elif GTK_CHECK_VERSION( 2,12,0 ) + return gdk_threads_add_timeout( seconds*1000, function, data ); +#else + struct gtr_func_data * d = g_new( struct gtr_func_data, 1 ); + d->function = function; + d->data = data; + return g_timeout_add( seconds*1000, gtr_thread_func, d ); +#endif +} diff --git a/gtk/util.h b/gtk/util.h index 37999543e..0ed49c2cd 100644 --- a/gtk/util.h +++ b/gtk/util.h @@ -94,6 +94,13 @@ char* gtr_get_help_url( void ); #ifdef GTK_MAJOR_VERSION +guint gtr_timeout_add_seconds( guint seconds, + GSourceFunc function, + gpointer data ); + +void gtr_idle_add( GSourceFunc func, + gpointer data ); + void gtr_toolbar_set_orientation( GtkToolbar * toolbar, GtkOrientation orientation ); @@ -102,10 +109,6 @@ void gtr_widget_set_tooltip_text( GtkWidget * w, const char * tip ); GtkWidget * gtr_button_new_from_stock( const char * stock, const char * mnemonic ); -guint gtr_timeout_add_seconds( guint seconds, - GSourceFunc function, - gpointer data ); - void addTorrentErrorDialog( GtkWidget * window_or_child, int err, const char * filename );