Changeset 11675
- Timestamp:
- Jan 15, 2011, 7:57:01 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gtk/msgwin.c
r11599 r11675 51 51 static struct tr_msg_list * myHead = NULL; 52 52 53 /*** 54 **** 55 ***/ 53 /**** 54 ***** 55 ****/ 56 57 /* is the user looking at the latest messages? */ 58 static gboolean 59 is_pinned_to_new( struct MsgData * data ) 60 { 61 gboolean pinned_to_new; 62 63 if( data->view == NULL ) 64 { 65 pinned_to_new = TRUE; 66 } 67 else 68 { 69 GtkTreePath * last_visible; 70 if( gtk_tree_view_get_visible_range( data->view, NULL, &last_visible ) ) 71 { 72 GtkTreeIter iter; 73 const int row_count = gtk_tree_model_iter_n_children( data->sort, NULL ); 74 if( gtk_tree_model_iter_nth_child( data->sort, &iter, NULL, row_count-1 ) ) 75 { 76 GtkTreePath * last_row = gtk_tree_model_get_path( data->sort, &iter ); 77 pinned_to_new = !gtk_tree_path_compare( last_visible, last_row ); 78 gtk_tree_path_free( last_row ); 79 } 80 gtk_tree_path_free( last_visible ); 81 } 82 } 83 84 return pinned_to_new; 85 } 86 87 static void 88 scroll_to_bottom( struct MsgData * data ) 89 { 90 if( data->sort != NULL ) 91 { 92 GtkTreeIter iter; 93 const int row_count = gtk_tree_model_iter_n_children( data->sort, NULL ); 94 if( gtk_tree_model_iter_nth_child( data->sort, &iter, NULL, row_count-1 ) ) 95 { 96 GtkTreePath * last_row = gtk_tree_model_get_path( data->sort, &iter ); 97 gtk_tree_view_scroll_to_cell( data->view, last_row, NULL, TRUE, 1, 0 ); 98 gtk_tree_path_free( last_row ); 99 } 100 } 101 } 102 103 /**** 104 ***** 105 ****/ 56 106 57 107 static void … … 60 110 struct MsgData * data = gdata; 61 111 const int level = gtr_combo_box_get_active_enum( combo_box ); 112 const gboolean pinned_to_new = is_pinned_to_new( data ); 62 113 63 114 tr_setMessageLevel( level ); … … 65 116 data->maxLevel = level; 66 117 gtk_tree_model_filter_refilter( GTK_TREE_MODEL_FILTER( data->filter ) ); 118 119 if( pinned_to_new ) 120 scroll_to_bottom( data ); 67 121 } 68 122 … … 287 341 288 342 static gboolean 289 isRowVisible( GtkTreeModel * model, 290 GtkTreeIter * iter, 291 gpointer gdata ) 343 isRowVisible( GtkTreeModel * model, GtkTreeIter * iter, gpointer gdata ) 292 344 { 293 345 const struct MsgData * data = gdata; … … 299 351 300 352 static void 301 onWindowDestroyed( gpointer gdata, 302 GObject * deadWindow UNUSED ) 353 onWindowDestroyed( gpointer gdata, GObject * deadWindow UNUSED ) 303 354 { 304 355 struct MsgData * data = gdata; … … 309 360 310 361 static tr_msg_list * 311 addMessages( GtkListStore * store, 312 struct tr_msg_list * head ) 313 { 314 const char * default_name = g_get_application_name( ); 315 static unsigned int sequence = 1; 316 tr_msg_list * i; 317 318 for( i = head; i; i = i->next ) 319 { 320 GtkTreeIter unused; 321 322 gtk_list_store_insert_with_values( store, &unused, 0, 362 addMessages( GtkListStore * store, struct tr_msg_list * head ) 363 { 364 tr_msg_list * i; 365 static unsigned int sequence = 0; 366 const char * default_name = g_get_application_name( ); 367 368 for( i=head; i && i->next; i=i->next ) 369 { 370 const char * name = i->name ? i->name : default_name; 371 372 gtk_list_store_insert_with_values( store, NULL, 0, 323 373 COL_TR_MSG, i, 324 COL_NAME, 325 ( i->name ? i->name : 326 default_name ), 374 COL_NAME, name, 327 375 COL_MESSAGE, i->message, 328 COL_SEQUENCE, sequence++,376 COL_SEQUENCE, ++sequence, 329 377 -1 ); 330 331 if( !i->next )332 break;333 378 } 334 379 … … 340 385 { 341 386 struct MsgData * data = gdata; 387 const gboolean pinned_to_new = is_pinned_to_new( data ); 342 388 343 389 if( !data->isPaused ) … … 355 401 myTail = tail; 356 402 } 357 } 403 404 if( pinned_to_new ) 405 scroll_to_bottom( data ); 406 } 407 358 408 return TRUE; 359 409 } … … 484 534 g_object_weak_ref( G_OBJECT( win ), onWindowDestroyed, data ); 485 535 536 scroll_to_bottom( data ); 486 537 gtk_widget_show_all( win ); 487 538 return win;
Note: See TracChangeset
for help on using the changeset viewer.