1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-24 08:43:27 +00:00

(trunk gtk) #2251: gtk client should use GDK-safe versions of g_idle_add() and g_timeout_add*()

This commit is contained in:
Charles Kerr 2009-06-29 17:22:35 +00:00
parent 6b7a400cee
commit bd5c9cf3a8
7 changed files with 68 additions and 21 deletions

View file

@ -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 );

View file

@ -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

View file

@ -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 );
}

View file

@ -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 *

View file

@ -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 );
}
/***

View file

@ -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
}

View file

@ -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 );