Changeset 10993


Ignore:
Timestamp:
Jul 11, 2010, 6:46:46 AM (12 years ago)
Author:
charles
Message:

(trunk gtk) #3416 "clicking close on the transmission window causes new "Quit Transmission?" dialog even if one already exists" -- fixed

Location:
trunk/gtk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/dialogs.c

    r10660 r10993  
    6565}
    6666
    67 static gboolean
    68 countActiveTorrents( GtkTreeModel *       model,
    69                      GtkTreePath   * path UNUSED,
    70                      GtkTreeIter *        iter,
    71                      gpointer             activeTorrentCount )
    72 {
    73     int activity = -1;
    74     gtk_tree_model_get( model, iter, MC_ACTIVITY, &activity, -1 );
    75     if( activity != TR_STATUS_STOPPED )
    76         *(int*)activeTorrentCount += 1;
    77     return FALSE; /* keep iterating */
    78 }
    79 
    80 void
     67GtkWidget *
    8168askquit( TrCore *       core,
    8269         GtkWindow *    parent,
     
    8875    GtkWidget *       wind;
    8976    GtkWidget *       dontask;
    90     GtkTreeModel *    model;
    91     int               activeTorrentCount;
    92 
    93     /* if the user doesn't want to be asked, don't ask */
    94     if( !pref_flag_get( PREF_KEY_ASKQUIT ) )
    95     {
    96         func( cbdata );
    97         return;
    98     }
    99 
    100     /* if there aren't any active torrents, don't ask */
    101     model = tr_core_model( core );
    102     activeTorrentCount = 0;
    103     gtk_tree_model_foreach( model, countActiveTorrents, &activeTorrentCount );
    104     if( !activeTorrentCount )
    105     {
    106         func( cbdata );
    107         return;
    108     }
    10977
    11078    stuff          = g_new( struct quitdata, 1 );
     
    143111
    144112    gtk_widget_show_all( wind );
     113
     114    return wind;
    145115}
    146116
  • trunk/gtk/dialogs.h

    r8846 r10993  
    3535
    3636/* prompt if the user wants to quit, calls func with cbdata if they do */
    37 void askquit( TrCore          * core,
    38               GtkWindow       * parent,
    39               callbackfunc_t    func,
    40               gpointer          cbdata );
     37GtkWidget * askquit( TrCore          * core,
     38                      GtkWindow       * parent,
     39                      callbackfunc_t    func,
     40                      gpointer          cbdata );
    4141
    4242void confirmRemove( GtkWindow * parent,
  • trunk/gtk/main.c

    r10991 r10993  
    8585    GSList            * details;
    8686    GtkTreeSelection  * sel;
     87    GtkWidget         * quit_dialog;
    8788};
    8889
     
    282283                         gpointer            user_data )
    283284{
    284     int                  activity = 0;
     285    int activity = 0;
    285286    struct counts_data * counts = user_data;
    286287
     
    296297
    297298static void
     299getTorrentCounts( struct cbdata * data, struct counts_data * counts )
     300{
     301    counts->activeCount = 0;
     302    counts->inactiveCount = 0;
     303    counts->totalCount = 0;
     304
     305    gtk_tree_selection_selected_foreach( data->sel, accumulateStatusForeach, counts );
     306}
     307
     308static void
    298309accumulateCanUpdateForeach( GtkTreeModel *      model,
    299310                            GtkTreePath  * path UNUSED,
     
    312323    struct counts_data counts;
    313324    struct cbdata * data = gdata;
    314     GtkTreeSelection * s = data->sel;
    315 
    316     counts.activeCount = 0;
    317     counts.inactiveCount = 0;
    318     counts.totalCount = 0;
    319     gtk_tree_selection_selected_foreach( s, accumulateStatusForeach, &counts );
     325
     326    getTorrentCounts( data, &counts );
    320327    action_sensitize( "pause-torrent", counts.activeCount != 0 );
    321328    action_sensitize( "start-torrent", counts.inactiveCount != 0 );
     
    329336
    330337    canUpdate = 0;
    331     gtk_tree_selection_selected_foreach( s, accumulateCanUpdateForeach, &canUpdate );
     338    gtk_tree_selection_selected_foreach( data->sel, accumulateCanUpdateForeach, &canUpdate );
    332339    action_sensitize( "update-tracker", canUpdate != 0 );
    333340
    334341    {
    335         GtkTreeView *  view = gtk_tree_selection_get_tree_view( s );
     342        GtkTreeView * view = gtk_tree_selection_get_tree_view( data->sel );
    336343        GtkTreeModel * model = gtk_tree_view_get_model( view );
    337344        const int torrentCount = gtk_tree_model_iter_n_children( model, NULL ) != 0;
     
    806813
    807814static gboolean
     815shouldConfirmBeforeExiting( struct cbdata * data )
     816{
     817    if( !pref_flag_get( PREF_KEY_ASKQUIT ) )
     818        return FALSE;
     819    else {
     820        struct counts_data counts;
     821        getTorrentCounts( data, &counts );
     822        return counts.activeCount > 0;
     823    }
     824}
     825
     826static void
     827maybeaskquit( struct cbdata * cbdata )
     828{
     829    if( !shouldConfirmBeforeExiting( cbdata ) )
     830        wannaquit( cbdata );
     831    else {
     832        if( cbdata->quit_dialog == NULL )
     833            cbdata->quit_dialog = askquit( cbdata->core, cbdata->wind, wannaquit, cbdata );
     834        gtk_window_present( GTK_WINDOW( cbdata->quit_dialog ) );
     835    }
     836}
     837
     838static gboolean
    808839winclose( GtkWidget * w    UNUSED,
    809840          GdkEvent * event UNUSED,
     
    815846        action_activate ( "toggle-main-window" );
    816847    else
    817         askquit( cbdata->core, cbdata->wind, wannaquit, cbdata );
     848        maybeaskquit( cbdata );
    818849
    819850    return TRUE; /* don't propagate event further */
     
    16931724    else if( !strcmp( action_name, "quit" ) )
    16941725    {
    1695         askquit( data->core, data->wind, wannaquit, data );
     1726        maybeaskquit( data );
    16961727    }
    16971728    else if( !strcmp( action_name, "select-all" ) )
Note: See TracChangeset for help on using the changeset viewer.