Changeset 7252


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

Location:
trunk/gtk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/actions.c

    r7106 r7252  
    109109static GtkActionEntry        entries[] =
    110110{
    111     { "torrent-menu",         NULL,                           N_(
    112           "_Torrent" ),
    113       NULL,            NULL,                   NULL                    },
    114     { "view-menu",            NULL,                  N_( "_View" ),
    115       NULL,            NULL,                   NULL                    },
    116     { "sort-menu",            NULL,                  N_(
    117           "_Sort Torrents By" ),        NULL,            NULL,
    118       NULL                    },
    119     { "edit-menu",            NULL,                  N_( "_Edit" ),
    120       NULL,            NULL,                   NULL                    },
    121     { "help-menu",            NULL,                  N_( "_Help" ),
    122       NULL,            NULL,                   NULL                    },
    123     { "add-torrent-toolbar",  GTK_STOCK_ADD,         NULL,
    124       NULL,            N_( "Add a torrent" ),  G_CALLBACK( action_cb ) },
    125     { "add-torrent-menu",     GTK_STOCK_ADD,         N_( "_Add..." ),
    126       "<control>D",    N_( "Add a torrent" ),  G_CALLBACK( action_cb ) },
    127     { "start-torrent",        GTK_STOCK_MEDIA_PLAY,
    128       N_( "_Start" ), "<control>S", N_( "Start torrent" ), G_CALLBACK(
    129           action_cb ) },
    130     { "show-stats",           NULL,                  N_( "_Statistics" ),
    131       NULL,            NULL,                   G_CALLBACK( action_cb ) },
    132     { "verify-torrent",       NULL,
    133       N_( "_Verify Local Data" ), NULL, NULL, G_CALLBACK( action_cb ) },
    134     { "pause-torrent",        GTK_STOCK_MEDIA_PAUSE,
    135       N_( "_Pause" ), "<control>P", N_( "Pause torrent" ), G_CALLBACK(
    136           action_cb ) },
    137     { "remove-torrent",       GTK_STOCK_REMOVE,      NULL,
    138       "Delete",        N_( "Remove torrent" ), G_CALLBACK( action_cb ) },
    139     { "delete-torrent",       GTK_STOCK_DELETE,      N_(
    140           "_Delete Files and Remove" ), "<shift>Delete", NULL,
    141       G_CALLBACK( action_cb ) },
    142     { "new-torrent",          GTK_STOCK_NEW,         N_( "_New..." ),
    143       NULL,
    144       N_( "Create a torrent" ),
    145       G_CALLBACK( action_cb ) },
    146     { "quit",                 GTK_STOCK_QUIT,        N_( "_Quit" ),
    147       NULL,            NULL,                   G_CALLBACK( action_cb ) },
    148     { "select-all",           GTK_STOCK_SELECT_ALL,
    149       N_( "Select _All" ), "<control>A", NULL, G_CALLBACK( action_cb ) },
    150     { "deselect-all",         NULL,
    151       N_( "Dese_lect All" ), "<shift><control>A", NULL, G_CALLBACK(
    152           action_cb ) },
    153     { "edit-preferences",     GTK_STOCK_PREFERENCES, NULL,
    154       NULL,            NULL,                   G_CALLBACK( action_cb ) },
    155     { "show-torrent-properties", GTK_STOCK_PROPERTIES,
    156       NULL, "<alt>Return", N_( "Torrent properties" ), G_CALLBACK( action_cb ) },
    157     { "open-torrent-folder",  GTK_STOCK_OPEN,
    158       N_( "_Open Folder" ), NULL, NULL, G_CALLBACK( action_cb ) },
    159     { "show-about-dialog",    GTK_STOCK_ABOUT,       NULL,
    160       NULL,            NULL,                   G_CALLBACK( action_cb ) },
    161     { "help",                 GTK_STOCK_HELP,        N_( "_Contents" ),
    162       "F1",            NULL,                   G_CALLBACK( action_cb ) },
    163     { "update-tracker",       GTK_STOCK_NETWORK,
    164       N_( "Ask Tracker for _More Peers" ), NULL, NULL, G_CALLBACK(
    165           action_cb ) },
    166     { "present-main-window",  NULL,                  NULL,
    167       NULL,            NULL,                   G_CALLBACK( action_cb ) },
     111    { "torrent-menu", NULL, N_( "_Torrent" ), NULL, NULL, NULL  },
     112    { "view-menu", NULL, N_( "_View" ), NULL, NULL, NULL  },
     113    { "sort-menu", NULL, N_( "_Sort Torrents By" ), NULL, NULL, NULL },
     114    { "edit-menu", NULL, N_( "_Edit" ), NULL, NULL, NULL },
     115    { "help-menu", NULL, N_( "_Help" ), NULL, NULL, NULL },
     116    { "add-torrent-toolbar",  GTK_STOCK_ADD, NULL, NULL, N_( "Add a torrent" ),  G_CALLBACK( action_cb ) },
     117    { "add-torrent-menu", GTK_STOCK_ADD, N_( "_Add..." ), "<control>D", N_( "Add a torrent" ), G_CALLBACK( action_cb ) },
     118    { "start-torrent", GTK_STOCK_MEDIA_PLAY, N_( "_Start" ), "<control>S", N_( "Start torrent" ), G_CALLBACK( action_cb ) },
     119    { "show-stats", NULL, N_( "_Statistics" ), NULL, NULL, G_CALLBACK( action_cb ) },
     120    { "verify-torrent", NULL, N_( "_Verify Local Data" ), NULL, NULL, G_CALLBACK( action_cb ) },
     121    { "pause-torrent", GTK_STOCK_MEDIA_PAUSE, N_( "_Pause" ), "<control>P", N_( "Pause torrent" ), G_CALLBACK( action_cb ) },
     122    { "pause-all-torrents", GTK_STOCK_MEDIA_PAUSE, N_( "_Pause All" ), NULL, N_( "Pause all torrents" ), G_CALLBACK( action_cb ) },
     123    { "remove-torrent", GTK_STOCK_REMOVE, NULL, "Delete", N_( "Remove torrent" ), G_CALLBACK( action_cb ) },
     124    { "delete-torrent", GTK_STOCK_DELETE, N_( "_Delete Files and Remove" ), "<shift>Delete", NULL, G_CALLBACK( action_cb ) },
     125    { "new-torrent", GTK_STOCK_NEW, N_( "_New..." ), NULL, N_( "Create a torrent" ), G_CALLBACK( action_cb ) },
     126    { "quit", GTK_STOCK_QUIT, N_( "_Quit" ), NULL, NULL, G_CALLBACK( action_cb ) },
     127    { "select-all", GTK_STOCK_SELECT_ALL, N_( "Select _All" ), "<control>A", NULL, G_CALLBACK( action_cb ) },
     128    { "deselect-all", NULL, N_( "Dese_lect All" ), "<shift><control>A", NULL, G_CALLBACK( action_cb ) },
     129    { "edit-preferences", GTK_STOCK_PREFERENCES, NULL, NULL, NULL, G_CALLBACK( action_cb ) },
     130    { "show-torrent-properties", GTK_STOCK_PROPERTIES, NULL, "<alt>Return", N_( "Torrent properties" ), G_CALLBACK( action_cb ) },
     131    { "open-torrent-folder",  GTK_STOCK_OPEN, N_( "_Open Folder" ), NULL, NULL, G_CALLBACK( action_cb ) },
     132    { "show-about-dialog", GTK_STOCK_ABOUT, NULL, NULL, NULL, G_CALLBACK( action_cb ) },
     133    { "help", GTK_STOCK_HELP, N_( "_Contents" ), "F1", NULL, G_CALLBACK( action_cb ) },
     134    { "update-tracker", GTK_STOCK_NETWORK, N_( "Ask Tracker for _More Peers" ), NULL, NULL, G_CALLBACK( action_cb ) },
     135    { "present-main-window", NULL, NULL, NULL, NULL, G_CALLBACK( action_cb ) },
    168136};
    169137
  • 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 );
  • trunk/gtk/ui.h

    r7106 r7252  
    7979    "    <menuitem action='show-about-dialog'/>\n"
    8080    "    <separator/>\n"
     81    "    <menuitem action='pause-all-torrents'/>\n"
     82    "    <separator/>\n"
    8183    "    <menuitem action='quit'/>\n"
    8284    "  </popup>\n"
Note: See TracChangeset for help on using the changeset viewer.