(trunk gtk) #3416 "clicking close on the transmission window causes new "Quit Transmission?" dialog even if one already exists" -- fixed
This commit is contained in:
parent
7233b57355
commit
68cc4d902f
|
@ -64,20 +64,7 @@ quitresp( GtkWidget * widget,
|
|||
gtk_widget_destroy( widget );
|
||||
}
|
||||
|
||||
static gboolean
|
||||
countActiveTorrents( GtkTreeModel * model,
|
||||
GtkTreePath * path UNUSED,
|
||||
GtkTreeIter * iter,
|
||||
gpointer activeTorrentCount )
|
||||
{
|
||||
int activity = -1;
|
||||
gtk_tree_model_get( model, iter, MC_ACTIVITY, &activity, -1 );
|
||||
if( activity != TR_STATUS_STOPPED )
|
||||
*(int*)activeTorrentCount += 1;
|
||||
return FALSE; /* keep iterating */
|
||||
}
|
||||
|
||||
void
|
||||
GtkWidget *
|
||||
askquit( TrCore * core,
|
||||
GtkWindow * parent,
|
||||
callbackfunc_t func,
|
||||
|
@ -87,25 +74,6 @@ askquit( TrCore * core,
|
|||
GtkWidget * w;
|
||||
GtkWidget * wind;
|
||||
GtkWidget * dontask;
|
||||
GtkTreeModel * model;
|
||||
int activeTorrentCount;
|
||||
|
||||
/* if the user doesn't want to be asked, don't ask */
|
||||
if( !pref_flag_get( PREF_KEY_ASKQUIT ) )
|
||||
{
|
||||
func( cbdata );
|
||||
return;
|
||||
}
|
||||
|
||||
/* if there aren't any active torrents, don't ask */
|
||||
model = tr_core_model( core );
|
||||
activeTorrentCount = 0;
|
||||
gtk_tree_model_foreach( model, countActiveTorrents, &activeTorrentCount );
|
||||
if( !activeTorrentCount )
|
||||
{
|
||||
func( cbdata );
|
||||
return;
|
||||
}
|
||||
|
||||
stuff = g_new( struct quitdata, 1 );
|
||||
stuff->func = func;
|
||||
|
@ -142,6 +110,8 @@ askquit( TrCore * core,
|
|||
gtk_widget_grab_focus( w );
|
||||
|
||||
gtk_widget_show_all( wind );
|
||||
|
||||
return wind;
|
||||
}
|
||||
|
||||
/***
|
||||
|
|
|
@ -34,10 +34,10 @@
|
|||
typedef void ( *callbackfunc_t )( gpointer );
|
||||
|
||||
/* prompt if the user wants to quit, calls func with cbdata if they do */
|
||||
void askquit( TrCore * core,
|
||||
GtkWindow * parent,
|
||||
callbackfunc_t func,
|
||||
gpointer cbdata );
|
||||
GtkWidget * askquit( TrCore * core,
|
||||
GtkWindow * parent,
|
||||
callbackfunc_t func,
|
||||
gpointer cbdata );
|
||||
|
||||
void confirmRemove( GtkWindow * parent,
|
||||
TrCore * core,
|
||||
|
|
51
gtk/main.c
51
gtk/main.c
|
@ -84,6 +84,7 @@ struct cbdata
|
|||
GSList * dupqueue;
|
||||
GSList * details;
|
||||
GtkTreeSelection * sel;
|
||||
GtkWidget * quit_dialog;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -281,7 +282,7 @@ accumulateStatusForeach( GtkTreeModel * model,
|
|||
GtkTreeIter * iter,
|
||||
gpointer user_data )
|
||||
{
|
||||
int activity = 0;
|
||||
int activity = 0;
|
||||
struct counts_data * counts = user_data;
|
||||
|
||||
++counts->totalCount;
|
||||
|
@ -294,6 +295,16 @@ accumulateStatusForeach( GtkTreeModel * model,
|
|||
++counts->activeCount;
|
||||
}
|
||||
|
||||
static void
|
||||
getTorrentCounts( struct cbdata * data, struct counts_data * counts )
|
||||
{
|
||||
counts->activeCount = 0;
|
||||
counts->inactiveCount = 0;
|
||||
counts->totalCount = 0;
|
||||
|
||||
gtk_tree_selection_selected_foreach( data->sel, accumulateStatusForeach, counts );
|
||||
}
|
||||
|
||||
static void
|
||||
accumulateCanUpdateForeach( GtkTreeModel * model,
|
||||
GtkTreePath * path UNUSED,
|
||||
|
@ -311,12 +322,8 @@ refreshActions( gpointer gdata )
|
|||
int canUpdate;
|
||||
struct counts_data counts;
|
||||
struct cbdata * data = gdata;
|
||||
GtkTreeSelection * s = data->sel;
|
||||
|
||||
counts.activeCount = 0;
|
||||
counts.inactiveCount = 0;
|
||||
counts.totalCount = 0;
|
||||
gtk_tree_selection_selected_foreach( s, accumulateStatusForeach, &counts );
|
||||
getTorrentCounts( data, &counts );
|
||||
action_sensitize( "pause-torrent", counts.activeCount != 0 );
|
||||
action_sensitize( "start-torrent", counts.inactiveCount != 0 );
|
||||
action_sensitize( "remove-torrent", counts.totalCount != 0 );
|
||||
|
@ -328,11 +335,11 @@ refreshActions( gpointer gdata )
|
|||
action_sensitize( "copy-magnet-link-to-clipboard", counts.totalCount == 1 );
|
||||
|
||||
canUpdate = 0;
|
||||
gtk_tree_selection_selected_foreach( s, accumulateCanUpdateForeach, &canUpdate );
|
||||
gtk_tree_selection_selected_foreach( data->sel, accumulateCanUpdateForeach, &canUpdate );
|
||||
action_sensitize( "update-tracker", canUpdate != 0 );
|
||||
|
||||
{
|
||||
GtkTreeView * view = gtk_tree_selection_get_tree_view( s );
|
||||
GtkTreeView * view = gtk_tree_selection_get_tree_view( data->sel );
|
||||
GtkTreeModel * model = gtk_tree_view_get_model( view );
|
||||
const int torrentCount = gtk_tree_model_iter_n_children( model, NULL ) != 0;
|
||||
action_sensitize( "select-all", torrentCount != 0 );
|
||||
|
@ -804,6 +811,30 @@ toggleMainWindow( struct cbdata * cbdata )
|
|||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
shouldConfirmBeforeExiting( struct cbdata * data )
|
||||
{
|
||||
if( !pref_flag_get( PREF_KEY_ASKQUIT ) )
|
||||
return FALSE;
|
||||
else {
|
||||
struct counts_data counts;
|
||||
getTorrentCounts( data, &counts );
|
||||
return counts.activeCount > 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
maybeaskquit( struct cbdata * cbdata )
|
||||
{
|
||||
if( !shouldConfirmBeforeExiting( cbdata ) )
|
||||
wannaquit( cbdata );
|
||||
else {
|
||||
if( cbdata->quit_dialog == NULL )
|
||||
cbdata->quit_dialog = askquit( cbdata->core, cbdata->wind, wannaquit, cbdata );
|
||||
gtk_window_present( GTK_WINDOW( cbdata->quit_dialog ) );
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
winclose( GtkWidget * w UNUSED,
|
||||
GdkEvent * event UNUSED,
|
||||
|
@ -814,7 +845,7 @@ winclose( GtkWidget * w UNUSED,
|
|||
if( cbdata->icon != NULL )
|
||||
action_activate ( "toggle-main-window" );
|
||||
else
|
||||
askquit( cbdata->core, cbdata->wind, wannaquit, cbdata );
|
||||
maybeaskquit( cbdata );
|
||||
|
||||
return TRUE; /* don't propagate event further */
|
||||
}
|
||||
|
@ -1692,7 +1723,7 @@ doAction( const char * action_name, gpointer user_data )
|
|||
}
|
||||
else if( !strcmp( action_name, "quit" ) )
|
||||
{
|
||||
askquit( data->core, data->wind, wannaquit, data );
|
||||
maybeaskquit( data );
|
||||
}
|
||||
else if( !strcmp( action_name, "select-all" ) )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue