]> granicus.if.org Git - transmission/commitdiff
(trunk gtk) make "gtr_label_set_text" public and use it everywhere instead of gtk_lab...
authorJordan Lee <jordan@transmissionbt.com>
Fri, 21 Jan 2011 16:32:27 +0000 (16:32 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Fri, 21 Jan 2011 16:32:27 +0000 (16:32 +0000)
Some of the refresh events to the main window's torrent list are caused by main window relayout caused by the toolbar's GtkLabels recalculating their size after being updated once per second. To prevent relayout in some trivial cases, I'm replacing the gtk_label_set_text() calls with gtr_label_set_text() because the latter doesn't update the label widget if the old and new text strings are the same.

There are other changes that can handle more important cases -- I'll test those out next.

gtk/details.c
gtk/makemeta-ui.c
gtk/stats.c
gtk/tr-prefs.c
gtk/tr-window.c
gtk/util.c
gtk/util.h

index 06af8fba6ef291d8184271a361dabe1c6cce0e16..f18b2db225defd952484ecaf7003613a99872c3d 100644 (file)
@@ -574,17 +574,6 @@ activityString( int activity, tr_bool finished )
     return "";
 }
 
-/* Only call gtk_label_set_text() if the new text differs from the old.
- * This way if the user has text selected, refreshing won't deselect it */
-static void
-gtr_label_set_text( GtkLabel * lb, const char * newstr )
-{
-    const char * oldstr = gtk_label_get_text( lb );
-
-    if( ( oldstr == NULL ) || strcmp( oldstr, newstr ) )
-        gtk_label_set_text( lb, newstr );
-}
-
 /* Only call gtk_text_buffer_set_text() if the new text differs from the old.
  * This way if the user has text selected, refreshing won't deselect it */
 static void
index e85a2cd9e367d873e054d57decf9aaa9ba468701..1f53dc71a878bf6cd67b11383d92748f6955b912 100644 (file)
@@ -90,7 +90,7 @@ onProgressDialogRefresh( gpointer data )
         g_assert_not_reached( );
 
     if( str != NULL ) {
-        gtk_label_set_text( GTK_LABEL( ui->progress_label ), str );
+        gtr_label_set_text( GTK_LABEL( ui->progress_label ), str );
         g_free( str );
     }
 
index a3a587f755956c0dfbb3b7d459dbd67e235f85e9..a73c035ba3bcfd9088cae6fe0a658d280d39985b 100644 (file)
@@ -40,7 +40,7 @@ static void
 setLabel( GtkWidget *  w,
           const char * str )
 {
-    gtk_label_set_text( GTK_LABEL( w ), str );
+    gtr_label_set_text( GTK_LABEL( w ), str );
 }
 
 static void
index b71a29432585cbd7961ce1edad8c091d7b422b22..f80c263189192cb7d3aab91c7fbb01b5d24cfd1c 100644 (file)
@@ -1104,7 +1104,7 @@ onCorePrefsChanged( TrCore * core UNUSED, const char *  key, gpointer gdata )
     {
         struct network_page_data * data = gdata;
         gdk_threads_enter();
-        gtk_label_set_text( GTK_LABEL( data->portLabel ), _( "Status unknown" ) );
+        gtr_label_set_text( GTK_LABEL( data->portLabel ), _( "Status unknown" ) );
         gtk_widget_set_sensitive( data->portButton, TRUE );
         gtk_widget_set_sensitive( data->portSpin, TRUE );
         gdk_threads_leave();
index d54a997fe8f0e0ed2b626009d1090d3a98fdcc77..805a6666cd2a38ed1da0d3ce8ba298c0d4d542a2 100644 (file)
@@ -536,7 +536,7 @@ onOptionsClicked( GtkButton * button UNUSED, gpointer vp )
 
     w = p->speedlimit_on_item[TR_DOWN];
     tr_formatter_speed_KBps( buf1, gtr_pref_int_get( TR_PREFS_KEY_DSPEED_KBps ), sizeof( buf1 ) );
-    gtk_label_set_text( GTK_LABEL( gtk_bin_get_child( GTK_BIN( w ) ) ), buf1 );
+    gtr_label_set_text( GTK_LABEL( gtk_bin_get_child( GTK_BIN( w ) ) ), buf1 );
 
     b = gtr_pref_flag_get( TR_PREFS_KEY_DSPEED_ENABLED );
     w = b ? p->speedlimit_on_item[TR_DOWN] : p->speedlimit_off_item[TR_DOWN];
@@ -544,7 +544,7 @@ onOptionsClicked( GtkButton * button UNUSED, gpointer vp )
 
     w = p->speedlimit_on_item[TR_UP];
     tr_formatter_speed_KBps( buf1, gtr_pref_int_get( TR_PREFS_KEY_USPEED_KBps ), sizeof( buf1 ) );
-    gtk_label_set_text( GTK_LABEL( gtk_bin_get_child( GTK_BIN( w ) ) ), buf1 );
+    gtr_label_set_text( GTK_LABEL( gtk_bin_get_child( GTK_BIN( w ) ) ), buf1 );
 
     b = gtr_pref_flag_get( TR_PREFS_KEY_USPEED_ENABLED );
     w = b ? p->speedlimit_on_item[TR_UP] : p->speedlimit_off_item[TR_UP];
@@ -552,7 +552,7 @@ onOptionsClicked( GtkButton * button UNUSED, gpointer vp )
 
     tr_strlratio( buf1, gtr_pref_double_get( TR_PREFS_KEY_RATIO ), sizeof( buf1 ) );
     g_snprintf( buf2, sizeof( buf2 ), _( "Stop at Ratio (%s)" ), buf1 );
-    gtk_label_set_text( GTK_LABEL( gtk_bin_get_child( GTK_BIN( p->ratio_on_item ) ) ), buf2 );
+    gtr_label_set_text( GTK_LABEL( gtk_bin_get_child( GTK_BIN( p->ratio_on_item ) ) ), buf2 );
 
     b = gtr_pref_flag_get( TR_PREFS_KEY_RATIO_ENABLED );
     gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( b ? p->ratio_on_item : p->ratio_off_item ), TRUE );
