Changeset 6718
- Timestamp:
- Sep 5, 2008, 9:01:00 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gtk/file-list.c
r6612 r6718 365 365 366 366 static void 367 setDownload( FileData * data, int do_download ) 368 { 367 onHighClicked( GtkButton * button UNUSED, gpointer gdata ) 368 { 369 setPriority( gdata, TR_PRI_HIGH ); 370 } 371 static void 372 onNormalClicked( GtkButton * button UNUSED, gpointer gdata ) 373 { 374 setPriority( gdata, TR_PRI_NORMAL ); 375 } 376 static void 377 onLowClicked( GtkButton * button UNUSED, gpointer gdata ) 378 { 379 setPriority( gdata, TR_PRI_LOW ); 380 } 381 382 static void 383 onDownloadToggled( GtkCellRendererToggle * cell UNUSED, char * path_str, gpointer gdata ) 384 { 385 FileData * data = gdata; 369 386 GtkTreeView * view = GTK_TREE_VIEW( data->view ); 370 GArray * a = getActiveFiles( view ); 371 tr_torrentSetFileDLs ( tr_torrent_handle( data->gtor ), 372 (tr_file_index_t*)a->data, 373 (tr_file_index_t)a->len, 374 do_download ); 375 refresh( data ); 387 GtkTreeSelection * sel = gtk_tree_view_get_selection( view ); 388 GtkTreePath * path = gtk_tree_path_new_from_string( path_str ); 389 GArray * a; 390 391 if( gtk_tree_selection_path_is_selected( sel, path ) ) 392 { 393 /* clicked in a selected row... use the current selection */ 394 a = getActiveFiles( view ); 395 } 396 else 397 { 398 /* clicked OUTSIDE of the selected row... just use the clicked row */ 399 unsigned int i; 400 gboolean is_file; 401 GtkTreeModel * model = gtk_tree_view_get_model( view ); 402 GtkTreeIter iter; 403 gtk_tree_model_get_iter( model, &iter, path ); 404 a = g_array_new( FALSE, FALSE, sizeof( tr_file_index_t ) ); 405 gtk_tree_model_get( model, &iter, FC_IS_FILE, &is_file, FC_INDEX, &i, -1 ); 406 if( is_file ) { 407 g_message( "appending %u", i ); 408 g_array_append_val( a, i ); 409 } 410 } 411 412 if( a->len ) 413 { 414 /* toggle the selected files based on the first one's current value */ 415 const tr_file_index_t i = g_array_index( a, tr_file_index_t, 0 ); 416 const tr_info * inf = tr_torrentInfo( tr_torrent_handle( data->gtor ) ); 417 const int do_download = inf->files[i].dnd; 418 tr_torrentSetFileDLs ( tr_torrent_handle( data->gtor ), 419 (tr_file_index_t*)a->data, 420 (tr_file_index_t)a->len, 421 do_download ); 422 refresh( data ); 423 } 424 425 /* cleanup */ 376 426 g_array_free( a, TRUE ); 377 } 378 379 static void 380 onHighClicked( GtkButton * button UNUSED, gpointer gdata ) 381 { 382 setPriority( gdata, TR_PRI_HIGH ); 383 } 384 static void 385 onNormalClicked( GtkButton * button UNUSED, gpointer gdata ) 386 { 387 setPriority( gdata, TR_PRI_NORMAL ); 388 } 389 static void 390 onLowClicked( GtkButton * button UNUSED, gpointer gdata ) 391 { 392 setPriority( gdata, TR_PRI_LOW ); 393 } 394 static void 395 onDownloadClicked( GtkButton * button UNUSED, gpointer gdata ) 396 { 397 setDownload( gdata, TRUE ); 398 } 399 static void 400 onIgnoreClicked( GtkButton * button UNUSED, gpointer gdata ) 401 { 402 setDownload( gdata, FALSE ); 427 gtk_tree_path_free( path ); 403 428 } 404 429 … … 521 546 int sub_state; 522 547 gboolean enabled; 548 gboolean active = FALSE; 549 gboolean inconsistent = FALSE; 523 550 gboolean is_file = FALSE; 524 const char * text;525 551 526 552 gtk_tree_model_get( model, iter, FC_IS_FILE, &is_file, … … 529 555 -1 ); 530 556 if( is_file && enabled ) 531 text = _( "Yes" );557 active = TRUE; 532 558 else if( is_file ) 533 text = _( "No" );559 active = FALSE; 534 560 else switch( sub_state & SUB_STATE_DOWNLOAD_MASK ) { 535 case SUB_STATE_DOWNLOAD: text = _( "Yes" ); break; 536 case SUB_STATE_IGNORE: text = _( "No" ); break; 537 default: text = _( "Mixed" ); break; 538 } 539 540 g_object_set( renderer, "text", text, 541 "xalign", (gfloat)0.5, 542 "yalign", (gfloat)0.5, 561 case SUB_STATE_DOWNLOAD: active = TRUE; break; 562 case SUB_STATE_IGNORE: active = FALSE; break; 563 default: inconsistent = TRUE; break; 564 } 565 566 g_object_set( renderer, "inconsistent", inconsistent, 567 "active", active, 543 568 NULL ); 544 569 } … … 588 613 } 589 614 615 static gboolean 616 onViewButtonPressed( GtkWidget * w, 617 GdkEventButton * event, 618 gpointer unused UNUSED ) 619 { 620 gboolean handled = FALSE; 621 622 if( ( event->type == GDK_BUTTON_PRESS ) && ( event->button == 1 ) ) 623 { 624 GtkTreePath * path; 625 GtkTreeViewColumn * column; 626 int cell_x; 627 int cell_y; 628 if( gtk_tree_view_get_path_at_pos( GTK_TREE_VIEW( w ), event->x, event->y, 629 &path, &column, &cell_x, &cell_y ) ) 630 { 631 const char * column_title = gtk_tree_view_column_get_title( column ); 632 if( !strcmp( column_title, _( "Priority" ) ) ) 633 { 634 handled = TRUE; 635 g_message( "row is (%s)", gtk_tree_path_to_string( path ) ); 636 } 637 gtk_tree_path_free( path ); 638 } 639 } 640 641 return handled; 642 } 643 590 644 GtkWidget * 591 645 file_list_new( TrTorrent * gtor ) … … 605 659 gtk_tree_view_set_rules_hint( GTK_TREE_VIEW( view ), TRUE ); 606 660 gtk_container_set_border_width( GTK_CONTAINER( view ), GUI_PAD_BIG ); 661 g_signal_connect( view, "button-press-event", G_CALLBACK(onViewButtonPressed), NULL ); 607 662 608 663 /* set up view */ … … 637 692 gtk_tree_view_column_set_cell_data_func( col, rend, renderProgress, NULL, NULL); 638 693 gtk_tree_view_append_column ( GTK_TREE_VIEW( view ), col); 694 data = g_new0( FileData, 1 ); 639 695 640 696 /* add "enabled" column */ 641 rend = gtk_cell_renderer_text_new( ); 697 rend = gtk_cell_renderer_toggle_new( ); 698 g_signal_connect( rend, "toggled", G_CALLBACK( onDownloadToggled ), data ); 642 699 /* Translators: this is a column header in Files tab, Details dialog; 643 700 Don't include the prefix "filedetails|" in the translation. … … 661 718 gtk_container_add( GTK_CONTAINER( scroll ), view ); 662 719 gtk_widget_set_size_request (scroll, -1, 200 ); 663 664 data = g_new0( FileData, 1 );665 720 666 721 vbox = gtk_vbox_new( FALSE, GUI_PAD ); … … 674 729 g_signal_connect( w, "clicked", G_CALLBACK(onLowClicked), data ); 675 730 gtk_box_pack_start( GTK_BOX( vbox ), w, FALSE, FALSE, 0 ); 676 w = gtk_button_new_with_mnemonic( _( "_Ignore" ) );677 g_signal_connect( w, "clicked", G_CALLBACK(onIgnoreClicked), data );678 gtk_box_pack_end( GTK_BOX( vbox ), w, FALSE, FALSE, 0 );679 w = gtk_button_new_with_mnemonic( _( "_Download" ) );680 g_signal_connect( w, "clicked", G_CALLBACK(onDownloadClicked), data );681 gtk_box_pack_end( GTK_BOX( vbox ), w, FALSE, FALSE, 0 );682 731 hbox = gtk_hbox_new( FALSE, GUI_PAD ); 683 732 gtk_box_pack_start_defaults( GTK_BOX( hbox ), scroll );
Note: See TracChangeset
for help on using the changeset viewer.