Changeset 10994


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

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

Location:
branches/2.0x/gtk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2.0x/gtk/dialogs.c

    r10660 r10994  
    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
  • branches/2.0x/gtk/dialogs.h

    r8846 r10994  
    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,
  • branches/2.0x/gtk/main.c

    r10992 r10994  
    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;
     
    799806
    800807static gboolean
     808shouldConfirmBeforeExiting( struct cbdata * data )
     809{
     810    if( !pref_flag_get( PREF_KEY_ASKQUIT ) )
     811        return FALSE;
     812    else {
     813        struct counts_data counts;
     814        getTorrentCounts( data, &counts );
     815        return counts.activeCount > 0;
     816    }
     817}
     818
     819static void
     820maybeaskquit( struct cbdata * cbdata )
     821{
     822    if( !shouldConfirmBeforeExiting( cbdata ) )
     823        wannaquit( cbdata );
     824    else {
     825        if( cbdata->quit_dialog == NULL )
     826            cbdata->quit_dialog = askquit( cbdata->core, cbdata->wind, wannaquit, cbdata );
     827        gtk_window_present( GTK_WINDOW( cbdata->quit_dialog ) );
     828    }
     829}
     830
     831static gboolean
    801832winclose( GtkWidget * w    UNUSED,
    802833          GdkEvent * event UNUSED,
     
    808839        action_activate ( "toggle-main-window" );
    809840    else
    810         askquit( cbdata->core, cbdata->wind, wannaquit, cbdata );
     841        maybeaskquit( cbdata );
    811842
    812843    return TRUE; /* don't propagate event further */
     
    16891720    else if( !strcmp( action_name, "quit" ) )
    16901721    {
    1691         askquit( data->core, data->wind, wannaquit, data );
     1722        maybeaskquit( data );
    16921723    }
    16931724    else if( !strcmp( action_name, "select-all" ) )
Note: See TracChangeset for help on using the changeset viewer.