(gtk) #748: hig improvements to the `remove torrent' confirmation dialog.

This commit is contained in:
Charles Kerr 2008-03-02 15:54:58 +00:00
parent f1c3b160af
commit f71665e166
5 changed files with 109 additions and 84 deletions

View File

@ -115,6 +115,8 @@ static GtkActionEntry entries[] =
N_("_Pause"), "<control>P", NULL, G_CALLBACK(action_cb) }, N_("_Pause"), "<control>P", NULL, G_CALLBACK(action_cb) },
{ "remove-torrent", GTK_STOCK_REMOVE, { "remove-torrent", GTK_STOCK_REMOVE,
N_("_Remove"), "Delete", NULL, G_CALLBACK(action_cb) }, N_("_Remove"), "Delete", NULL, G_CALLBACK(action_cb) },
{ "delete-torrent", GTK_STOCK_DELETE,
N_("_Delete Files"), "<control>Delete", NULL, G_CALLBACK(action_cb) },
{ "new-torrent", GTK_STOCK_NEW, N_("_New..."), NULL, { "new-torrent", GTK_STOCK_NEW, N_("_New..."), NULL,
N_("Create a new torrent"), N_("Create a new torrent"),
G_CALLBACK(action_cb) }, G_CALLBACK(action_cb) },

View File

@ -289,36 +289,25 @@ askquit( TrCore * core,
struct DeleteData struct DeleteData
{ {
GtkWidget * delete_files_tb; gboolean delete_files;
GList * torrents; GList * torrents;
TrCore * core; TrCore * core;
}; };
static void static void
deleteDownloadedToggled( GtkToggleButton * tb, gpointer warn ) removeResponse( GtkDialog * dialog, gint response, gpointer gdata )
{
GtkWidget * w = GTK_WIDGET( warn );
if( gtk_toggle_button_get_active( tb ) )
gtk_widget_show( w );
else
gtk_widget_hide( w );
}
static void
deleteResponse( GtkDialog * dialog, gint response, gpointer gdata )
{ {
struct DeleteData * data = gdata; struct DeleteData * data = gdata;
const int del = response == GTK_RESPONSE_ACCEPT; const int doRemove = response == GTK_RESPONSE_ACCEPT;
const int deleteFiles = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( data->delete_files_tb ) ); const int doDelete = data->delete_files;
GList * l; GList * l;
for( l=data->torrents; l!=NULL; l=l->next ) for( l=data->torrents; l!=NULL; l=l->next )
{ {
TrTorrent * gtor = TR_TORRENT( l->data ); TrTorrent * gtor = TR_TORRENT( l->data );
if( del ) if( doRemove )
tr_core_remove_torrent( data->core, gtor, deleteFiles ); tr_core_remove_torrent( data->core, gtor, doDelete );
else else
g_object_unref( G_OBJECT( gtor ) ); g_object_unref( G_OBJECT( gtor ) );
} }
@ -329,62 +318,77 @@ deleteResponse( GtkDialog * dialog, gint response, gpointer gdata )
} }
void void
confirmDelete( GtkWindow * parent, confirmRemove( GtkWindow * parent,
TrCore * core, TrCore * core,
GList * torrents ) GList * torrents )
{ {
char buf[1024];
GtkWidget * t;
GtkWidget * d; GtkWidget * d;
GtkWidget * w; char text[128];
GtkWidget * warn;
struct DeleteData * dd = g_new0( struct DeleteData, 1 ); struct DeleteData * dd = g_new0( struct DeleteData, 1 );
dd->core = core; dd->core = core;
dd->torrents = torrents; dd->torrents = torrents;
dd->delete_files = FALSE;
d = gtk_dialog_new_with_buttons( _( "Remove Torrent" ), g_snprintf( text, sizeof( text ),
parent, ngettext( "Remove torrent?",
GTK_DIALOG_DESTROY_WITH_PARENT|GTK_DIALOG_NO_SEPARATOR, "Remove torrents?",
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, g_list_length( torrents ) ) );
GTK_STOCK_REMOVE, GTK_RESPONSE_ACCEPT, d = gtk_message_dialog_new_with_markup( parent,
NULL ); GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_NONE,
"<b>%s</b>", text );
gtk_message_dialog_format_secondary_text( GTK_MESSAGE_DIALOG( d ),
_( "This removes the torrent, not its downloads." ) );
gtk_dialog_add_buttons( GTK_DIALOG( d ),
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_REMOVE, GTK_RESPONSE_ACCEPT,
NULL );
gtk_dialog_set_default_response( GTK_DIALOG ( d ),
GTK_RESPONSE_ACCEPT );
gtk_dialog_set_alternative_button_order( GTK_DIALOG( d ), gtk_dialog_set_alternative_button_order( GTK_DIALOG( d ),
GTK_RESPONSE_ACCEPT, GTK_RESPONSE_ACCEPT,
GTK_RESPONSE_CANCEL, GTK_RESPONSE_CANCEL,
-1 ); -1 );
g_signal_connect( d, "response", G_CALLBACK( deleteResponse ), dd ); g_signal_connect( d, "response", G_CALLBACK( removeResponse ), dd );
gtk_widget_show_all( d );
t = gtk_table_new( 3, 2, FALSE ); }
gtk_container_set_border_width( GTK_CONTAINER( t ), GUI_PAD_BIG );
gtk_table_set_col_spacing( GTK_TABLE( t ), 0, GUI_PAD_BIG ); void
gtk_table_set_row_spacings( GTK_TABLE( t ), GUI_PAD_BIG ); confirmDelete( GtkWindow * parent,
TrCore * core,
w = gtk_image_new_from_stock( GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_DIALOG ); GList * torrents )
gtk_table_attach( GTK_TABLE( t ), w, 0, 1, 0, 3, GTK_FILL, GTK_FILL, 0, 0 ); {
gtk_widget_show( w ); GtkWidget * d;
char text[128];
g_snprintf( buf, sizeof(buf), "<b>%s</b>", _( "Remove the selected torrent(s)?" ) ); struct DeleteData * dd = g_new0( struct DeleteData, 1 );
w = gtk_label_new( buf );
gtk_misc_set_alignment( GTK_MISC( w ), 0.0, 0.5 ); dd->core = core;
gtk_label_set_use_markup( GTK_LABEL( w ), TRUE ); dd->torrents = torrents;
gtk_table_attach( GTK_TABLE( t ), w, 1, 2, 0, 1, GTK_FILL, 0, 0, 0 ); dd->delete_files = TRUE;
gtk_widget_show( w );
g_snprintf( text, sizeof( text ),
g_snprintf( buf, sizeof( buf ), "<i>%s</i>", ngettext( "Delete torrent?",
_( "All downloaded files for this torrent will be deleted!" ) ); "Delete torrents?",
warn = gtk_label_new( buf ); g_list_length( torrents ) ) );
gtk_label_set_use_markup( GTK_LABEL( warn ), TRUE ); d = gtk_message_dialog_new_with_markup( parent,
gtk_table_attach( GTK_TABLE( t ), warn, 1, 2, 2, 3, GTK_FILL, 0, 0, 0 ); GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_WARNING,
w = gtk_check_button_new_with_mnemonic( _( "Delete _downloaded files" ) ); GTK_BUTTONS_NONE,
dd->delete_files_tb = w; "<b>%s</b>", text );
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( w ), FALSE ); gtk_message_dialog_format_secondary_text( GTK_MESSAGE_DIALOG( d ),
gtk_table_attach( GTK_TABLE( t ), w, 1, 2, 1, 2, GTK_FILL, 0, 0, 0 ); _( "This removes the torrent and deletes its downloads!" ) );
g_signal_connect( w, "toggled", G_CALLBACK(deleteDownloadedToggled), warn ); gtk_dialog_add_buttons( GTK_DIALOG( d ),
gtk_widget_show( w ); GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_DELETE, GTK_RESPONSE_ACCEPT,
gtk_widget_show( t ); NULL );
gtk_container_add( GTK_CONTAINER( GTK_DIALOG( d )->vbox ), t ); gtk_dialog_set_default_response( GTK_DIALOG ( d ),
gtk_widget_show( d ); GTK_RESPONSE_CANCEL );
gtk_dialog_set_alternative_button_order( GTK_DIALOG( d ),
GTK_RESPONSE_ACCEPT,
GTK_RESPONSE_CANCEL,
-1 );
g_signal_connect( d, "response", G_CALLBACK( removeResponse ), dd );
gtk_widget_show_all( d );
} }

