Changeset 7252 for trunk/gtk/main.c


Ignore:
Timestamp:
Dec 3, 2008, 5:15:17 AM (12 years ago)
Author:
charles
Message:

(gtk) #1300: "pause all" button in the right-click menu of the system tray icon

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/main.c

    r7112 r7252  
    4343
    4444#include <libtransmission/transmission.h>
     45#include <libtransmission/rpcimpl.h>
    4546#include <libtransmission/utils.h>
    4647#include <libtransmission/version.h>
     
    121122    GHashTable *  tor2details;
    122123    GHashTable *  details2tor;
     124    GtkTreeSelection * sel;
    123125};
    124126
     
    198200{
    199201    tr_torrent * tor;
    200 
    201202    gtk_tree_model_get( model, iter, MC_TORRENT_RAW, &tor, -1 );
    202203    *(int*)accumulated_status |= tr_torrentCanManualUpdate( tor );
     
    204205
    205206static void
    206 refreshTorrentActions( GtkTreeSelection * s )
     207refreshTorrentActions( struct cbdata * data )
    207208{
    208209    int                canUpdate;
    209210    struct counts_data counts;
     211    GtkTreeSelection * s = data->sel;
    210212
    211213    counts.activeCount = 0;
    212214    counts.inactiveCount = 0;
    213215    counts.totalCount = 0;
    214     gtk_tree_selection_selected_foreach( s, accumulateStatusForeach,
    215                                          &counts );
     216    gtk_tree_selection_selected_foreach( s, accumulateStatusForeach, &counts );
    216217    action_sensitize( "pause-torrent", counts.activeCount != 0 );
    217218    action_sensitize( "start-torrent", counts.inactiveCount != 0 );
     
    223224
    224225    canUpdate = 0;
    225     gtk_tree_selection_selected_foreach( s, accumulateCanUpdateForeach,
    226                                          &canUpdate );
     226    gtk_tree_selection_selected_foreach( s, accumulateCanUpdateForeach, &canUpdate );
    227227    action_sensitize( "update-tracker", canUpdate != 0 );
    228228
     
    230230        GtkTreeView *  view = gtk_tree_selection_get_tree_view( s );
    231231        GtkTreeModel * model = gtk_tree_view_get_model( view );
    232         const int      torrentCount = gtk_tree_model_iter_n_children( model,
    233                                                                       NULL )
    234                                       != 0;
     232        const int  torrentCount = gtk_tree_model_iter_n_children( model, NULL ) != 0;
    235233        action_sensitize( "select-all", torrentCount != 0 );
    236234        action_sensitize( "deselect-all", torrentCount != 0 );
    237235    }
    238 }
    239 
    240 static void
    241 selectionChangedCB( GtkTreeSelection * s,
    242                     gpointer unused    UNUSED )
    243 {
    244     refreshTorrentActions( s );
     236
     237    {
     238        tr_torrent * tor = NULL;
     239        tr_session * session = tr_core_session( data->core );
     240        int activeCount = 0;
     241        while(( tor = tr_torrentNext( session, tor )))
     242            if( TR_STATUS_IS_ACTIVE( tr_torrentGetActivity( tor )))
     243                ++activeCount;
     244        action_sensitize( "pause-all-torrents", activeCount != 0 );
     245    }
     246}
     247
     248static void
     249selectionChangedCB( GtkTreeSelection * s UNUSED, gpointer data )
     250{
     251    refreshTorrentActions( data );
    245252}
    246253
     
    703710static void
    704711rowChangedCB( GtkTreeModel  * model UNUSED,
    705               GtkTreePath *        path,
     712              GtkTreePath   * path,
    706713              GtkTreeIter   * iter  UNUSED,
    707               gpointer              sel )
    708 {
    709     if( gtk_tree_selection_path_is_selected ( sel, path ) )
    710         refreshTorrentActions( GTK_TREE_SELECTION( sel ) );
     714              gpointer        gdata )
     715{
     716    struct cbdata * data = gdata;
     717    if( gtk_tree_selection_path_is_selected ( data->sel, path ) )
     718        refreshTorrentActions( gdata );
    711719}
    712720
     
    720728    g_assert( NULL == cbdata->wind );
    721729    cbdata->wind = GTK_WINDOW( wind );
    722 
    723     sel = tr_window_get_selection( cbdata->wind );
    724     g_signal_connect( sel, "changed", G_CALLBACK(
    725                           selectionChangedCB ), NULL );
    726     selectionChangedCB( sel, NULL );
     730    cbdata->sel = sel = GTK_TREE_SELECTION( tr_window_get_selection( cbdata->wind ) );
     731
     732    g_signal_connect( sel, "changed", G_CALLBACK( selectionChangedCB ), cbdata );
     733    selectionChangedCB( sel, cbdata );
    727734    model = tr_core_model( cbdata->core );
    728     g_signal_connect( model, "row-changed", G_CALLBACK( rowChangedCB ), sel );
     735    g_signal_connect( model, "row-changed", G_CALLBACK( rowChangedCB ), cbdata );
    729736    g_signal_connect( wind, "delete-event", G_CALLBACK( winclose ), cbdata );
    730     refreshTorrentActions( sel );
     737    refreshTorrentActions( cbdata );
    731738
    732739    setupdrag( GTK_WIDGET( wind ), cbdata );
     
    11881195
    11891196        /* update the actions */
    1190         refreshTorrentActions( tr_window_get_selection( data->wind ) );
     1197        refreshTorrentActions( data );
    11911198    }
    11921199
     
    13811388}
    13821389
     1390static void
     1391pauseAllTorrents( struct cbdata * data )
     1392{
     1393    tr_session * session = tr_core_session( data->core );
     1394    const char * cmd = "{ \"method\": \"torrent-stop\" }";
     1395    char * response = tr_rpc_request_exec_json( session, cmd, strlen( cmd ), NULL );
     1396    tr_free( response );
     1397}
     1398
    13831399void
    1384 doAction( const char * action_name,
    1385           gpointer     user_data )
     1400doAction( const char * action_name, gpointer user_data )
    13861401{
    13871402    struct cbdata * data = user_data;
    13881403    gboolean        changed = FALSE;
    13891404
    1390     if( !strcmp ( action_name, "add-torrent-menu" )
     1405    if(  !strcmp( action_name, "add-torrent-menu" )
    13911406      || !strcmp( action_name, "add-torrent-toolbar" ) )
    13921407    {
    13931408        addDialog( data->wind, data->core );
    13941409    }
    1395     else if( !strcmp ( action_name, "show-stats" ) )
    1396     {
    1397         GtkWidget * dialog = stats_dialog_create( data->wind,
    1398                                                   data->core );
     1410    else if( !strcmp( action_name, "show-stats" ) )
     1411    {
     1412        GtkWidget * dialog = stats_dialog_create( data->wind, data->core );
    13991413        gtk_widget_show( dialog );
    14001414    }
    1401     else if( !strcmp ( action_name, "start-torrent" ) )
     1415    else if( !strcmp( action_name, "start-torrent" ) )
    14021416    {
    14031417        GtkTreeSelection * s = tr_window_get_selection( data->wind );
     
    14051419        changed |= gtk_tree_selection_count_selected_rows( s ) != 0;
    14061420    }
    1407     else if( !strcmp ( action_name, "pause-torrent" ) )
     1421    else if( !strcmp( action_name, "pause-all-torrents" ) )
     1422    {
     1423        pauseAllTorrents( data );
     1424    }
     1425    else if( !strcmp( action_name, "pause-torrent" ) )
    14081426    {
    14091427        GtkTreeSelection * s = tr_window_get_selection( data->wind );
     
    14111429        changed |= gtk_tree_selection_count_selected_rows( s ) != 0;
    14121430    }
    1413     else if( !strcmp ( action_name, "verify-torrent" ) )
     1431    else if( !strcmp( action_name, "verify-torrent" ) )
    14141432    {
    14151433        GtkTreeSelection * s = tr_window_get_selection( data->wind );
     
    14171435        changed |= gtk_tree_selection_count_selected_rows( s ) != 0;
    14181436    }
    1419     else if( !strcmp ( action_name, "open-torrent-folder" ) )
     1437    else if( !strcmp( action_name, "open-torrent-folder" ) )
    14201438    {
    14211439        GtkTreeSelection * s = tr_window_get_selection( data->wind );
    14221440        gtk_tree_selection_selected_foreach( s, openFolderForeach, data );
    14231441    }
    1424     else if( !strcmp ( action_name, "show-torrent-properties" ) )
     1442    else if( !strcmp( action_name, "show-torrent-properties" ) )
    14251443    {
    14261444        GtkTreeSelection * s = tr_window_get_selection( data->wind );
     
    14331451                                             data->wind );
    14341452    }
    1435     else if( !strcmp ( action_name, "new-torrent" ) )
     1453    else if( !strcmp( action_name, "new-torrent" ) )
    14361454    {
    14371455        GtkWidget * w = make_meta_ui( GTK_WINDOW( data->wind ),
     
    14471465        removeSelected( data, TRUE );
    14481466    }
    1449     else if( !strcmp ( action_name, "quit" ) )
     1467    else if( !strcmp( action_name, "quit" ) )
    14501468    {
    14511469        askquit( data->core, data->wind, wannaquit, data );
    14521470    }
    1453     else if( !strcmp ( action_name, "select-all" ) )
     1471    else if( !strcmp( action_name, "select-all" ) )
    14541472    {
    14551473        GtkTreeSelection * s = tr_window_get_selection( data->wind );
    14561474        gtk_tree_selection_select_all( s );
    14571475    }
    1458     else if( !strcmp ( action_name, "deselect-all" ) )
     1476    else if( !strcmp( action_name, "deselect-all" ) )
    14591477    {
    14601478        GtkTreeSelection * s = tr_window_get_selection( data->wind );
    14611479        gtk_tree_selection_unselect_all( s );
    14621480    }
    1463     else if( !strcmp ( action_name, "edit-preferences" ) )
     1481    else if( !strcmp( action_name, "edit-preferences" ) )
    14641482    {
    14651483        if( NULL == data->prefs )
     
    14721490        }
    14731491    }
    1474     else if( !strcmp ( action_name, "toggle-message-log" ) )
     1492    else if( !strcmp( action_name, "toggle-message-log" ) )
    14751493    {
    14761494        if( !data->msgwin )
     
    14881506        }
    14891507    }
    1490     else if( !strcmp ( action_name, "show-about-dialog" ) )
     1508    else if( !strcmp( action_name, "show-about-dialog" ) )
    14911509    {
    14921510        about( data->wind );
     
    14981516        g_free( url );
    14991517    }
    1500     else if( !strcmp ( action_name, "toggle-main-window" ) )
     1518    else if( !strcmp( action_name, "toggle-main-window" ) )
    15011519    {
    15021520        toggleMainWindow( data, FALSE );
    15031521    }
    1504     else if( !strcmp ( action_name, "present-main-window" ) )
     1522    else if( !strcmp( action_name, "present-main-window" ) )
    15051523    {
    15061524        toggleMainWindow( data, TRUE );
Note: See TracChangeset for help on using the changeset viewer.