- Timestamp:
- Jul 11, 2010, 6:46:48 AM (12 years ago)
- Location:
- branches/2.0x/gtk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.0x/gtk/dialogs.c
r10660 r10994 65 65 } 66 66 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 67 GtkWidget * 81 68 askquit( TrCore * core, 82 69 GtkWindow * parent, … … 88 75 GtkWidget * wind; 89 76 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 }109 77 110 78 stuff = g_new( struct quitdata, 1 ); … … 143 111 144 112 gtk_widget_show_all( wind ); 113 114 return wind; 145 115 } 146 116 -
branches/2.0x/gtk/dialogs.h
r8846 r10994 35 35 36 36 /* prompt if the user wants to quit, calls func with cbdata if they do */ 37 voidaskquit( TrCore * core,38 GtkWindow * parent,39 callbackfunc_t func,40 gpointer cbdata );37 GtkWidget * askquit( TrCore * core, 38 GtkWindow * parent, 39 callbackfunc_t func, 40 gpointer cbdata ); 41 41 42 42 void confirmRemove( GtkWindow * parent, -
branches/2.0x/gtk/main.c
r10992 r10994 85 85 GSList * details; 86 86 GtkTreeSelection * sel; 87 GtkWidget * quit_dialog; 87 88 }; 88 89 … … 282 283 gpointer user_data ) 283 284 { 284 int 285 int activity = 0; 285 286 struct counts_data * counts = user_data; 286 287 … … 296 297 297 298 static void 299 getTorrentCounts( 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 308 static void 298 309 accumulateCanUpdateForeach( GtkTreeModel * model, 299 310 GtkTreePath * path UNUSED, … … 312 323 struct counts_data counts; 313 324 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 ); 320 327 action_sensitize( "pause-torrent", counts.activeCount != 0 ); 321 328 action_sensitize( "start-torrent", counts.inactiveCount != 0 ); … … 329 336 330 337 canUpdate = 0; 331 gtk_tree_selection_selected_foreach( s, accumulateCanUpdateForeach, &canUpdate );338 gtk_tree_selection_selected_foreach( data->sel, accumulateCanUpdateForeach, &canUpdate ); 332 339 action_sensitize( "update-tracker", canUpdate != 0 ); 333 340 334 341 { 335 GtkTreeView * view = gtk_tree_selection_get_tree_view( s);342 GtkTreeView * view = gtk_tree_selection_get_tree_view( data->sel ); 336 343 GtkTreeModel * model = gtk_tree_view_get_model( view ); 337 344 const int torrentCount = gtk_tree_model_iter_n_children( model, NULL ) != 0; … … 799 806 800 807 static gboolean 808 shouldConfirmBeforeExiting( 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 819 static void 820 maybeaskquit( 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 831 static gboolean 801 832 winclose( GtkWidget * w UNUSED, 802 833 GdkEvent * event UNUSED, … … 808 839 action_activate ( "toggle-main-window" ); 809 840 else 810 askquit( cbdata->core, cbdata->wind, wannaquit,cbdata );841 maybeaskquit( cbdata ); 811 842 812 843 return TRUE; /* don't propagate event further */ … … 1689 1720 else if( !strcmp( action_name, "quit" ) ) 1690 1721 { 1691 askquit( data->core, data->wind, wannaquit,data );1722 maybeaskquit( data ); 1692 1723 } 1693 1724 else if( !strcmp( action_name, "select-all" ) )
Note: See TracChangeset
for help on using the changeset viewer.