@@ -759,7 +759,7 @@ updateTorrentCount( PrivateData * p )
             g_snprintf( buf, sizeof( buf ),
                         gtr_ngettext( "%'d Torrent", "%'d Torrents", torrentCount ),
                         torrentCount );
-        gtk_label_set_text( GTK_LABEL( p->gutter_lb ), buf );
+        gtr_label_set_text( GTK_LABEL( p->gutter_lb ), buf );
     }
 }
 
@@ -807,7 +807,7 @@ updateStats( PrivateData * p )
         tr_strlratio( ratio, stats.ratio, sizeof( ratio ) );
         g_snprintf( buf, sizeof( buf ), _( "Ratio: %s" ), ratio );
     }
-    gtk_label_set_text( GTK_LABEL( p->stats_lb ), buf );
+    gtr_label_set_text( GTK_LABEL( p->stats_lb ), buf );
 }
 
 static void
@@ -834,10 +834,10 @@ updateSpeeds( PrivateData * p )
         while( gtk_tree_model_iter_next( model, &iter ) );
 
         tr_formatter_speed_KBps( buf, down, sizeof( buf ) );
-        gtk_label_set_text( GTK_LABEL( p->dl_lb ), buf );
+        gtr_label_set_text( GTK_LABEL( p->dl_lb ), buf );
 
         tr_formatter_speed_KBps( buf, up, sizeof( buf ) );
-        gtk_label_set_text( GTK_LABEL( p->ul_lb ), buf );
+        gtr_label_set_text( GTK_LABEL( p->ul_lb ), buf );
     }
 }
 
index 1a1259214c7cfac35700bf3e4ef281921fd306ee..c6c3749dd08fa29d19ed468a33a22680366a1011 100644 (file)
@@ -940,3 +940,15 @@ gtr_paste_clipboard_url_into_entry( GtkWidget * e )
     g_free( text[i] );
 }
 
+/***
+****
+***/
+
+void
+gtr_label_set_text( GtkLabel * lb, const char * newstr )
+{
+    const char * oldstr = gtk_label_get_text( lb );
+
+    if( ( oldstr == NULL ) || strcmp( oldstr, newstr ) )
+        gtk_label_set_text( lb, newstr );
+}
index 87db1751b568ba60f2def3e57acb126c73d524f2..377835402fe5a9dc24c51c334f5ee670024ac76f 100644 (file)
@@ -200,5 +200,9 @@ int gtr_file_trash_or_remove( const char * filename );
 
 void gtr_paste_clipboard_url_into_entry( GtkWidget * entry );
 
+/* Only call gtk_label_set_text() if the new text differs from the old.
+ * This prevents the label from having to recalculate its size
+ * and prevents selected text in the label from being deselected */
+void gtr_label_set_text( GtkLabel * lb, const char * text );
 
 #endif /* GTR_UTIL_H */