]> granicus.if.org Git - transmission/commitdiff
(trunk gtk) #2251: gtk client should use GDK-safe versions of g_idle_add() and g_time...
authorCharles Kerr <charles@transmissionbt.com>
Mon, 29 Jun 2009 17:22:35 +0000 (17:22 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Mon, 29 Jun 2009 17:22:35 +0000 (17:22 +0000)
gtk/makemeta-ui.c
gtk/tr-core.c
gtk/tr-prefs.c
gtk/tr-torrent.c
gtk/tr-window.c
gtk/util.c
gtk/util.h

index 9a196f6a59d26588d42daa1fbd50064ec4a3faec..00450f65e79806066b207ea2069cd8e4d3952ccc 100644 (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 );
 
index 9befb91ba412f026de3fe19b5d586c399e8427b0..56f31d0a2860060b24328b04c2db85d9d827d454 100644 (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
index 04593d7ef63c24fbed6befca037ff128346ace8f..09970680f5d529e2ced2b3b050a02fbff997b24f 100644 (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 );
 }
index 183d7b10c8d69e97fa0cc822bfd33777d3817ed3..2255efe75e420624572173cfde45d6df98d02035 100644 (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 *
index 02d3012e1ae7ed92e69d13a5d5bbabca80147554..711b960662b87c63a1c8bb1e980154b37727630c 100644 (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 );
 }
 
 /***
index d8712ab3d93193f5a5b84555efe15fdd46d39171..607ed0ada46166ce86ff32dc56dd3da3a3b1e905 100644 (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
+}
index 37999543e76e64dc627aa6f3d11a2d2c0bf01ca0..0ed49c2cd1d1d2d158f910c2788dc42ecc4bbd40 100644 (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 );