mirror of
https://github.com/transmission/transmission
synced 2024-12-25 09:13:06 +00:00
(gtk) #1192: 1.3x's method of setting file priorities & download flags is unpopular
This commit is contained in:
parent
b29143614c
commit
abd98feaae
1 changed files with 97 additions and 95 deletions
192
gtk/file-list.c
192
gtk/file-list.c
|
@ -309,10 +309,10 @@ struct ActiveData
|
||||||
};
|
};
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
getActiveFilesForeach( GtkTreeModel * model,
|
getSelectedFilesForeach( GtkTreeModel * model,
|
||||||
GtkTreePath * path UNUSED,
|
GtkTreePath * path UNUSED,
|
||||||
GtkTreeIter * iter,
|
GtkTreeIter * iter,
|
||||||
gpointer gdata )
|
gpointer gdata )
|
||||||
{
|
{
|
||||||
struct ActiveData * data = gdata;
|
struct ActiveData * data = gdata;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
@ -339,59 +339,29 @@ getActiveFilesForeach( GtkTreeModel * model,
|
||||||
return FALSE; /* keep walking */
|
return FALSE; /* keep walking */
|
||||||
}
|
}
|
||||||
|
|
||||||
static GArray*
|
static void
|
||||||
getActiveFiles( GtkTreeView * view )
|
getSelectedFilesAndDescendants( GtkTreeView * view, GArray * indices )
|
||||||
{
|
{
|
||||||
struct ActiveData data;
|
struct ActiveData data;
|
||||||
data.sel = gtk_tree_view_get_selection( view );
|
data.sel = gtk_tree_view_get_selection( view );
|
||||||
data.array = g_array_new( FALSE, FALSE, sizeof( tr_file_index_t ) );
|
data.array = indices;
|
||||||
gtk_tree_model_foreach( gtk_tree_view_get_model( view ), getActiveFilesForeach, &data );
|
gtk_tree_model_foreach( gtk_tree_view_get_model( view ), getSelectedFilesForeach, &data );
|
||||||
return data.array;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
/* if `path' is a selected row, all selected rows are returned.
|
||||||
setPriority( FileData * data, int priority )
|
* otherwise, only the row indicated by `path' is returned.
|
||||||
|
* this is for toggling all the selected rows' states in a batch.
|
||||||
|
*/
|
||||||
|
static GArray*
|
||||||
|
getActiveFilesForPath( GtkTreeView * view, GtkTreePath * path )
|
||||||
{
|
{
|
||||||
GtkTreeView * view = GTK_TREE_VIEW( data->view );
|
|
||||||
GArray * a = getActiveFiles( view );
|
|
||||||
tr_torrentSetFilePriorities( tr_torrent_handle( data->gtor ),
|
|
||||||
(tr_file_index_t*)a->data,
|
|
||||||
(tr_file_index_t)a->len,
|
|
||||||
priority );
|
|
||||||
refresh( data );
|
|
||||||
g_array_free( a, TRUE );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
onHighClicked( GtkButton * button UNUSED, gpointer gdata )
|
|
||||||
{
|
|
||||||
setPriority( gdata, TR_PRI_HIGH );
|
|
||||||
}
|
|
||||||
static void
|
|
||||||
onNormalClicked( GtkButton * button UNUSED, gpointer gdata )
|
|
||||||
{
|
|
||||||
setPriority( gdata, TR_PRI_NORMAL );
|
|
||||||
}
|
|
||||||
static void
|
|
||||||
onLowClicked( GtkButton * button UNUSED, gpointer gdata )
|
|
||||||
{
|
|
||||||
setPriority( gdata, TR_PRI_LOW );
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
onDownloadToggled( GtkCellRendererToggle * cell UNUSED, char * path_str, gpointer gdata )
|
|
||||||
{
|
|
||||||
FileData * data = gdata;
|
|
||||||
GtkTreeView * view = GTK_TREE_VIEW( data->view );
|
|
||||||
GtkTreeSelection * sel = gtk_tree_view_get_selection( view );
|
GtkTreeSelection * sel = gtk_tree_view_get_selection( view );
|
||||||
GtkTreePath * path = gtk_tree_path_new_from_string( path_str );
|
GArray * indices = g_array_new( FALSE, FALSE, sizeof( tr_file_index_t ) );
|
||||||
GArray * a;
|
|
||||||
|
|
||||||
if( gtk_tree_selection_path_is_selected( sel, path ) )
|
if( gtk_tree_selection_path_is_selected( sel, path ) )
|
||||||
{
|
{
|
||||||
/* clicked in a selected row... use the current selection */
|
/* clicked in a selected row... use the current selection */
|
||||||
a = getActiveFiles( view );
|
getSelectedFilesAndDescendants( view, indices );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -401,30 +371,12 @@ onDownloadToggled( GtkCellRendererToggle * cell UNUSED, char * path_str, gpointe
|
||||||
GtkTreeModel * model = gtk_tree_view_get_model( view );
|
GtkTreeModel * model = gtk_tree_view_get_model( view );
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
gtk_tree_model_get_iter( model, &iter, path );
|
gtk_tree_model_get_iter( model, &iter, path );
|
||||||
a = g_array_new( FALSE, FALSE, sizeof( tr_file_index_t ) );
|
|
||||||
gtk_tree_model_get( model, &iter, FC_IS_FILE, &is_file, FC_INDEX, &i, -1 );
|
gtk_tree_model_get( model, &iter, FC_IS_FILE, &is_file, FC_INDEX, &i, -1 );
|
||||||
if( is_file ) {
|
if( is_file )
|
||||||
g_message( "appending %u", i );
|
g_array_append_val( indices, i );
|
||||||
g_array_append_val( a, i );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( a->len )
|
return indices;
|
||||||
{
|
|
||||||
/* toggle the selected files based on the first one's current value */
|
|
||||||
const tr_file_index_t i = g_array_index( a, tr_file_index_t, 0 );
|
|
||||||
const tr_info * inf = tr_torrentInfo( tr_torrent_handle( data->gtor ) );
|
|
||||||
const int do_download = inf->files[i].dnd;
|
|
||||||
tr_torrentSetFileDLs ( tr_torrent_handle( data->gtor ),
|
|
||||||
(tr_file_index_t*)a->data,
|
|
||||||
(tr_file_index_t)a->len,
|
|
||||||
do_download );
|
|
||||||
refresh( data );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* cleanup */
|
|
||||||
g_array_free( a, TRUE );
|
|
||||||
gtk_tree_path_free( path );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
/***
|
||||||
|
@ -615,25 +567,94 @@ renderPriority( GtkTreeViewColumn * column UNUSED,
|
||||||
static gboolean
|
static gboolean
|
||||||
onViewButtonPressed( GtkWidget * w,
|
onViewButtonPressed( GtkWidget * w,
|
||||||
GdkEventButton * event,
|
GdkEventButton * event,
|
||||||
gpointer unused UNUSED )
|
gpointer gdata )
|
||||||
{
|
{
|
||||||
|
FileData * data = gdata;
|
||||||
gboolean handled = FALSE;
|
gboolean handled = FALSE;
|
||||||
|
|
||||||
if( ( event->type == GDK_BUTTON_PRESS ) && ( event->button == 1 ) )
|
if( ( event->type == GDK_BUTTON_PRESS ) && ( event->button == 1 ) && !( event->state & ( GDK_SHIFT_MASK|GDK_CONTROL_MASK) ) )
|
||||||
{
|
{
|
||||||
|
GtkTreeView * view = GTK_TREE_VIEW( w );
|
||||||
GtkTreePath * path;
|
GtkTreePath * path;
|
||||||
GtkTreeViewColumn * column;
|
GtkTreeViewColumn * column;
|
||||||
int cell_x;
|
int cell_x;
|
||||||
int cell_y;
|
int cell_y;
|
||||||
if( gtk_tree_view_get_path_at_pos( GTK_TREE_VIEW( w ), event->x, event->y,
|
if( gtk_tree_view_get_path_at_pos( view, event->x, event->y,
|
||||||
&path, &column, &cell_x, &cell_y ) )
|
&path, &column, &cell_x, &cell_y ) )
|
||||||
{
|
{
|
||||||
const char * column_title = gtk_tree_view_column_get_title( column );
|
const char * column_title = gtk_tree_view_column_get_title( column );
|
||||||
if( !strcmp( column_title, _( "Priority" ) ) )
|
const gboolean downloadColumn = !strcmp( column_title, Q_( "filedetails|Download" ) );
|
||||||
|
const gboolean priorityColumn = !strcmp( column_title, _( "Priority" ) );
|
||||||
|
if( downloadColumn || priorityColumn )
|
||||||
{
|
{
|
||||||
handled = TRUE;
|
GArray * a = getActiveFilesForPath( view, path );
|
||||||
g_message( "row is (%s)", gtk_tree_path_to_string( path ) );
|
GtkTreeSelection * sel = gtk_tree_view_get_selection( view );
|
||||||
|
const gboolean isSelected = gtk_tree_selection_path_is_selected( sel, path );
|
||||||
|
GtkTreeModel * model = gtk_tree_view_get_model( view );
|
||||||
|
GtkTreeIter iter;
|
||||||
|
|
||||||
|
gtk_tree_model_get_iter( model, &iter, path );
|
||||||
|
|
||||||
|
if( priorityColumn )
|
||||||
|
{
|
||||||
|
gboolean is_file;
|
||||||
|
int sub_state;
|
||||||
|
int priority;
|
||||||
|
|
||||||
|
/* get the `priority' state of the clicked row */
|
||||||
|
gtk_tree_model_get( model, &iter, FC_IS_FILE, &is_file,
|
||||||
|
FC_PRIORITY, &priority,
|
||||||
|
FC_SUB_STATE, &sub_state,
|
||||||
|
-1 );
|
||||||
|
|
||||||
|
/* twiddle it to the next state */
|
||||||
|
if( !is_file ) switch( sub_state & SUB_STATE_PRIORITY_MASK ) {
|
||||||
|
case SUB_STATE_NORMAL: priority = TR_PRI_HIGH; break;
|
||||||
|
case SUB_STATE_HIGH: priority = TR_PRI_LOW; break;
|
||||||
|
default: priority = TR_PRI_NORMAL; break;
|
||||||
|
} else switch( priority ) {
|
||||||
|
case TR_PRI_LOW: priority = TR_PRI_NORMAL; break;
|
||||||
|
case TR_PRI_NORMAL: priority = TR_PRI_HIGH; break;
|
||||||
|
case TR_PRI_HIGH: priority = TR_PRI_LOW; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* apply that new state to the active files */
|
||||||
|
tr_torrentSetFilePriorities( tr_torrent_handle( data->gtor ),
|
||||||
|
(tr_file_index_t*)a->data,
|
||||||
|
(tr_file_index_t)a->len,
|
||||||
|
priority );
|
||||||
|
}
|
||||||
|
else if( downloadColumn )
|
||||||
|
{
|
||||||
|
gboolean is_file;
|
||||||
|
int sub_state;
|
||||||
|
gboolean enabled;
|
||||||
|
|
||||||
|
/* get the `enabled' state of the row that was clicked on */
|
||||||
|
gtk_tree_model_get( model, &iter, FC_IS_FILE, &is_file,
|
||||||
|
FC_ENABLED, &enabled,
|
||||||
|
FC_SUB_STATE, &sub_state, -1 );
|
||||||
|
|
||||||
|
/* twiddle it to the next state */
|
||||||
|
if( is_file )
|
||||||
|
enabled = !enabled;
|
||||||
|
else
|
||||||
|
enabled = ( sub_state & SUB_STATE_IGNORE ) ? 1 : 0;
|
||||||
|
|
||||||
|
/* apply that new state to the active files */
|
||||||
|
tr_torrentSetFileDLs ( tr_torrent_handle( data->gtor ),
|
||||||
|
(tr_file_index_t*)a->data,
|
||||||
|
(tr_file_index_t)a->len,
|
||||||
|
enabled );
|
||||||
|
}
|
||||||
|
|
||||||
|
refresh( data );
|
||||||
|
handled = isSelected;
|
||||||
|
|
||||||
|
/* cleanup */
|
||||||
|
g_array_free( a, TRUE );
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_tree_path_free( path );
|
gtk_tree_path_free( path );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -645,20 +666,17 @@ GtkWidget *
|
||||||
file_list_new( TrTorrent * gtor )
|
file_list_new( TrTorrent * gtor )
|
||||||
{
|
{
|
||||||
GtkWidget * ret;
|
GtkWidget * ret;
|
||||||
FileData * data;
|
|
||||||
GtkWidget * view, * scroll;
|
GtkWidget * view, * scroll;
|
||||||
GtkCellRenderer * rend;
|
GtkCellRenderer * rend;
|
||||||
GtkTreeViewColumn * col;
|
GtkTreeViewColumn * col;
|
||||||
GtkTreeSelection * sel;
|
GtkTreeSelection * sel;
|
||||||
GtkWidget * hbox;
|
FileData * data = g_new0( FileData, 1 );
|
||||||
GtkWidget * vbox;
|
|
||||||
GtkWidget * w;
|
|
||||||
|
|
||||||
/* create the view */
|
/* create the view */
|
||||||
view = gtk_tree_view_new( );
|
view = gtk_tree_view_new( );
|
||||||
gtk_tree_view_set_rules_hint( GTK_TREE_VIEW( view ), TRUE );
|
gtk_tree_view_set_rules_hint( GTK_TREE_VIEW( view ), TRUE );
|
||||||
gtk_container_set_border_width( GTK_CONTAINER( view ), GUI_PAD_BIG );
|
gtk_container_set_border_width( GTK_CONTAINER( view ), GUI_PAD_BIG );
|
||||||
g_signal_connect( view, "button-press-event", G_CALLBACK(onViewButtonPressed), NULL );
|
g_signal_connect( view, "button-press-event", G_CALLBACK(onViewButtonPressed), data );
|
||||||
|
|
||||||
/* set up view */
|
/* set up view */
|
||||||
sel = gtk_tree_view_get_selection( GTK_TREE_VIEW( view ) );
|
sel = gtk_tree_view_get_selection( GTK_TREE_VIEW( view ) );
|
||||||
|
@ -691,11 +709,9 @@ file_list_new( TrTorrent * gtor )
|
||||||
col = gtk_tree_view_column_new_with_attributes( Q_("filedetails|Progress"), rend, NULL );
|
col = gtk_tree_view_column_new_with_attributes( Q_("filedetails|Progress"), rend, NULL );
|
||||||
gtk_tree_view_column_set_cell_data_func( col, rend, renderProgress, NULL, NULL);
|
gtk_tree_view_column_set_cell_data_func( col, rend, renderProgress, NULL, NULL);
|
||||||
gtk_tree_view_append_column ( GTK_TREE_VIEW( view ), col);
|
gtk_tree_view_append_column ( GTK_TREE_VIEW( view ), col);
|
||||||
data = g_new0( FileData, 1 );
|
|
||||||
|
|
||||||
/* add "enabled" column */
|
/* add "enabled" column */
|
||||||
rend = gtk_cell_renderer_toggle_new( );
|
rend = gtk_cell_renderer_toggle_new( );
|
||||||
g_signal_connect( rend, "toggled", G_CALLBACK( onDownloadToggled ), data );
|
|
||||||
/* Translators: this is a column header in Files tab, Details dialog;
|
/* Translators: this is a column header in Files tab, Details dialog;
|
||||||
Don't include the prefix "filedetails|" in the translation.
|
Don't include the prefix "filedetails|" in the translation.
|
||||||
The items for this column are checkboxes (yes/no) */
|
The items for this column are checkboxes (yes/no) */
|
||||||
|
@ -718,21 +734,7 @@ data = g_new0( FileData, 1 );
|
||||||
gtk_container_add( GTK_CONTAINER( scroll ), view );
|
gtk_container_add( GTK_CONTAINER( scroll ), view );
|
||||||
gtk_widget_set_size_request (scroll, -1, 200 );
|
gtk_widget_set_size_request (scroll, -1, 200 );
|
||||||
|
|
||||||
vbox = gtk_vbox_new( FALSE, GUI_PAD );
|
ret = scroll;
|
||||||
w = gtk_button_new_with_mnemonic( _( "_High" ) );
|
|
||||||
g_signal_connect( w, "clicked", G_CALLBACK(onHighClicked), data );
|
|
||||||
gtk_box_pack_start( GTK_BOX( vbox ), w, FALSE, FALSE, 0 );
|
|
||||||
w = gtk_button_new_with_mnemonic( _( "_Normal" ) );
|
|
||||||
g_signal_connect( w, "clicked", G_CALLBACK(onNormalClicked), data );
|
|
||||||
gtk_box_pack_start( GTK_BOX( vbox ), w, FALSE, FALSE, 0 );
|
|
||||||
w = gtk_button_new_with_mnemonic( _( "_Low" ) );
|
|
||||||
g_signal_connect( w, "clicked", G_CALLBACK(onLowClicked), data );
|
|
||||||
gtk_box_pack_start( GTK_BOX( vbox ), w, FALSE, FALSE, 0 );
|
|
||||||
hbox = gtk_hbox_new( FALSE, GUI_PAD );
|
|
||||||
gtk_box_pack_start_defaults( GTK_BOX( hbox ), scroll );
|
|
||||||
gtk_box_pack_start( GTK_BOX( hbox ), vbox, 0, 0, 0 );
|
|
||||||
|
|
||||||
ret = hbox;
|
|
||||||
data->view = view;
|
data->view = view;
|
||||||
data->top = scroll;
|
data->top = scroll;
|
||||||
g_object_set_data_full( G_OBJECT( ret ), "file-data", data, freeData );
|
g_object_set_data_full( G_OBJECT( ret ), "file-data", data, freeData );
|
||||||
|
|
Loading…
Reference in a new issue