View File

@ -39,5 +39,6 @@ GtkWidget* promptfordir( GtkWindow * parent,
void askquit( TrCore*, GtkWindow* parent, callbackfunc_t func, void* cbdata ); void askquit( TrCore*, GtkWindow* parent, callbackfunc_t func, void* cbdata );
void confirmDelete( GtkWindow * parent, TrCore * core, GList * torrents ); void confirmDelete( GtkWindow * parent, TrCore * core, GList * torrents );
void confirmRemove( GtkWindow * parent, TrCore * core, GList * torrents );
#endif /* TG_PREFS_H */ #endif /* TG_PREFS_H */

View File

@ -200,6 +200,7 @@ refreshTorrentActions( GtkTreeSelection * s )
action_sensitize( "pause-torrent", counts.activeCount!=0 ); action_sensitize( "pause-torrent", counts.activeCount!=0 );
action_sensitize( "start-torrent", counts.inactiveCount!=0 ); action_sensitize( "start-torrent", counts.inactiveCount!=0 );
action_sensitize( "remove-torrent", counts.totalCount!=0 ); action_sensitize( "remove-torrent", counts.totalCount!=0 );
action_sensitize( "delete-torrent", counts.totalCount!=0 );
action_sensitize( "verify-torrent", counts.totalCount!=0 ); action_sensitize( "verify-torrent", counts.totalCount!=0 );
action_sensitize( "show-torrent-details", counts.totalCount==1 ); action_sensitize( "show-torrent-details", counts.totalCount==1 );
@ -806,7 +807,8 @@ coreprompt( TrCore * core,
} }
#if GTK_CHECK_VERSION(2,8,0) #if GTK_CHECK_VERSION(2,8,0)
gtk_window_set_urgency_hint( GTK_WINDOW( cbdata->wind ), TRUE ); if( cbdata->wind )
gtk_window_set_urgency_hint( GTK_WINDOW( cbdata->wind ), TRUE );
g_signal_connect( w, "focus-in-event", g_signal_connect( w, "focus-in-event",
G_CALLBACK(on_main_window_focus_in), cbdata ); G_CALLBACK(on_main_window_focus_in), cbdata );
#endif #endif
@ -955,18 +957,6 @@ stopTorrentForeach (GtkTreeModel * model,
g_object_unref( G_OBJECT( tor ) ); g_object_unref( G_OBJECT( tor ) );
} }
static void
accumulateSelectedTorrents( GtkTreeModel * model,
GtkTreePath * path UNUSED,
GtkTreeIter * iter,
gpointer gdata )
{
GList ** data = ( GList** ) gdata;
TrTorrent * tor = NULL;
gtk_tree_model_get( model, iter, MC_TORRENT, &tor, -1 );
*data = g_list_append( *data, tor );
}
static void static void
updateTrackerForeach (GtkTreeModel * model, updateTrackerForeach (GtkTreeModel * model,
GtkTreePath * path UNUSED, GtkTreePath * path UNUSED,
@ -1028,12 +1018,39 @@ recheckTorrentForeach (GtkTreeModel * model,
} }
static gboolean static gboolean
msgwinclosed() msgwinclosed( void )
{ {
action_toggle( "toggle-message-log", FALSE ); action_toggle( "toggle-message-log", FALSE );
return FALSE; return FALSE;
} }
static void
accumulateSelectedTorrents( GtkTreeModel * model,
GtkTreePath * path UNUSED,
GtkTreeIter * iter,
gpointer gdata )
{
GList ** data = ( GList** ) gdata;
TrTorrent * tor = NULL;
gtk_tree_model_get( model, iter, MC_TORRENT, &tor, -1 );
*data = g_list_append( *data, tor );
}
static void
removeSelected( struct cbdata * data, gboolean doDelete )
{
GList * l = NULL;
GtkTreeSelection * s = tr_window_get_selection( data->wind );
gtk_tree_selection_selected_foreach( s, accumulateSelectedTorrents, &l );
gtk_tree_selection_unselect_all( s );
if( l ) {
if( doDelete )
confirmDelete( data->wind, data->core, l );
else
confirmRemove( data->wind, data->core, l );
}
}
void void
doAction ( const char * action_name, gpointer user_data ) doAction ( const char * action_name, gpointer user_data )
{ {
@ -1085,14 +1102,13 @@ doAction ( const char * action_name, gpointer user_data )
tr_core_handle( data->core ) ); tr_core_handle( data->core ) );
gtk_widget_show_all( w ); gtk_widget_show_all( w );
} }
else if (!strcmp (action_name, "remove-torrent")) else if( !strcmp( action_name, "remove-torrent" ) )
{ {
GList * l = NULL; removeSelected( data, FALSE );
GtkTreeSelection * s = tr_window_get_selection(data->wind); }
gtk_tree_selection_selected_foreach( s, accumulateSelectedTorrents, &l ); else if( !strcmp( action_name, "delete-torrent" ) )
gtk_tree_selection_unselect_all( s ); {
if( l != NULL ) removeSelected( data, TRUE );
confirmDelete( data->wind, data->core, l );
} }
else if (!strcmp (action_name, "close")) else if (!strcmp (action_name, "close"))
{ {

View File

@ -9,8 +9,9 @@ const char * fallback_ui_file =
" <menuitem action='update-tracker'/>\n" " <menuitem action='update-tracker'/>\n"
" <menuitem action='pause-torrent'/>\n" " <menuitem action='pause-torrent'/>\n"
" <menuitem action='verify-torrent'/>\n" " <menuitem action='verify-torrent'/>\n"
" <menuitem action='remove-torrent'/>\n"
" <menuitem action='show-torrent-details'/>\n" " <menuitem action='show-torrent-details'/>\n"
" <menuitem action='remove-torrent'/>\n"
" <menuitem action='delete-torrent'/>\n"
" <separator/>\n" " <separator/>\n"
" <menuitem action='close'/>\n" " <menuitem action='close'/>\n"
" <menuitem action='quit'/>\n" " <menuitem action='quit'/>\n"
@ -62,6 +63,7 @@ const char * fallback_ui_file =
" <menuitem action='update-tracker'/>\n" " <menuitem action='update-tracker'/>\n"
" <separator/>\n" " <separator/>\n"
" <menuitem action='remove-torrent'/>\n" " <menuitem action='remove-torrent'/>\n"
" <menuitem action='delete-torrent'/>\n"
" </popup>\n" " </popup>\n"
"\n" "\n"
" <popup name='icon-popup'>\n" " <popup name='icon-popup'>\n"