Changeset 2469


Ignore:
Timestamp:
Jul 23, 2007, 9:01:26 PM (16 years ago)
Author:
charles
Message:

torrent filter counts work now.

Location:
trunk/wx
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wx/Makefile.am

    r2465 r2469  
    55bin_PROGRAMS = Xmission
    66
    7 Xmission_SOURCES = xmission.cc torrent-list.cc
     7Xmission_SOURCES = \
     8    xmission.cc \
     9    torrent-filter.cc \
     10    torrent-list.cc
    811
    912Xmission_LDADD = ../libtransmission/libtransmission.a @WX_LIBS@ $(PTHREAD_LIBS) -lm
  • trunk/wx/torrent-list.cc

    r2466 r2469  
    166166
    167167BEGIN_EVENT_TABLE(TorrentListCtrl, wxListCtrl)
    168     EVT_LIST_COL_CLICK(TORRENT_LIST_CTRL, TorrentListCtrl::OnSort)
     168    EVT_LIST_COL_CLICK( TORRENT_LIST_CTRL, TorrentListCtrl::OnSort )
     169    EVT_LIST_ITEM_SELECTED( TORRENT_LIST_CTRL, TorrentListCtrl::OnItemSelected )
     170    EVT_LIST_ITEM_DESELECTED( TORRENT_LIST_CTRL, TorrentListCtrl::OnItemDeselected )
    169171END_EVENT_TABLE()
    170172
     
    174176                                    const wxPoint     & pos,
    175177                                    const wxSize      & size):
    176     wxListCtrl( parent, TORRENT_LIST_CTRL, pos, size, wxLC_REPORT|wxLC_SINGLE_SEL ),
     178    wxListCtrl( parent, TORRENT_LIST_CTRL, pos, size, wxLC_REPORT ),
    177179    myHandle( handle ),
    178180    myConfig( config )
     
    318320}
    319321
     322/***
     323****
     324***/
     325
     326void
     327TorrentListCtrl :: OnSort( wxListEvent& event )
     328{
     329    const int_v  cols = getTorrentColumns( myConfig );
     330    const int key = cols[ event.GetColumn() ];
     331    Sort( key );
     332}
     333
     334void
     335TorrentListCtrl :: OnItemSelected( wxListEvent& event )
     336{
     337    std::set<tr_torrent_t*> sel;
     338    long item = -1;
     339    for ( ;; ) {
     340        item = GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
     341        if ( item == -1 )
     342            break;
     343        sel.insert( myTorrents[GetItemData(item)] );
     344    }
     345    fire_selection_changed( sel );
     346}
     347
     348void
     349TorrentListCtrl :: OnItemDeselected( wxListEvent& event )
     350{
     351    OnItemSelected( event );
     352}
     353
     354/***
     355****
     356***/
     357
    320358static torrents_t * uglyHack = NULL;
    321359
     
    414452
    415453    return ret;
    416 }
    417 
    418 void
    419 TorrentListCtrl :: OnSort( wxListEvent& event )
    420 {
    421     const int_v  cols = getTorrentColumns( myConfig );
    422     const int key = cols[ event.GetColumn() ];
    423     Sort( key );
    424454}
    425455
     
    453483    uglyHack = NULL;
    454484}
     485
     486/***
     487****
     488***/
    455489
    456490void
  • trunk/wx/torrent-list.h

    r2465 r2469  
    3030
    3131    public:
     32
     33        enum ShowMode
     34        {
     35            SHOW_ALL,
     36            SHOW_DOWNLOADING,
     37            SHOW_UPLOADING,
     38            SHOW_COMPLETE,
     39            SHOW_INCOMPLETE,
     40            SHOW_ACTIVE,
     41            SHOW_INACTIVE,
     42            N_FILTERS
     43        };
     44
     45        void SetShowMode( ShowMode );
     46
     47        int GetShowModeCounts( ShowMode ) const;
     48
     49    public:
     50
     51        struct Listener
     52        {
     53            Listener() {}
     54
     55            virtual ~Listener() {}
     56
     57            virtual void OnTorrentListSelectionChanged(
     58                TorrentListCtrl*,
     59                const std::set<tr_torrent_t*>& ) = 0;
     60        };
     61
     62    private:
     63        typedef std::set<Listener*> listeners_t;
     64        listeners_t myListeners;
     65        void fire_selection_changed( const std::set<tr_torrent_t*>& t ) {
     66            for( listeners_t::iterator it(myListeners.begin()), end(myListeners.end()); it!=end; )
     67                (*it++)->OnTorrentListSelectionChanged( this, t );
     68        }
     69    public:
     70        void AddListener( Listener* l ) { myListeners.insert(l); }
     71        void RemoveListener( Listener* l ) { myListeners.erase(l); }
     72
     73    public:
    3274        void Rebuild ();
    3375        void Repopulate ();
     
    4183        void Sort( int column );
    4284        void Resort( );
    43         void OnSort( wxListEvent& );
    4485        void RefreshTorrent( tr_torrent_t*, int, const std::vector<int>& );
    4586        static int Compare( long, long, long );
     
    4889        typedef std::map<std::string,int> str2int_t;
    4990        str2int_t myHashToRow;
     91
     92    private:
     93        void OnSort( wxListEvent& );
     94        void OnItemSelected( wxListEvent& );
     95        void OnItemDeselected( wxListEvent& );
    5096
    5197    private:
  • trunk/wx/xmission.cc

    r2468 r2469  
    2020#include <wx/config.h>
    2121#include <wx/image.h>
     22#include <wx/intl.h>
    2223#include <wx/listctrl.h>
    2324#include <wx/notebook.h>
     
    4344}
    4445
     46#include "torrent-filter.h"
    4547#include "torrent-list.h"
    4648
     
    5658    tr_handle_t * handle = NULL;
    5759
    58     typedef std::vector<tr_torrent_t*> torrents_t;
     60    typedef std::vector<tr_torrent_t*> torrents_v;
    5961}
    6062
     
    6466    MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
    6567    virtual ~MyFrame();
     68
     69public:
    6670    void OnQuit( wxCommandEvent& );
    6771    void OnAbout( wxCommandEvent& );
     
    6973    void OnTimer( wxTimerEvent& );
    7074
     75private:
     76    void RefreshFilterCounts( );
     77
    7178protected:
    7279    wxConfig * myConfig;
     
    7582private:
    7683    TorrentListCtrl * myTorrentList;
     84    wxListCtrl * myFilters;
    7785    wxTaskBarIcon * myTaskBarIcon;
    7886    wxIcon * myLogoIcon;
    7987    wxIcon * myTrayLogo;
     88    torrents_v myTorrents;
    8089};
    8190
     
    181190
    182191void
     192MyFrame :: RefreshFilterCounts( )
     193{
     194    for( int i=0; i<TorrentFilter::N_FILTERS; ++i )
     195    {
     196        wxString xstr = TorrentFilter::getFilterName( i );
     197        const int count = TorrentFilter::CountHits( i, myTorrents );
     198        if( count )
     199            xstr += wxString::Format(_T(" (%d)"), count );
     200        myFilters->SetItem( i, 0, xstr );
     201    }
     202}
     203
     204void
    183205MyFrame :: OnTimer(wxTimerEvent& event)
    184206{
    185     myTorrentList->Refresh ();
     207    RefreshFilterCounts( );
     208
     209    myTorrentList->Refresh ( );
    186210
    187211    float dl, ul;
     
    287311    /* Filters */
    288312
    289     wxListCtrl * filters = new wxListCtrl( row1, wxID_ANY, wxDefaultPosition, wxDefaultSize,
    290                                            wxLC_REPORT|wxLC_SINGLE_SEL|wxLC_NO_HEADER );
    291     filters->InsertColumn( wxLIST_FORMAT_LEFT, _T("YYZ") );
    292     int i = 0;
    293     filters->InsertItem( i++, _T("All") );
    294     filters->InsertItem( i++, _T("Downloading (1)") );
    295     filters->InsertItem( i++, _T("Completed") );
    296     filters->InsertItem( i++, _T("Active (1)") );
    297     filters->InsertItem( i++, _T("Inactive") );
     313    myFilters = new wxListCtrl( row1, wxID_ANY, wxDefaultPosition, wxSize(120,-1),
     314                                wxLC_REPORT|wxLC_SINGLE_SEL|wxLC_NO_HEADER );
     315    myFilters->InsertColumn( wxLIST_FORMAT_LEFT, _("Filters"), wxLIST_FORMAT_LEFT, 120 );
     316    for( int i=0; i<TorrentFilter::N_FILTERS; ++i )
     317        myFilters->InsertItem( i, TorrentFilter::getFilterName(i) );
    298318
    299319    /* Torrent List */
     
    302322
    303323    wxBoxSizer * boxSizer = new wxBoxSizer( wxHORIZONTAL );
    304     boxSizer->Add( filters, 0, wxEXPAND|wxRIGHT, 5 );
     324    boxSizer->Add( myFilters, 0, wxEXPAND|wxRIGHT, 5 );
    305325    boxSizer->Add( myTorrentList, 1, wxEXPAND, 0 );
    306326    row1->SetSizer( boxSizer );
     327    //boxSizer->SetSizeHints( row1 );
    307328
    308329
     
    344365    int count = 0;
    345366    tr_torrent_t ** torrents = tr_loadTorrents ( handle, destination, flags, &count );
    346     myTorrentList->Add( std::vector<tr_torrent_t*>( torrents, torrents+count ) );
     367    myTorrents.insert( myTorrents.end(), torrents, torrents+count );
     368    myTorrentList->Add( myTorrents );
    347369    tr_free( torrents );
    348370}
Note: See TracChangeset for help on using the changeset viewer.