2 // This file is part of the aMule Project.
4 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002 Merkur ( devs@emule-project.net / http://www.emule-project.net )
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
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.
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
26 #include <protocol/ed2k/ClientSoftware.h>
27 #include <common/MenuIDs.h>
29 #include <common/Format.h> // Needed for CFormat
30 #include "amule.h" // Needed for theApp
31 #include "amuleDlg.h" // Needed for CamuleDlg
32 #include "BarShader.h" // Needed for CBarShader
33 #include "ClientDetailDialog.h" // Needed for CClientDetailDialog
34 #include "ChatWnd.h" // Needed for CChatWnd
35 #include "CommentDialogLst.h" // Needed for CCommentDialogLst
36 #include "DownloadListCtrl.h" // Interface declarations
37 #include "DataToText.h" // Needed for PriorityToStr
38 #include "FileDetailDialog.h" // Needed for CFileDetailDialog
39 #include "GuiEvents.h" // Needed for CoreNotify_*
40 #ifdef ENABLE_IP2COUNTRY
41 #include "IP2Country.h" // Needed for IP2Country
44 #include "muuli_wdr.h" // Needed for ID_DLOADLIST
45 #include "PartFile.h" // Needed for CPartFile
46 #include "Preferences.h"
47 #include "SharedFileList.h" // Needed for CSharedFileList
48 #include "TerminationProcess.h" // Needed for CTerminationProcess
49 #include "updownclient.h" // Needed for CUpDownClient
55 struct CtrlItem_Struct
70 DownloadItemType
GetType() const {
74 CPartFile
* GetOwner() const {
78 CPartFile
* GetFile() const {
82 CUpDownClient
* GetSource() const {
86 void SetContents(CPartFile
* file
) {
94 void SetContents(CPartFile
* owner
, CUpDownClient
* source
, DownloadItemType type
) {
95 wxCHECK_RET(type
!= FILE_TYPE
, wxT("Invalid type, not a source"));
99 m_sourceValue
= source
;
109 CPartFile
* m_fileValue
;
110 CUpDownClient
* m_sourceValue
;
111 DownloadItemType m_type
;
116 #define m_ImageList theApp->amuledlg->m_imagelist
119 BEGIN_EVENT_TABLE(CDownloadListCtrl
, CMuleListCtrl
)
120 EVT_LIST_ITEM_ACTIVATED(ID_DLOADLIST
, CDownloadListCtrl::OnItemActivated
)
121 EVT_LIST_ITEM_RIGHT_CLICK(ID_DLOADLIST
, CDownloadListCtrl::OnMouseRightClick
)
122 EVT_LIST_ITEM_MIDDLE_CLICK(ID_DLOADLIST
, CDownloadListCtrl::OnMouseMiddleClick
)
124 EVT_CHAR( CDownloadListCtrl::OnKeyPressed
)
126 EVT_MENU( MP_CANCEL
, CDownloadListCtrl::OnCancelFile
)
128 EVT_MENU( MP_PAUSE
, CDownloadListCtrl::OnSetStatus
)
129 EVT_MENU( MP_STOP
, CDownloadListCtrl::OnSetStatus
)
130 EVT_MENU( MP_RESUME
, CDownloadListCtrl::OnSetStatus
)
132 EVT_MENU( MP_PRIOLOW
, CDownloadListCtrl::OnSetPriority
)
133 EVT_MENU( MP_PRIONORMAL
, CDownloadListCtrl::OnSetPriority
)
134 EVT_MENU( MP_PRIOHIGH
, CDownloadListCtrl::OnSetPriority
)
135 EVT_MENU( MP_PRIOAUTO
, CDownloadListCtrl::OnSetPriority
)
137 EVT_MENU( MP_SWAP_A4AF_TO_THIS
, CDownloadListCtrl::OnSwapSources
)
138 EVT_MENU( MP_SWAP_A4AF_TO_THIS_AUTO
, CDownloadListCtrl::OnSwapSources
)
139 EVT_MENU( MP_SWAP_A4AF_TO_ANY_OTHER
, CDownloadListCtrl::OnSwapSources
)
141 EVT_MENU_RANGE( MP_ASSIGNCAT
, MP_ASSIGNCAT
+ 99, CDownloadListCtrl::OnSetCategory
)
143 EVT_MENU( MP_CLEARCOMPLETED
, CDownloadListCtrl::OnClearCompleted
)
145 EVT_MENU( MP_GETMAGNETLINK
, CDownloadListCtrl::OnGetLink
)
146 EVT_MENU( MP_GETED2KLINK
, CDownloadListCtrl::OnGetLink
)
148 EVT_MENU( MP_METINFO
, CDownloadListCtrl::OnViewFileInfo
)
149 EVT_MENU( MP_VIEW
, CDownloadListCtrl::OnPreviewFile
)
150 EVT_MENU( MP_VIEWFILECOMMENTS
, CDownloadListCtrl::OnViewFileComments
)
152 EVT_MENU( MP_WS
, CDownloadListCtrl::OnGetFeedback
)
153 EVT_MENU( MP_RAZORSTATS
, CDownloadListCtrl::OnGetRazorStats
)
155 EVT_MENU( MP_CHANGE2FILE
, CDownloadListCtrl::OnSwapSource
)
156 EVT_MENU( MP_SHOWLIST
, CDownloadListCtrl::OnViewFiles
)
157 EVT_MENU( MP_ADDFRIEND
, CDownloadListCtrl::OnAddFriend
)
158 EVT_MENU( MP_SENDMESSAGE
, CDownloadListCtrl::OnSendMessage
)
159 EVT_MENU( MP_DETAIL
, CDownloadListCtrl::OnViewClientInfo
)
164 //! This listtype is used when gathering the selected items.
165 typedef std::list
<CtrlItem_Struct
*> ItemList
;
169 CDownloadListCtrl::CDownloadListCtrl(
170 wxWindow
*parent
, wxWindowID winid
, const wxPoint
& pos
, const wxSize
& size
,
171 long style
, const wxValidator
& validator
, const wxString
& name
)
173 CMuleListCtrl( parent
, winid
, pos
, size
, style
| wxLC_OWNERDRAW
, validator
, name
)
175 // Setting the sorter function.
176 SetSortFunc( SortProc
);
178 // Set the table-name (for loading and saving preferences).
179 SetTableName( wxT("Download") );
183 wxColour colour
= BLEND( SYSCOLOR( wxSYS_COLOUR_HIGHLIGHT
), 125 );
184 m_hilightBrush
= new wxBrush( colour
, wxSOLID
);
186 colour
= BLEND( SYSCOLOR( wxSYS_COLOUR_BTNSHADOW
), 125 );
187 m_hilightUnfocusBrush
= new wxBrush( colour
, wxSOLID
);
189 InsertColumn( 0, _("File Name"), wxLIST_FORMAT_LEFT
, 260 );
190 InsertColumn( 1, _("Size"), wxLIST_FORMAT_LEFT
, 60 );
191 InsertColumn( 2, _("Transferred"), wxLIST_FORMAT_LEFT
, 65 );
192 InsertColumn( 3, _("Completed"), wxLIST_FORMAT_LEFT
, 65 );
193 InsertColumn( 4, _("Speed"), wxLIST_FORMAT_LEFT
, 65 );
194 InsertColumn( 5, _("Progress"), wxLIST_FORMAT_LEFT
, 170 );
195 InsertColumn( 6, _("Sources"), wxLIST_FORMAT_LEFT
, 50 );
196 InsertColumn( 7, _("Priority"), wxLIST_FORMAT_LEFT
, 55 );
197 InsertColumn( 8, _("Status"), wxLIST_FORMAT_LEFT
, 70 );
198 InsertColumn( 9, _("Time Remaining"), wxLIST_FORMAT_LEFT
, 110 );
199 InsertColumn( 10, _("Last Seen Complete"), wxLIST_FORMAT_LEFT
, 220 );
200 InsertColumn( 11, _("Last Reception"), wxLIST_FORMAT_LEFT
, 220 );
203 m_completedFiles
= 0;
209 CDownloadListCtrl::~CDownloadListCtrl()
211 while ( !m_ListItems
.empty() ) {
212 delete m_ListItems
.begin()->second
;
213 m_ListItems
.erase( m_ListItems
.begin() );
215 delete m_hilightBrush
;
216 delete m_hilightUnfocusBrush
;
220 void CDownloadListCtrl::AddFile( CPartFile
* file
)
224 // Avoid duplicate entries of files
225 if ( m_ListItems
.find( file
) == m_ListItems
.end() ) {
226 CtrlItem_Struct
* newitem
= new CtrlItem_Struct
;
227 newitem
->SetContents(file
);
229 m_ListItems
.insert( ListItemsPair( file
, newitem
) );
231 // Check if the new file is visible in the current category
232 if ( file
->CheckShowItemInGivenCat( m_category
) ) {
233 ShowFile( file
, true );
239 void CDownloadListCtrl::AddSource(CPartFile
* owner
, CUpDownClient
* source
, DownloadItemType type
)
241 wxCHECK_RET(owner
, wxT("NULL owner in CDownloadListCtrl::AddSource"));
242 wxCHECK_RET(source
, wxT("NULL source in CDownloadListCtrl::AddSource"));
243 wxCHECK_RET(type
!= FILE_TYPE
, wxT("Invalid type, not a source"));
245 // Update the other instances of this source
247 ListIteratorPair rangeIt
= m_ListItems
.equal_range(source
);
248 for ( ListItems::iterator it
= rangeIt
.first
; it
!= rangeIt
.second
; ++it
) {
249 CtrlItem_Struct
* cur_item
= it
->second
;
251 // Check if this source has been already added to this file => to be sure
252 if ( cur_item
->GetOwner() == owner
) {
253 // Update this instance with its new setting
254 cur_item
->SetContents(owner
, source
, type
);
255 cur_item
->dwUpdated
= 0;
257 } else if ( type
== AVAILABLE_SOURCE
) {
258 // The state 'Available' is exclusive
259 cur_item
->SetContents(cur_item
->GetOwner(), source
, A4AF_SOURCE
);
260 cur_item
->dwUpdated
= 0;
268 if ( owner
->ShowSources() ) {
269 CtrlItem_Struct
* newitem
= new CtrlItem_Struct
;
270 newitem
->SetContents(owner
, source
, type
);
272 m_ListItems
.insert( ListItemsPair(source
, newitem
) );
274 // Find the owner-object
275 ListItems::iterator it
= m_ListItems
.find( owner
);
277 if ( it
!= m_ListItems
.end() ) {
278 long item
= FindItem( -1, reinterpret_cast<wxUIntPtr
>(it
->second
) );
281 item
= InsertItem( item
+ 1, wxEmptyString
);
283 SetItemPtrData( item
, reinterpret_cast<wxUIntPtr
>(newitem
) );
285 // background.. this should be in a function
287 listitem
.m_itemId
= item
;
289 listitem
.SetBackgroundColour( GetBackgroundColour() );
298 void CDownloadListCtrl::RemoveSource( const CUpDownClient
* source
, const CPartFile
* owner
)
302 // Retrieve all entries matching the source
303 ListIteratorPair rangeIt
= m_ListItems
.equal_range(source
);
305 for ( ListItems::iterator it
= rangeIt
.first
; it
!= rangeIt
.second
; ) {
306 ListItems::iterator tmp
= it
++;
308 CtrlItem_Struct
* item
= tmp
->second
;
309 if ( owner
== NULL
|| owner
== item
->GetOwner() ) {
310 // Remove it from the m_ListItems
311 m_ListItems
.erase( tmp
);
313 long index
= FindItem( -1, reinterpret_cast<wxUIntPtr
>(item
) );
325 void CDownloadListCtrl::RemoveFile( CPartFile
* file
)
329 // Ensure that any assosiated sources and list-entries are removed
330 ShowFile( file
, false );
332 // Find the assosiated list-item
333 ListItems::iterator it
= m_ListItems
.find( file
);
335 if ( it
!= m_ListItems
.end() ) {
338 m_ListItems
.erase( it
);
343 void CDownloadListCtrl::UpdateItem(const void* toupdate
)
345 // Retrieve all entries matching the source
346 ListIteratorPair rangeIt
= m_ListItems
.equal_range( toupdate
);
348 // Visible lines, default to all because not all platforms
349 // support the GetVisibleLines function
350 long first
= 0, last
= GetItemCount();
353 // Get visible lines if we need them
354 if ( rangeIt
.first
!= rangeIt
.second
) {
355 GetVisibleLines( &first
, &last
);
359 for ( ListItems::iterator it
= rangeIt
.first
; it
!= rangeIt
.second
; ++it
) {
360 CtrlItem_Struct
* item
= it
->second
;
362 long index
= FindItem( -1, reinterpret_cast<wxUIntPtr
>(item
) );
364 // Determine if the file should be shown in the current category
365 if ( item
->GetType() == FILE_TYPE
) {
366 CPartFile
* file
= item
->GetFile();
368 bool show
= file
->CheckShowItemInGivenCat( m_category
);
374 // Only update visible lines
375 if ( index
>= first
&& index
<= last
) {
376 RefreshItem( index
);
379 // Item should no longer be shown in
380 // the current category
381 ShowFile( file
, false );
384 // Item has been hidden but new status means
385 // that it should it should be shown in the
387 ShowFile( file
, true );
390 if (file
->GetStatus() == PS_COMPLETE
) {
391 m_completedFiles
= true;
393 CastByID(ID_BTNCLRCOMPL
, GetParent(), wxButton
)->Enable(true);
398 // Only update visible lines
399 if ( index
>= first
&& index
<= last
) {
400 RefreshItem( index
);
407 void CDownloadListCtrl::ShowFile( CPartFile
* file
, bool show
)
411 ListItems::iterator it
= m_ListItems
.find( file
);
413 if ( it
!= m_ListItems
.end() ) {
414 CtrlItem_Struct
* item
= it
->second
;
417 // Check if the file is already being displayed
418 long index
= FindItem( -1, reinterpret_cast<wxUIntPtr
>(item
) );
420 long newitem
= InsertItem( GetItemCount(), wxEmptyString
);
422 SetItemPtrData( newitem
, reinterpret_cast<wxUIntPtr
>(item
) );
425 myitem
.m_itemId
= newitem
;
426 myitem
.SetBackgroundColour( GetBackgroundColour() );
430 RefreshItem( newitem
);
435 // Ensure sources are hidden
436 ShowSources( file
, false );
438 // Try to find the file and remove it
439 long index
= FindItem( -1, reinterpret_cast<wxUIntPtr
>(item
) );
442 ShowFilesCount( -1 );
449 void CDownloadListCtrl::ShowSources( CPartFile
* file
, bool show
)
451 // Check if the current state is the same as the new state
452 if ( file
->ShowSources() == show
) {
458 file
->SetShowSources( show
);
461 const CPartFile::SourceSet
& normSources
= file
->GetSourceList();
462 const CPartFile::SourceSet
& a4afSources
= file
->GetA4AFList();
464 // Adding normal sources
465 CPartFile::SourceSet::const_iterator it
;
466 for ( it
= normSources
.begin(); it
!= normSources
.end(); ++it
) {
467 switch ((*it
)->GetDownloadState()) {
470 AddSource( file
, *it
, AVAILABLE_SOURCE
);
473 AddSource( file
, *it
, UNAVAILABLE_SOURCE
);
478 // Adding A4AF sources
479 for ( it
= a4afSources
.begin(); it
!= a4afSources
.end(); ++it
) {
480 AddSource( file
, *it
, A4AF_SOURCE
);
483 for ( int i
= GetItemCount() - 1; i
>= 0; --i
) {
484 CtrlItem_Struct
* item
= (CtrlItem_Struct
*)GetItemData(i
);
486 if ( item
->GetType() != FILE_TYPE
&& item
->GetOwner() == file
) {
487 // Remove from the grand list, this call doesn't remove the source
488 // from the listctrl, because ShowSources is now false. This also
490 RemoveSource(item
->GetSource(), file
);
499 void CDownloadListCtrl::ChangeCategory( int newCategory
)
503 // remove all displayed files with a different cat and show the correct ones
504 for (ListItems::const_iterator it
= m_ListItems
.begin(); it
!= m_ListItems
.end(); it
++) {
505 const CtrlItem_Struct
*cur_item
= it
->second
;
507 if ( cur_item
->GetType() == FILE_TYPE
) {
508 CPartFile
* file
= cur_item
->GetFile();
510 bool curVisibility
= file
->CheckShowItemInGivenCat( m_category
);
511 bool newVisibility
= file
->CheckShowItemInGivenCat( newCategory
);
513 // Check if the visibility of the file has changed. However, if the
514 // current category is the default (0) category, then we can't use
515 // curVisiblity to see if the visibility has changed but instead
516 // have to let ShowFile() check if the file is or isn't on the list.
517 if ( curVisibility
!= newVisibility
|| !newCategory
) {
518 ShowFile( file
, newVisibility
);
525 m_category
= newCategory
;
529 uint8
CDownloadListCtrl::GetCategory() const
538 const int itFILES
= 1;
539 const int itSOURCES
= 2;
542 * Helper-function: This function is used to gather selected items.
544 * @param list A pointer to the list to gather items from.
545 * @param types The desired types OR'd together.
546 * @return A list containing the selected items of the choosen types.
548 ItemList
GetSelectedItems( CDownloadListCtrl
* list
, int types
)
552 long index
= list
->GetNextItem( -1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
554 while ( index
> -1 ) {
555 CtrlItem_Struct
* item
= (CtrlItem_Struct
*)list
->GetItemData( index
);
558 add
|= ( item
->GetType() == FILE_TYPE
) && ( types
& itFILES
);
559 add
|= ( item
->GetType() != FILE_TYPE
) && ( types
& itSOURCES
);
562 results
.push_back( item
);
565 index
= list
->GetNextItem( index
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
572 void CDownloadListCtrl::OnCancelFile(wxCommandEvent
& WXUNUSED(event
))
574 ItemList files
= ::GetSelectedItems(this, itFILES
);
577 if (files
.size() == 1) {
578 question
= _("Are you sure that you wish to delete the selected file?");
580 question
= _("Are you sure that you wish to delete the selected files?");
582 if (wxMessageBox( question
, _("Cancel"), wxICON_QUESTION
| wxYES_NO
, this) == wxYES
) {
583 for (ItemList::iterator it
= files
.begin(); it
!= files
.end(); ++it
) {
584 CPartFile
* file
= (*it
)->GetFile();
586 switch (file
->GetStatus()) {
587 case PS_WAITINGFORHASH
:
593 CoreNotify_PartFile_Delete(file
);
602 void CDownloadListCtrl::OnSetPriority( wxCommandEvent
& event
)
605 switch ( event
.GetId() ) {
606 case MP_PRIOLOW
: priority
= PR_LOW
; break;
607 case MP_PRIONORMAL
: priority
= PR_NORMAL
; break;
608 case MP_PRIOHIGH
: priority
= PR_HIGH
; break;
609 case MP_PRIOAUTO
: priority
= PR_AUTO
; break;
614 ItemList files
= ::GetSelectedItems( this, itFILES
);
616 for ( ItemList::iterator it
= files
.begin(); it
!= files
.end(); ++it
) {
617 CPartFile
* file
= (*it
)->GetFile();
619 if ( priority
== PR_AUTO
) {
620 CoreNotify_PartFile_PrioAuto( file
, true );
622 CoreNotify_PartFile_PrioAuto( file
, false );
624 CoreNotify_PartFile_PrioSet( file
, priority
, true );
630 void CDownloadListCtrl::OnSwapSources( wxCommandEvent
& event
)
632 ItemList files
= ::GetSelectedItems( this, itFILES
);
634 for ( ItemList::iterator it
= files
.begin(); it
!= files
.end(); ++it
) {
635 CPartFile
* file
= (*it
)->GetFile();
637 switch ( event
.GetId() ) {
638 case MP_SWAP_A4AF_TO_THIS
:
639 CoreNotify_PartFile_Swap_A4AF( file
);
642 case MP_SWAP_A4AF_TO_THIS_AUTO
:
643 CoreNotify_PartFile_Swap_A4AF_Auto( file
);
646 case MP_SWAP_A4AF_TO_ANY_OTHER
:
647 CoreNotify_PartFile_Swap_A4AF_Others( file
);
654 void CDownloadListCtrl::OnSetCategory( wxCommandEvent
& event
)
656 ItemList files
= ::GetSelectedItems( this, itFILES
);
658 for ( ItemList::iterator it
= files
.begin(); it
!= files
.end(); ++it
) {
659 CPartFile
* file
= (*it
)->GetFile();
661 CoreNotify_PartFile_SetCat( file
, event
.GetId() - MP_ASSIGNCAT
);
664 ChangeCategory( m_category
);
668 void CDownloadListCtrl::OnSetStatus( wxCommandEvent
& event
)
670 ItemList files
= ::GetSelectedItems( this, itFILES
);
672 for ( ItemList::iterator it
= files
.begin(); it
!= files
.end(); ++it
) {
673 CPartFile
* file
= (*it
)->GetFile();
675 switch ( event
.GetId() ) {
677 CoreNotify_PartFile_Pause( file
);
681 CoreNotify_PartFile_Resume( file
);
685 ShowSources(file
, false);
686 CoreNotify_PartFile_Stop( file
);
693 void CDownloadListCtrl::OnClearCompleted( wxCommandEvent
& WXUNUSED(event
) )
699 void CDownloadListCtrl::OnGetLink(wxCommandEvent
& event
)
701 ItemList files
= ::GetSelectedItems( this, itFILES
);
705 for ( ItemList::iterator it
= files
.begin(); it
!= files
.end(); ++it
) {
706 CPartFile
* file
= (*it
)->GetFile();
708 if ( event
.GetId() == MP_GETED2KLINK
) {
709 URIs
+= theApp
->CreateED2kLink( file
) + wxT("\n");
711 URIs
+= theApp
->CreateMagnetLink( file
) + wxT("\n");
715 if ( !URIs
.IsEmpty() ) {
716 theApp
->CopyTextToClipboard( URIs
.BeforeLast(wxT('\n')) );
721 void CDownloadListCtrl::OnGetFeedback(wxCommandEvent
& WXUNUSED(event
))
724 ItemList files
= ::GetSelectedItems(this, itFILES
);
725 for (ItemList::iterator it
= files
.begin(); it
!= files
.end(); ++it
) {
726 CPartFile
* file
= (*it
)->GetFile();
727 feed
+= file
->GetFeedback();
729 if (!feed
.IsEmpty()) {
730 theApp
->CopyTextToClipboard(feed
);
735 void CDownloadListCtrl::OnGetRazorStats( wxCommandEvent
& WXUNUSED(event
) )
737 ItemList files
= ::GetSelectedItems( this, itFILES
);
739 if ( files
.size() == 1 ) {
740 CPartFile
* file
= files
.front()->GetFile();
742 theApp
->amuledlg
->LaunchUrl(
743 wxT("http://stats.razorback2.com/ed2khistory?ed2k=") +
744 file
->GetFileHash().Encode());
749 void CDownloadListCtrl::OnViewFileInfo( wxCommandEvent
& WXUNUSED(event
) )
751 ItemList files
= ::GetSelectedItems( this, itFILES
);
753 if ( files
.size() == 1 ) {
754 CPartFile
* file
= files
.front()->GetFile();
756 CFileDetailDialog
dialog( this, file
);
762 void CDownloadListCtrl::OnViewFileComments( wxCommandEvent
& WXUNUSED(event
) )
764 ItemList files
= ::GetSelectedItems( this, itFILES
);
766 if ( files
.size() == 1 ) {
767 CPartFile
* file
= files
.front()->GetFile();
769 CCommentDialogLst
dialog( this, file
);
775 void CDownloadListCtrl::OnPreviewFile( wxCommandEvent
& WXUNUSED(event
) )
777 ItemList files
= ::GetSelectedItems( this, itFILES
);
779 if ( files
.size() == 1 ) {
780 PreviewFile(files
.front()->GetFile());
784 void CDownloadListCtrl::OnSwapSource( wxCommandEvent
& WXUNUSED(event
) )
786 ItemList sources
= ::GetSelectedItems( this, itSOURCES
);
788 for ( ItemList::iterator it
= sources
.begin(); it
!= sources
.end(); ++it
) {
789 CPartFile
* file
= (*it
)->GetOwner();
790 CUpDownClient
* source
= (*it
)->GetSource();
792 source
->SwapToAnotherFile( true, false, false, file
);
797 void CDownloadListCtrl::OnViewFiles( wxCommandEvent
& WXUNUSED(event
) )
799 ItemList sources
= ::GetSelectedItems( this, itSOURCES
);
801 if ( sources
.size() == 1 ) {
802 CUpDownClient
* source
= sources
.front()->GetSource();
804 source
->RequestSharedFileList();
809 void CDownloadListCtrl::OnAddFriend( wxCommandEvent
& WXUNUSED(event
) )
811 ItemList sources
= ::GetSelectedItems( this, itSOURCES
);
813 for ( ItemList::iterator it
= sources
.begin(); it
!= sources
.end(); ++it
) {
814 CUpDownClient
* client
= (*it
)->GetSource();
815 if (client
->IsFriend()) {
816 theApp
->amuledlg
->m_chatwnd
->RemoveFriend(client
->GetUserHash(), client
->GetIP(), client
->GetUserPort());
818 theApp
->amuledlg
->m_chatwnd
->AddFriend( client
);
824 void CDownloadListCtrl::OnSendMessage( wxCommandEvent
& WXUNUSED(event
) )
826 ItemList sources
= ::GetSelectedItems( this, itSOURCES
);
828 if ( sources
.size() == 1 ) {
829 CUpDownClient
* source
= (sources
.front())->GetSource();
831 // These values are cached, since calling wxGetTextFromUser will
832 // start an event-loop, in which the client may be deleted.
833 wxString userName
= source
->GetUserName();
834 uint64 userID
= GUI_ID(source
->GetIP(), source
->GetUserPort());
836 wxString message
= ::wxGetTextFromUser(_("Send message to user"),
837 _("Message to send:"));
838 if ( !message
.IsEmpty() ) {
839 theApp
->amuledlg
->m_chatwnd
->SendMessage(message
, userName
, userID
);
845 void CDownloadListCtrl::OnViewClientInfo( wxCommandEvent
& WXUNUSED(event
) )
847 ItemList sources
= ::GetSelectedItems( this, itSOURCES
);
849 if ( sources
.size() == 1 ) {
850 CUpDownClient
* source
= (sources
.front())->GetSource();
852 CClientDetailDialog
dialog( this, source
);
858 void CDownloadListCtrl::OnItemActivated( wxListEvent
& evt
)
860 CtrlItem_Struct
* content
= (CtrlItem_Struct
*)GetItemData( evt
.GetIndex() );
862 if ( content
->GetType() == FILE_TYPE
) {
863 CPartFile
* file
= content
->GetFile();
865 if ((!file
->IsPartFile() || file
->GetStatus() == PS_COMPLETE
) && file
->PreviewAvailable()) {
868 ShowSources( file
, !file
->ShowSources() );
875 void CDownloadListCtrl::OnMouseRightClick(wxListEvent
& evt
)
877 long index
= CheckSelection(evt
);
885 CtrlItem_Struct
* item
= (CtrlItem_Struct
*)GetItemData( index
);
886 if (item
->GetType() == FILE_TYPE
) {
887 m_menu
= new wxMenu( _("Downloads") );
889 wxMenu
* priomenu
= new wxMenu();
890 priomenu
->AppendCheckItem(MP_PRIOLOW
, _("Low"));
891 priomenu
->AppendCheckItem(MP_PRIONORMAL
, _("Normal"));
892 priomenu
->AppendCheckItem(MP_PRIOHIGH
, _("High"));
893 priomenu
->AppendCheckItem(MP_PRIOAUTO
, _("Auto"));
895 m_menu
->Append(MP_MENU_PRIO
, _("Priority"), priomenu
);
896 m_menu
->Append(MP_CANCEL
, _("Cancel"));
897 m_menu
->Append(MP_STOP
, _("&Stop"));
898 m_menu
->Append(MP_PAUSE
, _("&Pause"));
899 m_menu
->Append(MP_RESUME
, _("&Resume"));
900 m_menu
->Append(MP_CLEARCOMPLETED
, _("C&lear completed"));
901 //-----------------------------------------------------
902 m_menu
->AppendSeparator();
903 //-----------------------------------------------------
904 wxMenu
* extendedmenu
= new wxMenu();
905 extendedmenu
->Append(MP_SWAP_A4AF_TO_THIS
,
906 _("Swap every A4AF to this file now"));
907 extendedmenu
->AppendCheckItem(MP_SWAP_A4AF_TO_THIS_AUTO
,
908 _("Swap every A4AF to this file (Auto)"));
909 //-----------------------------------------------------
910 extendedmenu
->AppendSeparator();
911 //-----------------------------------------------------
912 extendedmenu
->Append(MP_SWAP_A4AF_TO_ANY_OTHER
,
913 _("Swap every A4AF to any other file now"));
914 //-----------------------------------------------------
915 m_menu
->Append(MP_MENU_EXTD
,
916 _("Extended Options"), extendedmenu
);
917 //-----------------------------------------------------
918 m_menu
->AppendSeparator();
919 //-----------------------------------------------------
920 /* Commented out till RB2 is back
921 m_menu->Append( MP_RAZORSTATS,
922 _("Get Razorback 2's stats for this file"));
923 //-----------------------------------------------------
924 m_menu->AppendSeparator();
925 //-----------------------------------------------------
927 m_menu
->Append(MP_VIEW
, _("Preview"));
928 m_menu
->Append(MP_METINFO
, _("Show file &details"));
929 m_menu
->Append(MP_VIEWFILECOMMENTS
,
930 _("Show all comments"));
931 //-----------------------------------------------------
932 m_menu
->AppendSeparator();
933 //-----------------------------------------------------
934 m_menu
->Append(MP_GETMAGNETLINK
,
935 _("Copy magnet URI to clipboard"));
936 m_menu
->Append(MP_GETED2KLINK
,
937 _("Copy ED2k &link to clipboard"));
938 m_menu
->Append(MP_WS
,
939 _("Copy feedback to clipboard"));
940 //-----------------------------------------------------
941 m_menu
->AppendSeparator();
942 //-----------------------------------------------------
943 // Add dinamic entries
944 wxMenu
*cats
= new wxMenu(_("Category"));
945 if (theApp
->glob_prefs
->GetCatCount() > 1) {
946 for (uint32 i
= 0; i
< theApp
->glob_prefs
->GetCatCount(); i
++) {
948 cats
->Append( MP_ASSIGNCAT
, _("unassign") );
950 cats
->Append( MP_ASSIGNCAT
+ i
,
951 theApp
->glob_prefs
->GetCategory(i
)->title
);
955 m_menu
->Append(MP_MENU_CATS
, _("Assign to category"), cats
);
956 m_menu
->Enable(MP_MENU_CATS
, (theApp
->glob_prefs
->GetCatCount() > 1) );
958 CPartFile
* file
= item
->GetFile();
961 (file
->GetStatus() != PS_ERROR
) &&
962 (file
->GetStatus() != PS_COMPLETE
) &&
963 (file
->IsStopped() != true);
964 const bool canPause
=
965 (file
->GetStatus() != PS_PAUSED
) && canStop
;
966 const bool fileResumable
=
967 (file
->GetStatus() == PS_PAUSED
) ||
968 (file
->GetStatus() == PS_ERROR
) ||
969 (file
->GetStatus() == PS_INSUFFICIENT
);
971 wxMenu
* menu
= m_menu
;
972 menu
->Enable( MP_CANCEL
, ( file
->GetStatus() != PS_COMPLETE
) );
973 menu
->Enable( MP_PAUSE
, canPause
);
974 menu
->Enable( MP_STOP
, canStop
);
975 menu
->Enable( MP_RESUME
, fileResumable
);
976 menu
->Enable( MP_CLEARCOMPLETED
, m_completedFiles
);
979 if (file
->IsPartFile() && (file
->GetStatus() != PS_COMPLETE
)) {
980 view
<< CFormat(wxT("%s [%s]")) % _("Preview")
981 % file
->GetPartMetFileName().RemoveExt();
982 } else if ( file
->GetStatus() == PS_COMPLETE
) {
983 view
<< _("&Open the file");
985 menu
->SetLabel(MP_VIEW
, view
);
986 menu
->Enable(MP_VIEW
, file
->PreviewAvailable() );
988 menu
->Check( MP_SWAP_A4AF_TO_THIS_AUTO
, file
->IsA4AFAuto() );
990 int priority
= file
->IsAutoDownPriority() ?
991 PR_AUTO
: file
->GetDownPriority();
993 priomenu
->Check( MP_PRIOHIGH
, priority
== PR_HIGH
);
994 priomenu
->Check( MP_PRIONORMAL
, priority
== PR_NORMAL
);
995 priomenu
->Check( MP_PRIOLOW
, priority
== PR_LOW
);
996 priomenu
->Check( MP_PRIOAUTO
, priority
== PR_AUTO
);
998 menu
->Enable( MP_MENU_EXTD
, canPause
);
1000 PopupMenu(m_menu
, evt
.GetPoint());
1003 CUpDownClient
* client
= item
->GetSource();
1005 m_menu
= new wxMenu(wxT("Clients"));
1006 m_menu
->Append(MP_DETAIL
, _("Show &Details"));
1007 m_menu
->Append(MP_ADDFRIEND
, client
->IsFriend() ? _("Remove from friends") : _("Add to Friends"));
1008 m_menu
->Append(MP_SHOWLIST
, _("View Files"));
1009 m_menu
->Append(MP_SENDMESSAGE
, _("Send message"));
1010 m_menu
->Append(MP_CHANGE2FILE
, _("Swap to this file"));
1012 // Only enable the Swap option for A4AF sources
1013 m_menu
->Enable(MP_CHANGE2FILE
, (item
->GetType() == A4AF_SOURCE
));
1014 // We need a valid IP if we are to message the client
1015 m_menu
->Enable(MP_SENDMESSAGE
, (client
->GetIP() != 0));
1017 m_menu
->Enable(MP_SHOWLIST
, !client
->HasDisabledSharedFiles());
1019 PopupMenu(m_menu
, evt
.GetPoint());
1029 void CDownloadListCtrl::OnMouseMiddleClick(wxListEvent
& evt
)
1031 // Check if clicked item is selected. If not, unselect all and select it.
1032 long index
= CheckSelection(evt
);
1037 CtrlItem_Struct
* item
= (CtrlItem_Struct
*)GetItemData( index
);
1039 if ( item
->GetType() == FILE_TYPE
) {
1040 CFileDetailDialog(this, item
->GetFile()).ShowModal();
1042 CClientDetailDialog(this, item
->GetSource()).ShowModal();
1047 void CDownloadListCtrl::OnKeyPressed( wxKeyEvent
& event
)
1049 // Check if delete was pressed
1050 switch (event
.GetKeyCode()) {
1051 case WXK_NUMPAD_DELETE
:
1054 OnCancelFile( evt
);
1058 ItemList files
= ::GetSelectedItems( this, itFILES
);
1059 if (files
.size() == 1) {
1060 CPartFile
* file
= files
.front()->GetFile();
1062 // Currently renaming of completed files causes problem with kad
1063 if (file
->IsPartFile()) {
1064 wxString strNewName
= ::wxGetTextFromUser(
1065 _("Enter new name for this file:"),
1066 _("File rename"), file
->GetFileName().GetPrintable());
1068 CPath newName
= CPath(strNewName
);
1069 if (newName
.IsOk() && (newName
!= file
->GetFileName())) {
1070 theApp
->sharedfiles
->RenameFile(file
, newName
);
1082 void CDownloadListCtrl::OnDrawItem(
1083 int item
, wxDC
* dc
, const wxRect
& rect
, const wxRect
& rectHL
, bool highlighted
)
1085 // Don't do any drawing if there's nobody to see it.
1086 if ( !theApp
->amuledlg
->IsDialogVisible( CamuleDlg::DT_TRANSFER_WND
) ) {
1090 CtrlItem_Struct
* content
= (CtrlItem_Struct
*)GetItemData(item
);
1092 // Define text-color and background
1093 if ((content
->GetType() == FILE_TYPE
) && (highlighted
)) {
1095 dc
->SetBackground(*m_hilightBrush
);
1096 dc
->SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
));
1098 dc
->SetBackground(*m_hilightUnfocusBrush
);
1099 dc
->SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
));
1102 dc
->SetBackground(*(wxTheBrushList
->FindOrCreateBrush(
1103 wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX
), wxSOLID
)));
1104 dc
->SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
1108 // Define the border of the drawn area
1109 if ( highlighted
) {
1111 if ( ( content
->GetType() == FILE_TYPE
) && !GetFocus() ) {
1112 old
= m_hilightUnfocusBrush
->GetColour();
1114 old
= m_hilightBrush
->GetColour();
1118 ((int)old
.Red() * 65) / 100,
1119 ((int)old
.Green() * 65) / 100,
1120 ((int)old
.Blue() * 65) / 100);
1122 dc
->SetPen( wxPen(newcol
, 1, wxSOLID
) );
1124 dc
->SetPen(*wxTRANSPARENT_PEN
);
1128 dc
->SetBrush( dc
->GetBackground() );
1129 dc
->DrawRectangle( rectHL
.x
, rectHL
.y
, rectHL
.width
, rectHL
.height
);
1131 dc
->SetPen(*wxTRANSPARENT_PEN
);
1133 if ( content
->GetType() == FILE_TYPE
&& ( !highlighted
|| !GetFocus() ) ) {
1134 // If we have category, override textforeground with what category tells us.
1135 CPartFile
*file
= content
->GetFile();
1136 if ( file
->GetCategory() ) {
1137 dc
->SetTextForeground(
1138 WxColourFromCr(theApp
->glob_prefs
->GetCatColor(file
->GetCategory())) );
1142 // Various constant values we use
1143 const int iTextOffset
= ( rect
.GetHeight() - dc
->GetCharHeight() ) / 2;
1144 const int iOffset
= 4;
1146 // The starting end ending position of the tree
1147 bool tree_show
= false;
1151 wxRect
cur_rec( iOffset
, rect
.y
, 0, rect
.height
);
1152 for (int i
= 0; i
< GetColumnCount(); i
++) {
1153 wxListItem listitem
;
1154 GetColumn(i
, listitem
);
1156 if (listitem
.GetWidth() > 2*iOffset
) {
1157 cur_rec
.width
= listitem
.GetWidth() - 2*iOffset
;
1159 // Make a copy of the current rectangle so we can apply specific tweaks
1160 wxRect target_rec
= cur_rec
;
1162 tree_show
= ( listitem
.GetWidth() > 0 );
1164 tree_start
= cur_rec
.x
- iOffset
;
1165 tree_end
= cur_rec
.x
+ iOffset
;
1167 // Double the offset to make room for the cirle-marker
1168 target_rec
.x
+= iOffset
;
1169 target_rec
.width
-= iOffset
;
1171 // will ensure that text is about in the middle ;)
1172 target_rec
.y
+= iTextOffset
;
1176 if ( content
->GetType() == FILE_TYPE
) {
1177 DrawFileItem(dc
, i
, target_rec
, content
);
1179 DrawSourceItem(dc
, i
, target_rec
, content
);
1183 // Increment to the next column
1184 cur_rec
.x
+= listitem
.GetWidth();
1187 // Draw tree last so it draws over selected and focus (looks better)
1189 // Gather some information
1190 const bool notLast
= item
+ 1 != GetItemCount();
1191 const bool notFirst
= item
!= 0;
1192 const bool hasNext
= notLast
&&
1193 ((CtrlItem_Struct
*)GetItemData(item
+ 1))->GetType() != FILE_TYPE
;
1194 const bool isOpenRoot
= content
->GetType() == FILE_TYPE
&&
1195 (content
->GetFile())->ShowSources() &&
1196 ((content
->GetFile())->GetStatus() != PS_COMPLETE
);
1197 const bool isChild
= content
->GetType() != FILE_TYPE
;
1199 // Might as well calculate these now
1200 const int treeCenter
= tree_start
+ 3;
1201 const int middle
= cur_rec
.y
+ ( cur_rec
.height
+ 1 ) / 2;
1203 // Set up a new pen for drawing the tree
1204 dc
->SetPen( *(wxThePenList
->FindOrCreatePen(dc
->GetTextForeground(), 1, wxSOLID
)) );
1207 // Draw the line to the status bar
1208 dc
->DrawLine(tree_end
, middle
, tree_start
+ 3, middle
);
1210 // Draw the line to the child node
1212 dc
->DrawLine(treeCenter
, middle
, treeCenter
, cur_rec
.y
+ cur_rec
.height
+ 1);
1215 // Draw the line back up to parent node
1217 dc
->DrawLine(treeCenter
, middle
, treeCenter
, cur_rec
.y
- 1);
1219 } else if ( isOpenRoot
) {
1220 // Draw empty circle
1221 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1223 dc
->DrawCircle( treeCenter
, middle
, 3 );
1225 // Draw the line to the child node if there are any children
1227 dc
->DrawLine(treeCenter
, middle
+ 3, treeCenter
, cur_rec
.y
+ cur_rec
.height
+ 1);
1235 void CDownloadListCtrl::DrawFileItem( wxDC
* dc
, int nColumn
, const wxRect
& rect
, CtrlItem_Struct
* item
) const
1237 wxDCClipper
clipper( *dc
, rect
.GetX(), rect
.GetY(), rect
.GetWidth(), rect
.GetHeight() );
1239 const CPartFile
* file
= item
->GetFile();
1241 // Used to contain the contenst of cells that dont need any fancy drawing, just text.
1247 // show no. of partfile in filename column
1249 if (thePrefs::ShowPartFileNumber()) {
1250 if (file
->IsPartFile() && !(file
->GetStatus() == PS_COMPLETE
)) {
1251 filename
= CFormat(wxT("[%s] ")) % file
->GetPartMetFileName().RemoveAllExt();
1254 filename
+= file
->GetFileName().GetPrintable();
1256 if (file
->HasRating() || file
->HasComment()) {
1257 int image
= Client_CommentOnly_Smiley
;
1258 if (file
->HasRating()) {
1259 image
= Client_InvalidRating_Smiley
+ file
->UserRating() - 1;
1262 wxASSERT(image
>= Client_InvalidRating_Smiley
);
1263 wxASSERT(image
<= Client_CommentOnly_Smiley
);
1267 // it's already centered by OnDrawItem() ...
1268 m_ImageList
.Draw(image
, *dc
, rect
.GetX(), rect
.GetY() - 1,
1269 wxIMAGELIST_DRAW_TRANSPARENT
);
1270 dc
->DrawText(filename
, rect
.GetX() + imgWidth
+ 4, rect
.GetY());
1272 dc
->DrawText(filename
, rect
.GetX(), rect
.GetY());
1279 text
= CastItoXBytes( file
->GetFileSize() );
1284 text
= CastItoXBytes( file
->GetTransferred() );
1289 text
= CastItoXBytes( file
->GetCompletedSize() );
1294 if ( file
->GetTransferingSrcCount() ) {
1295 text
= wxString::Format( wxT("%.1f "), file
->GetKBpsDown() ) +
1302 if (thePrefs::ShowProgBar())
1304 int iWidth
= rect
.GetWidth() - 2;
1305 int iHeight
= rect
.GetHeight() - 2;
1307 // DO NOT DRAW IT ALL THE TIME
1308 uint32 dwTicks
= GetTickCount();
1310 wxMemoryDC cdcStatus
;
1312 if ( item
->dwUpdated
< dwTicks
|| !item
->status
|| iWidth
!= item
->status
->GetWidth() ) {
1313 if ( item
->status
== NULL
) {
1314 item
->status
= new wxBitmap(iWidth
, iHeight
);
1315 } else if ( item
->status
->GetWidth() != iWidth
) {
1316 // Only recreate if the size has changed
1317 item
->status
->Create(iWidth
, iHeight
);
1320 cdcStatus
.SelectObject( *item
->status
);
1322 if ( thePrefs::UseFlatBar() ) {
1323 DrawFileStatusBar( file
, &cdcStatus
,
1324 wxRect(0, 0, iWidth
, iHeight
), true);
1326 DrawFileStatusBar( file
, &cdcStatus
,
1327 wxRect(1, 1, iWidth
- 2, iHeight
- 2), false);
1329 // Draw black border
1330 cdcStatus
.SetPen( *wxBLACK_PEN
);
1331 cdcStatus
.SetBrush( *wxTRANSPARENT_BRUSH
);
1332 cdcStatus
.DrawRectangle( 0, 0, iWidth
, iHeight
);
1335 item
->dwUpdated
= dwTicks
+ 5000; // Plus five seconds
1337 cdcStatus
.SelectObject( *item
->status
);
1340 dc
->Blit( rect
.GetX(), rect
.GetY() + 1, iWidth
, iHeight
, &cdcStatus
, 0, 0);
1343 if (thePrefs::ShowPercent()) {
1344 // Percentage of completing
1345 // We strip anything below the first decimal point,
1346 // to avoid Format doing roundings
1347 float percent
= floor( file
->GetPercentCompleted() * 10.0f
) / 10.0f
;
1349 wxString buffer
= wxString::Format( wxT("%.1f%%"), percent
);
1350 int middlex
= (2*rect
.GetX() + rect
.GetWidth()) >> 1;
1351 int middley
= (2*rect
.GetY() + rect
.GetHeight()) >> 1;
1353 wxCoord textwidth
, textheight
;
1355 dc
->GetTextExtent(buffer
, &textwidth
, &textheight
);
1356 wxColour AktColor
= dc
->GetTextForeground();
1357 if (thePrefs::ShowProgBar()) {
1358 dc
->SetTextForeground(*wxWHITE
);
1360 dc
->SetTextForeground(*wxBLACK
);
1362 dc
->DrawText(buffer
, middlex
- (textwidth
>> 1), middley
- (textheight
>> 1));
1363 dc
->SetTextForeground(AktColor
);
1370 uint16 sc
= file
->GetSourceCount();
1371 uint16 ncsc
= file
->GetNotCurrentSourcesCount();
1373 text
= wxString::Format( wxT("%i/%i" ), sc
- ncsc
, sc
);
1375 text
= wxString::Format( wxT("%i"), sc
);
1378 if ( file
->GetSrcA4AFCount() ) {
1379 text
+= wxString::Format( wxT("+%i"), file
->GetSrcA4AFCount() );
1382 if ( file
->GetTransferingSrcCount() ) {
1383 text
+= wxString::Format( wxT(" (%i)"), file
->GetTransferingSrcCount() );
1391 text
= PriorityToStr( file
->GetDownPriority(), file
->IsAutoDownPriority() );
1396 text
= file
->getPartfileStatus();
1401 if ((file
->GetStatus() != PS_COMPLETING
) && file
->IsPartFile()) {
1402 uint64 remainSize
= file
->GetFileSize() - file
->GetCompletedSize();
1403 sint32 remainTime
= file
->getTimeRemaining();
1405 if (remainTime
>= 0) {
1406 text
= CastSecondsToHM(remainTime
);
1408 text
= _("Unknown");
1411 text
+= wxT(" (") + CastItoXBytes(remainSize
) + wxT(")");
1416 // Last seen completed
1418 if ( file
->lastseencomplete
) {
1419 text
= wxDateTime( file
->lastseencomplete
).Format( _("%y/%m/%d %H:%M:%S") );
1421 text
= _("Unknown");
1428 const time_t lastReceived
= file
->GetLastChangeDatetime();
1430 text
= wxDateTime(lastReceived
).Format( _("%y/%m/%d %H:%M:%S") );
1432 text
= _("Unknown");
1437 if ( !text
.IsEmpty() ) {
1438 dc
->DrawText( text
, rect
.GetX(), rect
.GetY() );
1443 void CDownloadListCtrl::DrawSourceItem(
1444 wxDC
* dc
, int nColumn
, const wxRect
& rect
, CtrlItem_Struct
* item
) const
1446 wxDCClipper
clipper( *dc
, rect
.GetX(), rect
.GetY(), rect
.GetWidth(), rect
.GetHeight() );
1449 const CUpDownClient
* client
= item
->GetSource();
1452 // Client name + various icons
1454 wxRect cur_rec
= rect
;
1455 // +3 is added by OnDrawItem()... so take it off
1456 // Kry - eMule says +1, so I'm trusting it
1457 wxPoint
point( cur_rec
.GetX(), cur_rec
.GetY()+1 );
1459 if (item
->GetType() != A4AF_SOURCE
) {
1462 switch (client
->GetDownloadState()) {
1465 case DS_WAITCALLBACK
:
1466 case DS_TOOMANYCONNS
:
1467 image
= Client_Red_Smiley
;
1470 if (client
->IsRemoteQueueFull()) {
1471 image
= Client_Grey_Smiley
;
1473 image
= Client_Yellow_Smiley
;
1476 case DS_DOWNLOADING
:
1478 image
= Client_Green_Smiley
;
1480 case DS_NONEEDEDPARTS
:
1482 image
= Client_Grey_Smiley
;
1484 default: // DS_NONE i.e.
1485 image
= Client_White_Smiley
;
1488 m_ImageList
.Draw(image
, *dc
, point
.x
, point
.y
,
1489 wxIMAGELIST_DRAW_TRANSPARENT
);
1491 m_ImageList
.Draw(Client_Grey_Smiley
, *dc
, point
.x
, point
.y
,
1492 wxIMAGELIST_DRAW_TRANSPARENT
);
1496 wxPoint
point2( cur_rec
.GetX(), cur_rec
.GetY() + 1 );
1500 if ( client
->IsFriend() ) {
1501 clientImage
= Client_Friend_Smiley
;
1503 switch ( client
->GetClientSoft() ) {
1505 clientImage
= Client_aMule_Smiley
;
1508 case SO_NEW_MLDONKEY
:
1509 case SO_NEW2_MLDONKEY
:
1510 clientImage
= Client_mlDonkey_Smiley
;
1513 case SO_EDONKEYHYBRID
:
1514 clientImage
= Client_eDonkeyHybrid_Smiley
;
1517 clientImage
= Client_eMule_Smiley
;
1520 clientImage
= Client_lphant_Smiley
;
1523 case SO_NEW_SHAREAZA
:
1524 case SO_NEW2_SHAREAZA
:
1525 clientImage
= Client_Shareaza_Smiley
;
1528 clientImage
= Client_xMule_Smiley
;
1531 // cDonkey, Compatible, Unknown
1532 // No icon for those yet.
1533 // Using the eMule one + '?'
1534 clientImage
= Client_Unknown
;
1539 m_ImageList
.Draw(clientImage
, *dc
, point2
.x
, point
.y
,
1540 wxIMAGELIST_DRAW_TRANSPARENT
);
1542 if (client
->GetScoreRatio() > 1) {
1543 // Has credits, draw the gold star
1544 m_ImageList
.Draw(Client_CreditsYellow_Smiley
, *dc
, point2
.x
, point
.y
,
1545 wxIMAGELIST_DRAW_TRANSPARENT
);
1546 } else if ( client
->ExtProtocolAvailable() ) {
1547 // Ext protocol -> Draw the '+'
1548 m_ImageList
.Draw(Client_ExtendedProtocol_Smiley
, *dc
, point2
.x
, point
.y
,
1549 wxIMAGELIST_DRAW_TRANSPARENT
);
1552 if (client
->IsIdentified()) {
1554 m_ImageList
.Draw(Client_SecIdent_Smiley
, *dc
, point2
.x
, point
.y
,
1555 wxIMAGELIST_DRAW_TRANSPARENT
);
1556 } else if (client
->IsBadGuy()) {
1558 m_ImageList
.Draw(Client_BadGuy_Smiley
, *dc
, point2
.x
, point
.y
,
1559 wxIMAGELIST_DRAW_TRANSPARENT
);
1562 if (client
->HasObfuscatedConnectionBeenEstablished()) {
1563 // the "¿" except it's a key
1564 m_ImageList
.Draw(Client_Encryption_Smiley
, *dc
, point2
.x
, point
.y
,
1565 wxIMAGELIST_DRAW_TRANSPARENT
);
1569 #ifdef ENABLE_IP2COUNTRY
1571 const CountryData
& countrydata
= theApp
->amuledlg
->m_IP2Country
->GetCountryData(client
->GetFullIP());
1572 dc
->DrawBitmap(countrydata
.Flag
,
1573 rect
.x
+ 40, rect
.y
+ 5,
1574 wxIMAGELIST_DRAW_TRANSPARENT
);
1576 userName
<< countrydata
.Name
;
1578 userName
<< wxT(" - ");
1579 #endif // ENABLE_IP2COUNTRY
1580 if (client
->GetUserName().IsEmpty()) {
1581 userName
<< wxT("?");
1583 userName
<< client
->GetUserName();
1585 dc
->DrawText(userName
, rect
.GetX() + 60, rect
.GetY());
1589 case 3: // completed
1590 if (item
->GetType() != A4AF_SOURCE
&& client
->GetTransferredDown()) {
1591 buffer
= CastItoXBytes(client
->GetTransferredDown());
1592 dc
->DrawText(buffer
, rect
.GetX(), rect
.GetY());
1597 if (item
->GetType() != A4AF_SOURCE
&& client
->GetKBpsDown() > 0.001) {
1598 buffer
= wxString::Format(wxT("%.1f "),
1599 client
->GetKBpsDown()) + _("kB/s");
1600 dc
->DrawText(buffer
, rect
.GetX(), rect
.GetY());
1604 case 5: // file info
1605 if ( thePrefs::ShowProgBar() ) {
1606 int iWidth
= rect
.GetWidth() - 2;
1607 int iHeight
= rect
.GetHeight() - 2;
1609 if ( item
->GetType() != A4AF_SOURCE
) {
1610 uint32 dwTicks
= GetTickCount();
1612 wxMemoryDC cdcStatus
;
1614 if ( item
->dwUpdated
< dwTicks
|| !item
->status
||
1615 iWidth
!= item
->status
->GetWidth() ) {
1617 if (item
->status
== NULL
) {
1618 item
->status
= new wxBitmap(iWidth
, iHeight
);
1619 } else if ( item
->status
->GetWidth() != iWidth
) {
1620 // Only recreate if size has changed
1621 item
->status
->Create(iWidth
, iHeight
);
1624 cdcStatus
.SelectObject(*(item
->status
));
1626 if ( thePrefs::UseFlatBar() ) {
1627 DrawSourceStatusBar( client
, &cdcStatus
,
1628 wxRect(0, 0, iWidth
, iHeight
), true);
1630 DrawSourceStatusBar( client
, &cdcStatus
,
1631 wxRect(1, 1, iWidth
- 2, iHeight
- 2), false);
1633 // Draw black border
1634 cdcStatus
.SetPen( *wxBLACK_PEN
);
1635 cdcStatus
.SetBrush( *wxTRANSPARENT_BRUSH
);
1636 cdcStatus
.DrawRectangle( 0, 0, iWidth
, iHeight
);
1640 item
->dwUpdated
= dwTicks
+ 10000;
1642 cdcStatus
.SelectObject(*(item
->status
));
1645 dc
->Blit(rect
.GetX(), rect
.GetY() + 1, iWidth
, iHeight
, &cdcStatus
, 0, 0);
1649 int midx
= (2*rect
.GetX() + rect
.GetWidth()) >> 1;
1650 int midy
= (2*rect
.GetY() + rect
.GetHeight()) >> 1;
1652 wxCoord txtwidth
, txtheight
;
1654 dc
->GetTextExtent(buffer
, &txtwidth
, &txtheight
);
1656 dc
->SetTextForeground(*wxBLACK
);
1657 dc
->DrawText(buffer
, midx
- (txtwidth
>> 1), midy
- (txtheight
>> 1));
1659 // Draw black border
1660 dc
->SetPen( *wxBLACK_PEN
);
1661 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1662 dc
->DrawRectangle( rect
.GetX(), rect
.GetY() + 1, iWidth
, iHeight
);
1669 dc
->DrawText(client
->GetClientVerString(), rect
.GetX(), rect
.GetY());
1674 // We only show priority for sources actually queued for that file
1675 if ( item
->GetType() != A4AF_SOURCE
&&
1676 client
->GetDownloadState() == DS_ONQUEUE
) {
1677 if (client
->IsRemoteQueueFull()) {
1678 buffer
= _("Queue Full");
1679 dc
->DrawText(buffer
, rect
.GetX(), rect
.GetY());
1681 if (client
->GetRemoteQueueRank()) {
1682 sint16 qrDiff
= client
->GetRemoteQueueRank() -
1683 client
->GetOldRemoteQueueRank();
1684 if(qrDiff
== client
->GetRemoteQueueRank() ) {
1687 wxColour savedColour
= dc
->GetTextForeground();
1689 dc
->SetTextForeground(*wxBLUE
);
1692 dc
->SetTextForeground(*wxRED
);
1694 //if( qrDiff == 0 ) {
1695 // dc->SetTextForeground(*wxLIGHT_GREY);
1697 buffer
= wxString::Format(_("QR: %u (%i)"),
1698 client
->GetRemoteQueueRank(), qrDiff
);
1699 dc
->DrawText(buffer
, rect
.GetX(), rect
.GetY());
1700 dc
->SetTextForeground(savedColour
);
1707 if (item
->GetType() != A4AF_SOURCE
) {
1708 buffer
= DownloadStateToStr( client
->GetDownloadState(),
1709 client
->IsRemoteQueueFull() );
1711 buffer
= _("Asked for another file");
1712 if ( client
->GetRequestFile() &&
1713 client
->GetRequestFile()->GetFileName().IsOk()) {
1714 buffer
+= CFormat(wxT(" (%s)"))
1715 % client
->GetRequestFile()->GetFileName();
1718 dc
->DrawText(buffer
, rect
.GetX(), rect
.GetY());
1720 // Source comes from?
1722 buffer
= wxGetTranslation(OriginToText(client
->GetSourceFrom()));
1723 dc
->DrawText(buffer
, rect
.GetX(), rect
.GetY());
1730 wxString
CDownloadListCtrl::GetTTSText(unsigned item
) const
1732 CtrlItem_Struct
* content
= (CtrlItem_Struct
*)GetItemData(item
);
1734 if (content
->GetType() == FILE_TYPE
) {
1735 CPartFile
* file
= content
->GetFile();
1737 return file
->GetFileName().GetPrintable();
1740 return wxEmptyString
;
1744 int CDownloadListCtrl::SortProc(wxUIntPtr param1
, wxUIntPtr param2
, long sortData
)
1746 CtrlItem_Struct
* item1
= (CtrlItem_Struct
*)param1
;
1747 CtrlItem_Struct
* item2
= (CtrlItem_Struct
*)param2
;
1749 int sortMod
= (sortData
& CMuleListCtrl::SORT_DES
) ? -1 : 1;
1750 sortData
&= CMuleListCtrl::COLUMN_MASK
;
1753 if ( item1
->GetType() == FILE_TYPE
) {
1754 if ( item2
->GetType() == FILE_TYPE
) {
1755 // Both are files, so we just compare them
1756 comp
= Compare( item1
->GetFile(), item2
->GetFile(), sortData
);
1758 // A file and a source, checking if they belong to each other
1759 if ( item1
->GetFile() == item2
->GetOwner() ) {
1760 // A file should always be above its sources
1761 // Returning directly to avoid the modifier
1764 // Source belongs to anther file, so we compare the files instead
1765 comp
= Compare( item1
->GetFile(), item2
->GetOwner(), sortData
);
1769 if ( item2
->GetType() == FILE_TYPE
) {
1770 // A source and a file, checking if they belong to each other
1771 if ( item1
->GetOwner() == item2
->GetFile() ) {
1772 // A source should always be below its file
1773 // Returning directly to avoid the modifier
1776 // Source belongs to anther file, so we compare the files instead
1777 comp
= Compare( item1
->GetOwner(), item2
->GetFile(), sortData
);
1780 // Two sources, some different possibilites
1781 if ( item1
->GetOwner() == item2
->GetOwner() ) {
1782 // Avilable sources first, if we have both an
1783 // available and an unavailable
1784 comp
= ( item2
->GetType() - item1
->GetType() );
1787 // A4AF and non-A4AF. The order is fixed regardless of sort-order.
1790 comp
= Compare(item1
->GetSource(), item2
->GetSource(), sortData
);
1793 // Belongs to different files, so we compare the files
1794 comp
= Compare( item1
->GetOwner(), item2
->GetOwner(), sortData
);
1799 // We modify the result so that it matches with ascending or decending
1800 return sortMod
* comp
;
1804 int CDownloadListCtrl::Compare( const CPartFile
* file1
, const CPartFile
* file2
, long lParamSort
)
1808 switch (lParamSort
) {
1812 file1
->GetFileName(),
1813 file2
->GetFileName() );
1819 file1
->GetFileSize(),
1820 file2
->GetFileSize() );
1823 // Sort by transferred
1826 file1
->GetTransferred(),
1827 file2
->GetTransferred() );
1830 // Sort by completed
1833 file1
->GetCompletedSize(),
1834 file2
->GetCompletedSize() );
1840 file1
->GetKBpsDown() * 1024,
1841 file2
->GetKBpsDown() * 1024 );
1844 // Sort by percentage completed
1847 file1
->GetPercentCompleted(),
1848 file2
->GetPercentCompleted() );
1851 // Sort by number of sources
1854 file1
->GetSourceCount(),
1855 file2
->GetSourceCount() );
1861 file1
->GetDownPriority(),
1862 file2
->GetDownPriority() );
1868 file1
->getPartfileStatusRang(),
1869 file2
->getPartfileStatusRang() );
1872 // Sort by remaining time
1874 if (file1
->getTimeRemaining() == -1) {
1875 if (file2
->getTimeRemaining() == -1) {
1881 if (file2
->getTimeRemaining() == -1) {
1885 file1
->getTimeRemaining(),
1886 file2
->getTimeRemaining() );
1891 // Sort by last seen complete
1894 file1
->lastseencomplete
,
1895 file2
->lastseencomplete
);
1898 // Sort by last reception
1901 file1
->GetLastChangeDatetime(),
1902 file2
->GetLastChangeDatetime() );
1910 int CDownloadListCtrl::Compare(
1911 const CUpDownClient
* client1
, const CUpDownClient
* client2
, long lParamSort
)
1913 switch (lParamSort
) {
1916 return CmpAny( client1
->GetUserName(), client2
->GetUserName() );
1918 // Sort by status (size field)
1920 return CmpAny( client1
->GetDownloadState(), client2
->GetDownloadState() );
1922 // Sort by transferred in the following fields
1925 return CmpAny( client1
->GetTransferredDown(), client2
->GetTransferredDown() );
1929 return CmpAny( client1
->GetKBpsDown(), client2
->GetKBpsDown() );
1931 // Sort by parts offered (Progress field)
1934 client1
->GetAvailablePartCount(),
1935 client2
->GetAvailablePartCount() );
1937 // Sort by client version
1939 if (client1
->GetClientSoft() != client2
->GetClientSoft()) {
1940 return client1
->GetSoftStr().Cmp(client2
->GetSoftStr());
1943 if (client1
->GetVersion() != client2
->GetVersion()) {
1944 return CmpAny(client1
->GetVersion(), client2
->GetVersion());
1947 return client1
->GetClientModString().Cmp(client2
->GetClientModString());
1950 // Sort by Queue-Rank
1952 // This will sort by download state: Downloading, OnQueue, Connecting ...
1953 // However, Asked For Another will always be placed last, due to
1954 // sorting in SortProc
1955 if ( client1
->GetDownloadState() != client2
->GetDownloadState() ) {
1956 return client1
->GetDownloadState() - client2
->GetDownloadState();
1959 // Placing items on queue before items on full queues
1960 if ( client1
->IsRemoteQueueFull() ) {
1961 if ( client2
->IsRemoteQueueFull() ) {
1966 } else if ( client2
->IsRemoteQueueFull() ) {
1969 if ( client1
->GetRemoteQueueRank() ) {
1970 if ( client2
->GetRemoteQueueRank() ) {
1972 client1
->GetRemoteQueueRank(),
1973 client2
->GetRemoteQueueRank() );
1978 if ( client2
->GetRemoteQueueRank() ) {
1989 if (client1
->GetDownloadState() == client2
->GetDownloadState()) {
1991 client1
->IsRemoteQueueFull(),
1992 client2
->IsRemoteQueueFull() );
1995 client1
->GetDownloadState(),
1996 client2
->GetDownloadState() );
2000 // Source of source ;)
2002 return CmpAny(client1
->GetSourceFrom(), client2
->GetSourceFrom());
2010 void CDownloadListCtrl::ClearCompleted()
2012 m_completedFiles
= false;
2013 CastByID(ID_BTNCLRCOMPL
, GetParent(), wxButton
)->Enable(false);
2015 // Search for completed files
2016 for ( ListItems::iterator it
= m_ListItems
.begin(); it
!= m_ListItems
.end(); ) {
2017 CtrlItem_Struct
* item
= it
->second
; ++it
;
2019 if ( item
->GetType() == FILE_TYPE
) {
2020 CPartFile
* file
= item
->GetFile();
2022 if ( file
->IsPartFile() == false ) {
2030 void CDownloadListCtrl::ShowFilesCount( int diff
)
2032 m_filecount
+= diff
;
2034 wxString str
= wxString::Format( _("Downloads (%i)"), m_filecount
);
2035 wxStaticText
* label
= CastByName( wxT("downloadsLabel"), GetParent(), wxStaticText
);
2037 label
->SetLabel( str
);
2038 label
->GetParent()->Layout();
2044 bool CDownloadListCtrl::ShowItemInCurrentCat(
2045 const CPartFile
* file
, int newsel
) const
2048 ((newsel
== 0 && !thePrefs::ShowAllNotCats()) ||
2049 (newsel
== 0 && thePrefs::ShowAllNotCats() && file
->GetCategory() == 0)) ||
2050 (newsel
> 0 && newsel
== file
->GetCategory());
2055 void CDownloadListCtrl::DrawFileStatusBar(
2056 const CPartFile
* file
, wxDC
* dc
, const wxRect
& rect
, bool bFlat
) const
2058 static CBarShader
s_ChunkBar(16);
2060 COLORREF crHave
= ( bFlat
? RGB( 0, 0, 0 ) : RGB( 104, 104, 104 ) );
2061 COLORREF crPending
= ( bFlat
? RGB( 255, 255, 100 ) : RGB( 255, 208, 0 ) );
2062 COLORREF crProgress
= ( bFlat
? RGB( 0, 150, 0 ) : RGB( 0, 224, 0 ) );
2063 COLORREF crMissing
= RGB(255, 0, 0);
2065 s_ChunkBar
.SetHeight(rect
.height
);
2066 s_ChunkBar
.SetWidth(rect
.width
);
2067 s_ChunkBar
.SetFileSize( file
->GetFileSize() );
2068 s_ChunkBar
.Set3dDepth( thePrefs::Get3DDepth() );
2071 if ( file
->GetStatus() == PS_COMPLETE
|| file
->GetStatus() == PS_COMPLETING
) {
2072 s_ChunkBar
.Fill( crProgress
);
2073 s_ChunkBar
.Draw(dc
, rect
.x
, rect
.y
, bFlat
);
2078 // Part availability ( of missing parts )
2079 const CPartFile::CGapPtrList
& gaplist
= file
->GetGapList();
2080 CPartFile::CGapPtrList::const_iterator it
= gaplist
.begin();
2081 uint64 lastGapEnd
= 0;
2082 for (; it
!= gaplist
.end(); ++it
) {
2083 Gap_Struct
* gap
= *it
;
2086 uint32 start
= ( gap
->start
/ PARTSIZE
);
2087 // fill the Have-Part (between this gap and the last)
2089 s_ChunkBar
.FillRange(lastGapEnd
+ 1, gap
->start
- 1, crHave
);
2091 lastGapEnd
= gap
->end
;
2093 uint32 end
= ( gap
->end
/ PARTSIZE
) + 1;
2095 // Avoid going past the filesize. Dunno if this can happen, but the old code did check.
2096 if ( end
> file
->GetPartCount() ) {
2097 end
= file
->GetPartCount();
2100 // Place each gap, one PART at a time
2101 for ( uint64 i
= start
; i
< end
; ++i
) {
2103 if ( i
< file
->m_SrcpartFrequency
.size() && file
->m_SrcpartFrequency
[i
]) {
2104 int blue
= 210 - ( 22 * ( file
->m_SrcpartFrequency
[i
] - 1 ) );
2105 color
= RGB( 0, ( blue
< 0 ? 0 : blue
), 255 );
2110 if ( file
->IsStopped() ) {
2111 color
= DarkenColour( color
, 2 );
2114 uint64 gap_begin
= ( i
== start
? gap
->start
: PARTSIZE
* i
);
2115 uint64 gap_end
= ( i
== end
- 1 ? gap
->end
: PARTSIZE
* ( i
+ 1 ) - 1 );
2117 s_ChunkBar
.FillRange( gap_begin
, gap_end
, color
);
2120 // fill the last Have-Part (between this gap and the last)
2121 s_ChunkBar
.FillRange(lastGapEnd
+ 1, file
->GetFileSize() - 1, crHave
);
2125 const CPartFile::CReqBlockPtrList
& requestedblocks_list
= file
->GetRequestedBlockList();
2126 CPartFile::CReqBlockPtrList::const_iterator it2
= requestedblocks_list
.begin();
2127 // adjacing pending parts must be joined to avoid bright lines between them
2128 uint64 lastStartOffset
= 0;
2129 uint64 lastEndOffset
= 0;
2130 COLORREF color
= file
->IsStopped() ? DarkenColour( crPending
, 2 ) : crPending
;
2131 for (; it2
!= requestedblocks_list
.end(); ++it2
) {
2133 if ((*it2
)->StartOffset
> lastEndOffset
+ 1) {
2134 // not adjacing, draw last block
2135 s_ChunkBar
.FillRange(lastStartOffset
, lastEndOffset
, color
);
2136 lastStartOffset
= (*it2
)->StartOffset
;
2137 lastEndOffset
= (*it2
)->EndOffset
;
2139 // adjacing, grow block
2140 lastEndOffset
= (*it2
)->EndOffset
;
2143 s_ChunkBar
.FillRange(lastStartOffset
, lastEndOffset
, color
);
2146 // Draw the progress-bar
2147 s_ChunkBar
.Draw( dc
, rect
.x
, rect
.y
, bFlat
);
2150 // Green progressbar width
2151 int width
= (int)(( (float)rect
.width
/ (float)file
->GetFileSize() ) *
2152 file
->GetCompletedSize() );
2155 dc
->SetBrush( wxBrush( crProgress
, wxSOLID
) );
2157 dc
->DrawRectangle( rect
.x
, rect
.y
, width
, 3 );
2159 // Draw the two black lines for 3d-effect
2160 dc
->SetPen( wxPen( wxColour( 0, 0, 0 ), 1, wxSOLID
) );
2161 dc
->DrawLine( rect
.x
, rect
.y
+ 0, rect
.x
+ width
, rect
.y
+ 0 );
2162 dc
->DrawLine( rect
.x
, rect
.y
+ 2, rect
.x
+ width
, rect
.y
+ 2 );
2164 // Draw the green line
2165 dc
->SetPen( wxPen( crProgress
, 1, wxSOLID
) );
2166 dc
->DrawLine( rect
.x
, rect
.y
+ 1, rect
.x
+ width
, rect
.y
+ 1 );
2171 void CDownloadListCtrl::DrawSourceStatusBar(
2172 const CUpDownClient
* source
, wxDC
* dc
, const wxRect
& rect
, bool bFlat
) const
2174 static CBarShader
s_StatusBar(16);
2176 uint32 crBoth
= ( bFlat
? RGB( 0, 150, 0 ) : RGB( 0, 192, 0 ) );
2177 uint32 crNeither
= ( bFlat
? RGB( 224, 224, 224 ) : RGB( 240, 240, 240 ) );
2178 uint32 crClientOnly
= ( bFlat
? RGB( 0, 0, 0 ) : RGB( 104, 104, 104 ) );
2179 uint32 crPending
= ( bFlat
? RGB( 255, 208, 0 ) : RGB( 255, 208, 0 ) );
2180 uint32 crNextPending
= ( bFlat
? RGB( 255, 255, 100 ) : RGB( 255, 255, 100 ) );
2182 CPartFile
* reqfile
= source
->GetRequestFile();
2184 s_StatusBar
.SetFileSize( reqfile
->GetFileSize() );
2185 s_StatusBar
.SetHeight(rect
.height
);
2186 s_StatusBar
.SetWidth(rect
.width
);
2187 s_StatusBar
.Set3dDepth( thePrefs::Get3DDepth() );
2189 // Barry - was only showing one part from client, even when reserved bits from 2 parts
2190 wxString gettingParts
= source
->ShowDownloadingParts();
2192 const BitVector
& partStatus
= source
->GetPartStatus();
2195 for ( uint64 i
= 0; i
< partStatus
.size(); i
++ ) {
2196 uint64 uStart
= PARTSIZE
* i
;
2197 uEnd
= wxMin(reqfile
->GetFileSize(), uStart
+ PARTSIZE
) - 1;
2200 if (!partStatus
[i
]) {
2202 } else if ( reqfile
->IsComplete(uStart
, uEnd
)) {
2204 } else if ( source
->GetDownloadState() == DS_DOWNLOADING
&&
2205 source
->GetLastBlockOffset() <= uEnd
&&
2206 source
->GetLastBlockOffset() >= uStart
) {
2208 } else if (gettingParts
.GetChar((uint16
)i
) == 'Y') {
2209 color
= crNextPending
;
2211 color
= crClientOnly
;
2214 if ( source
->GetRequestFile()->IsStopped() ) {
2215 color
= DarkenColour( color
, 2 );
2218 s_StatusBar
.FillRange(uStart
, uEnd
, color
);
2220 // fill the rest (if partStatus is empty)
2221 s_StatusBar
.FillRange(uEnd
+ 1, reqfile
->GetFileSize() - 1, crNeither
);
2223 s_StatusBar
.Draw(dc
, rect
.x
, rect
.y
, bFlat
);
2227 # define QUOTE wxT("\"")
2229 # define QUOTE wxT("\'")
2232 void CDownloadListCtrl::PreviewFile(CPartFile
* file
)
2235 // If no player set in preferences, use mplayer.
2236 // And please, do a warning also :P
2237 if (thePrefs::GetVideoPlayer().IsEmpty()) {
2239 "Please set your preferred video player on preferences.\nMeanwhile, aMule will attempt to use mplayer and you will get this warning on every preview"),
2240 _("File preview"), wxOK
, this);
2241 // Since newer versions for some reason mplayer does not automatically
2242 // select video output device and needs a parameter, go figure...
2243 command
= wxT("xterm -T \"aMule Preview\" -iconic -e mplayer ") QUOTE
wxT("$file") QUOTE
;
2245 command
= thePrefs::GetVideoPlayer();
2248 // Check if we are (pre)viewing a completed file or not
2249 if (file
->GetStatus() != PS_COMPLETE
) {
2250 // Remove the .met and see if out video player specifiation uses the magic string
2251 wxString fileWithoutMet
= thePrefs::GetTempDir().JoinPaths(
2252 file
->GetPartMetFileName().RemoveExt()).GetRaw();
2253 if (!command
.Replace(wxT("$file"), fileWithoutMet
)) {
2254 // No magic string, so we just append the filename to the player command
2255 // Need to use quotes in case filename contains spaces
2256 command
<< wxT(" ") << QUOTE
<< fileWithoutMet
<< QUOTE
;
2259 // This is a complete file
2260 // FIXME: This is probably not going to work if the filenames are mangled ...
2261 wxString rawFileName
= file
->GetFullName().GetRaw();
2262 if (!command
.Replace(wxT("$file"), rawFileName
)) {
2263 // No magic string, so we just append the filename to the player command
2264 // Need to use quotes in case filename contains spaces
2265 command
<< wxT(" ") << QUOTE
<< rawFileName
<< QUOTE
;
2269 // We can't use wxShell here, it blocks the app
2270 CTerminationProcess
*p
= new CTerminationProcess(command
);
2271 int ret
= wxExecute(command
, wxEXEC_ASYNC
, p
);
2276 CFormat( _("ERROR: Failed to execute external media-player! Command: `%s'") ) %
2280 // File_checked_for_headers