Upstream tarball 9964
[amule.git] / src / SharedFilesWnd.cpp
blob914d9fd14c061c99bcb607257bed0e16dda87571
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002-2008 Merkur ( devs@emule-project.net / http://www.emule-project.net )
6 //
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
9 // respective authors.
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include <wx/gauge.h> // Do_not_auto_remove (win32)
29 #include "SharedFilesWnd.h" // Interface declarations
30 #include "SharedFilesCtrl.h"
31 #include "muuli_wdr.h" // Needed for ID_SHFILELIST
32 #include "KnownFileList.h" // Needed for CKnownFileList
33 #include "KnownFile.h" // Needed for CKnownFile
34 #include "amule.h" // Needed for theApp
38 BEGIN_EVENT_TABLE(CSharedFilesWnd, wxPanel)
39 EVT_LIST_ITEM_SELECTED( ID_SHFILELIST, CSharedFilesWnd::OnItemActivated )
40 EVT_BUTTON( ID_BTNRELSHARED, CSharedFilesWnd::OnBtnReloadShared )
41 END_EVENT_TABLE()
45 CSharedFilesWnd::CSharedFilesWnd( wxWindow* pParent )
46 : wxPanel(pParent, -1)
48 wxSizer* content = sharedfilesDlg(this, true);
49 content->Show(this, true);
51 m_bar_requests = CastChild( wxT("popbar"), wxGauge );
52 m_bar_accepted = CastChild( wxT("popbarAccept"), wxGauge );
53 m_bar_transfer = CastChild( wxT("popbarTrans"), wxGauge );
54 sharedfilesctrl = CastChild( wxT("sharedFilesCt"), CSharedFilesCtrl );
55 wxASSERT(sharedfilesctrl);
59 CSharedFilesWnd::~CSharedFilesWnd()
64 void CSharedFilesWnd::SelectionUpdated()
66 uint64 lTransferred = theApp->knownfiles->transferred;
67 uint32 lAccepted = theApp->knownfiles->accepted;
68 uint32 lRequested = theApp->knownfiles->requested;
69 m_bar_requests->SetRange( lRequested );
70 m_bar_accepted->SetRange( lAccepted );
71 m_bar_transfer->SetRange( lTransferred / 1024 );
73 if ( !sharedfilesctrl->GetSelectedItemCount() ) {
74 // Requests
75 m_bar_requests->SetValue( 0 );
76 CastChild(IDC_SREQUESTED, wxStaticText)->SetLabel( wxT("-") );
77 CastChild(IDC_SREQUESTED2, wxStaticText)->SetLabel( wxT("-") );
79 // Accepted requets
80 m_bar_accepted->SetValue( 0 );
81 CastChild(IDC_SACCEPTED, wxStaticText)->SetLabel( wxT("-") );
82 CastChild(IDC_SACCEPTED2, wxStaticText)->SetLabel( wxT("-") );
84 // Transferred
85 m_bar_transfer->SetValue( 0 );
86 CastChild(IDC_STRANSFERRED, wxStaticText)->SetLabel( wxT("-") );
87 CastChild(IDC_STRANSFERRED2, wxStaticText)->SetLabel( wxT("-") );
88 } else {
89 // Create a total statistic for the selected item(s)
90 uint32 session_requests = 0;
91 uint32 session_accepted = 0;
92 uint64 session_transferred = 0;
93 uint32 all_requests = 0;
94 uint32 all_accepted = 0;
95 uint64 all_transferred = 0;
97 long index = sharedfilesctrl->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
98 while ( index > -1 ) {
99 if ( sharedfilesctrl->GetItemState( index, wxLIST_STATE_SELECTED ) ) {
100 CKnownFile* file = (CKnownFile*)sharedfilesctrl->GetItemData( index );
102 session_requests += file->statistic.GetRequests();
103 session_accepted += file->statistic.GetAccepts();
104 session_transferred += file->statistic.GetTransferred();
106 all_requests += file->statistic.GetAllTimeRequests();
107 all_accepted += file->statistic.GetAllTimeAccepts();
108 all_transferred += file->statistic.GetAllTimeTransferred();
110 index = sharedfilesctrl->GetNextItem( index, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
113 // Requests
114 session_requests = session_requests > lRequested ? lRequested : session_requests;
115 m_bar_requests->SetValue( session_requests );
116 CastChild(IDC_SREQUESTED, wxStaticText)->SetLabel( wxString::Format(wxT("%u"), session_requests ) );
117 CastChild(IDC_SREQUESTED2, wxStaticText)->SetLabel( wxString::Format(wxT("%u"), all_requests ) );
119 // Accepted requets
120 session_accepted = session_accepted > lAccepted ? lAccepted : session_accepted;
121 m_bar_accepted->SetValue( session_accepted );
122 CastChild(IDC_SACCEPTED, wxStaticText)->SetLabel( wxString::Format(wxT("%u"), session_accepted ) );
123 CastChild(IDC_SACCEPTED2, wxStaticText)->SetLabel( wxString::Format(wxT("%u"), all_accepted ) );
125 // Transferred
126 session_transferred = session_transferred > lTransferred ? lTransferred : session_transferred;
127 m_bar_transfer->SetValue( session_transferred / 1024 );
128 CastChild(IDC_STRANSFERRED, wxStaticText)->SetLabel( CastItoXBytes( session_transferred ) );
129 CastChild(IDC_STRANSFERRED2, wxStaticText)->SetLabel( CastItoXBytes( all_transferred ) );
131 Layout();
135 void CSharedFilesWnd::OnBtnReloadShared( wxCommandEvent& WXUNUSED(evt) )
137 theApp->sharedfiles->Reload();
138 #ifndef CLIENT_GUI
139 // remote gui will update display when data is back
140 SelectionUpdated();
141 #endif
145 void CSharedFilesWnd::OnItemActivated(wxListEvent& evt)
147 SelectionUpdated();
149 evt.Skip();
153 void CSharedFilesWnd::RemoveAllSharedFiles() {
154 sharedfilesctrl->DeleteAllItems();
155 sharedfilesctrl->ShowFilesCount();
156 SelectionUpdated();
158 // File_checked_for_headers