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 "SharedFilesCtrl.h" // Interface declarations
28 #include <common/MenuIDs.h>
30 #include "muuli_wdr.h" // Needed for ID_SHFILELIST
31 #include "SharedFilesWnd.h" // Needed for CSharedFilesWnd
32 #include "amuleDlg.h" // Needed for CamuleDlg
33 #include "CommentDialog.h" // Needed for CCommentDialog
34 #include "PartFile.h" // Needed for CPartFile
35 #include "SharedFileList.h" // Needed for CKnownFileMap
36 #include "amule.h" // Needed for theApp
37 #include "ServerConnect.h" // Needed for CServerConnect
38 #include "Preferences.h" // Needed for thePrefs
39 #include "BarShader.h" // Needed for CBarShader
40 #include "DataToText.h" // Needed for PriorityToStr
41 #include "GuiEvents.h" // Needed for CoreNotify_*
42 #include "MuleCollection.h" // Needed for CMuleCollection
43 #include "DownloadQueue.h" // Needed for CDownloadQueue
44 #include "TransferWnd.h" // Needed for CTransferWnd
47 BEGIN_EVENT_TABLE(CSharedFilesCtrl
,CMuleListCtrl
)
48 EVT_LIST_ITEM_RIGHT_CLICK(-1, CSharedFilesCtrl::OnRightClick
)
50 EVT_MENU( MP_PRIOVERYLOW
, CSharedFilesCtrl::OnSetPriority
)
51 EVT_MENU( MP_PRIOLOW
, CSharedFilesCtrl::OnSetPriority
)
52 EVT_MENU( MP_PRIONORMAL
, CSharedFilesCtrl::OnSetPriority
)
53 EVT_MENU( MP_PRIOHIGH
, CSharedFilesCtrl::OnSetPriority
)
54 EVT_MENU( MP_PRIOVERYHIGH
, CSharedFilesCtrl::OnSetPriority
)
55 EVT_MENU( MP_POWERSHARE
, CSharedFilesCtrl::OnSetPriority
)
56 EVT_MENU( MP_PRIOAUTO
, CSharedFilesCtrl::OnSetPriorityAuto
)
58 EVT_MENU( MP_CMT
, CSharedFilesCtrl::OnEditComment
)
59 EVT_MENU( MP_ADDCOLLECTION
, CSharedFilesCtrl::OnAddCollection
)
60 EVT_MENU( MP_GETMAGNETLINK
, CSharedFilesCtrl::OnCreateURI
)
61 EVT_MENU( MP_GETED2KLINK
, CSharedFilesCtrl::OnCreateURI
)
62 EVT_MENU( MP_GETSOURCEED2KLINK
, CSharedFilesCtrl::OnCreateURI
)
63 EVT_MENU( MP_GETCRYPTSOURCEDED2KLINK
, CSharedFilesCtrl::OnCreateURI
)
64 EVT_MENU( MP_GETHOSTNAMESOURCEED2KLINK
, CSharedFilesCtrl::OnCreateURI
)
65 EVT_MENU( MP_GETHOSTNAMECRYPTSOURCEED2KLINK
, CSharedFilesCtrl::OnCreateURI
)
66 EVT_MENU( MP_GETAICHED2KLINK
, CSharedFilesCtrl::OnCreateURI
)
67 EVT_MENU( MP_RENAME
, CSharedFilesCtrl::OnRename
)
68 EVT_MENU( MP_WS
, CSharedFilesCtrl::OnGetFeedback
)
71 EVT_CHAR( CSharedFilesCtrl::OnKeyPressed
)
74 enum SharedFilesListColumns
{
75 ID_SHARED_COL_NAME
= 0,
90 CSharedFilesCtrl::CSharedFilesCtrl(wxWindow
* parent
, int id
, const wxPoint
& pos
, wxSize size
, int flags
)
91 : CMuleListCtrl(parent
, id
, pos
, size
, flags
| wxLC_OWNERDRAW
)
93 // Setting the sorter function.
94 SetSortFunc( SortProc
);
96 // Set the table-name (for loading and saving preferences).
97 SetTableName( wxT("Shared") );
101 InsertColumn(ID_SHARED_COL_NAME
, _("File Name"), wxLIST_FORMAT_LEFT
, 250, wxT("N") );
102 InsertColumn(ID_SHARED_COL_SIZE
, _("Size"), wxLIST_FORMAT_LEFT
, 100, wxT("Z") );
103 InsertColumn(ID_SHARED_COL_TYPE
, _("Type"), wxLIST_FORMAT_LEFT
, 50, wxT("Y") );
104 InsertColumn(ID_SHARED_COL_PRIO
, _("Priority"), wxLIST_FORMAT_LEFT
, 70, wxT("p") );
105 InsertColumn(ID_SHARED_COL_ID
, _("FileID"), wxLIST_FORMAT_LEFT
, 220, wxT("I") );
106 InsertColumn(ID_SHARED_COL_REQ
, _("Requests"), wxLIST_FORMAT_LEFT
, 100, wxT("Q") );
107 InsertColumn(ID_SHARED_COL_AREQ
, _("Accepted Requests"), wxLIST_FORMAT_LEFT
, 100, wxT("A") );
108 InsertColumn(ID_SHARED_COL_TRA
, _("Transferred Data"), wxLIST_FORMAT_LEFT
, 120, wxT("T") );
109 InsertColumn(ID_SHARED_COL_RTIO
, _("Share Ratio"), wxLIST_FORMAT_LEFT
, 100, wxT("R") );
110 InsertColumn(ID_SHARED_COL_PART
, _("Obtained Parts"), wxLIST_FORMAT_LEFT
, 120, wxT("P") );
111 InsertColumn(ID_SHARED_COL_CMPL
, _("Complete Sources"), wxLIST_FORMAT_LEFT
, 120, wxT("C") );
112 InsertColumn(ID_SHARED_COL_PATH
, _("Directory Path"), wxLIST_FORMAT_LEFT
, 220, wxT("D") );
118 wxString
CSharedFilesCtrl::GetOldColumnOrder() const
120 return wxT("N,Z,Y,p,I,Q,A,T,R,P,C,D");
124 CSharedFilesCtrl::~CSharedFilesCtrl()
129 void CSharedFilesCtrl::OnRightClick(wxListEvent
& event
)
131 long item_hit
= CheckSelection(event
);
133 if ( (m_menu
== NULL
) && (item_hit
!= -1)) {
134 m_menu
= new wxMenu(_("Shared Files"));
135 wxMenu
* prioMenu
= new wxMenu();
136 prioMenu
->AppendCheckItem(MP_PRIOVERYLOW
, _("Very low"));
137 prioMenu
->AppendCheckItem(MP_PRIOLOW
, _("Low"));
138 prioMenu
->AppendCheckItem(MP_PRIONORMAL
, _("Normal"));
139 prioMenu
->AppendCheckItem(MP_PRIOHIGH
, _("High"));
140 prioMenu
->AppendCheckItem(MP_PRIOVERYHIGH
, _("Very High"));
141 prioMenu
->AppendCheckItem(MP_POWERSHARE
, _("Release"));
142 prioMenu
->AppendCheckItem(MP_PRIOAUTO
, _("Auto"));
144 m_menu
->Append(0,_("Priority"),prioMenu
);
145 m_menu
->AppendSeparator();
147 CKnownFile
* file
= (CKnownFile
*)GetItemData(item_hit
);
148 if (file
->GetFileComment().IsEmpty() && !file
->GetFileRating()) {
149 m_menu
->Append(MP_CMT
, _("Add Comment/Rating"));
151 m_menu
->Append(MP_CMT
, _("Edit Comment/Rating"));
154 m_menu
->AppendSeparator();
155 m_menu
->Append(MP_RENAME
, _("Rename"));
156 m_menu
->AppendSeparator();
158 if (file
->GetFileName().GetExt() == wxT("emulecollection")) {
159 m_menu
->Append( MP_ADDCOLLECTION
, _("Add files in collection to transfer list"));
160 m_menu
->AppendSeparator();
162 m_menu
->Append(MP_GETMAGNETLINK
,_("Copy magnet &URI to clipboard"));
163 m_menu
->Append(MP_GETED2KLINK
,_("Copy eD2k &link to clipboard"));
164 m_menu
->Append(MP_GETSOURCEED2KLINK
,_("Copy eD2k link to clipboard (&Source)"));
165 m_menu
->Append(MP_GETCRYPTSOURCEDED2KLINK
,_("Copy eD2k link to clipboard (Source) (&With Crypt options)"));
166 m_menu
->Append(MP_GETHOSTNAMESOURCEED2KLINK
,_("Copy eD2k link to clipboard (&Hostname)"));
167 m_menu
->Append(MP_GETHOSTNAMECRYPTSOURCEED2KLINK
,_("Copy eD2k link to clipboard (Hostname) (With &Crypt options)"));
168 m_menu
->Append(MP_GETAICHED2KLINK
,_("Copy eD2k link to clipboard (&AICH info)"));
169 m_menu
->Append(MP_WS
,_("Copy feedback to clipboard"));
171 m_menu
->Enable(MP_GETAICHED2KLINK
, file
->HasProperAICHHashSet());
172 m_menu
->Enable(MP_GETHOSTNAMESOURCEED2KLINK
, !thePrefs::GetYourHostname().IsEmpty());
173 m_menu
->Enable(MP_GETHOSTNAMECRYPTSOURCEED2KLINK
, !thePrefs::GetYourHostname().IsEmpty());
175 int priority
= file
->IsAutoUpPriority() ? PR_AUTO
: file
->GetUpPriority();
177 prioMenu
->Check(MP_PRIOVERYLOW
, priority
== PR_VERYLOW
);
178 prioMenu
->Check(MP_PRIOLOW
, priority
== PR_LOW
);
179 prioMenu
->Check(MP_PRIONORMAL
, priority
== PR_NORMAL
);
180 prioMenu
->Check(MP_PRIOHIGH
, priority
== PR_HIGH
);
181 prioMenu
->Check(MP_PRIOVERYHIGH
,priority
== PR_VERYHIGH
);
182 prioMenu
->Check(MP_POWERSHARE
, priority
== PR_POWERSHARE
);
183 prioMenu
->Check(MP_PRIOAUTO
, priority
== PR_AUTO
);
185 PopupMenu( m_menu
, event
.GetPoint() );
194 void CSharedFilesCtrl::OnGetFeedback(wxCommandEvent
& WXUNUSED(event
))
197 long index
= GetNextItem(-1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
198 while (index
!= -1) {
199 if (feed
.IsEmpty()) {
200 feed
= CFormat(_("Feedback from: %s (%s)\n\n")) % thePrefs::GetUserNick() % theApp
->GetFullMuleVersion();
204 feed
+= ((CKnownFile
*)GetItemData(index
))->GetFeedback();
205 index
= GetNextItem(index
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
208 if (!feed
.IsEmpty()) {
209 theApp
->CopyTextToClipboard(feed
);
215 void CSharedFilesCtrl::ShowFileList()
220 std::vector
<CKnownFile
*> files
;
221 theApp
->sharedfiles
->CopyFileList(files
);
222 for (unsigned i
= 0; i
< files
.size(); ++i
) {
223 DoShowFile(files
[i
], true);
234 void CSharedFilesCtrl::RemoveFile(CKnownFile
*toRemove
)
236 long index
= FindItem( -1, reinterpret_cast<wxUIntPtr
>(toRemove
) );
246 void CSharedFilesCtrl::ShowFile(CKnownFile
* file
)
248 DoShowFile(file
, false);
252 void CSharedFilesCtrl::DoShowFile(CKnownFile
* file
, bool batch
)
254 wxUIntPtr ptr
= reinterpret_cast<wxUIntPtr
>(file
);
255 if ((!batch
) && (FindItem(-1, ptr
) > -1)) {
259 const long insertPos
= (batch
? GetItemCount() : GetInsertPos(ptr
));
261 long newitem
= InsertItem(insertPos
, wxEmptyString
);
262 SetItemPtrData( newitem
, ptr
);
269 void CSharedFilesCtrl::OnSetPriority( wxCommandEvent
& event
)
273 switch ( event
.GetId() ) {
274 case MP_PRIOVERYLOW
: priority
= PR_VERYLOW
; break;
275 case MP_PRIOLOW
: priority
= PR_LOW
; break;
276 case MP_PRIONORMAL
: priority
= PR_NORMAL
; break;
277 case MP_PRIOHIGH
: priority
= PR_HIGH
; break;
278 case MP_PRIOVERYHIGH
: priority
= PR_VERYHIGH
; break;
279 case MP_POWERSHARE
: priority
= PR_POWERSHARE
; break;
282 long index
= GetNextItem( -1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
284 while( index
!= -1 ) {
285 CKnownFile
* file
= (CKnownFile
*)GetItemData( index
);
286 CoreNotify_KnownFile_Up_Prio_Set( file
, priority
);
288 RefreshItem( index
);
290 index
= GetNextItem( index
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
295 void CSharedFilesCtrl::OnSetPriorityAuto( wxCommandEvent
& WXUNUSED(event
) )
297 long index
= GetNextItem( -1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
299 while( index
!= -1 ) {
300 CKnownFile
* file
= (CKnownFile
*)GetItemData( index
);
301 CoreNotify_KnownFile_Up_Prio_Auto(file
);
303 RefreshItem( index
);
305 index
= GetNextItem( index
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
310 void CSharedFilesCtrl::OnCreateURI( wxCommandEvent
& event
)
314 if ( event
.GetId() == MP_GETSOURCEED2KLINK
|| event
.GetId() == MP_GETCRYPTSOURCEDED2KLINK
) {
315 if ( !( (theApp
->IsConnectedED2K() && !theApp
->serverconnect
->IsLowID())
316 || (theApp
->IsConnectedKad() && !theApp
->IsFirewalledKad() ))) {
317 wxMessageBox(_("You need a HighID to create a valid sourcelink"), _("WARNING"), wxOK
| wxICON_ERROR
, this);
322 long index
= GetNextItem( -1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
324 while( index
!= -1 ) {
325 CKnownFile
* file
= (CKnownFile
*)GetItemData( index
);
327 switch ( event
.GetId() ) {
328 case MP_GETMAGNETLINK
: URIs
+= theApp
->CreateMagnetLink( file
) + wxT("\n"); break;
329 case MP_GETED2KLINK
: URIs
+= theApp
->CreateED2kLink( file
) + wxT("\n"); break;
330 case MP_GETSOURCEED2KLINK
: URIs
+= theApp
->CreateED2kLink( file
, true) + wxT("\n"); break;
331 case MP_GETCRYPTSOURCEDED2KLINK
: URIs
+= theApp
->CreateED2kLink( file
, true, false, true) + wxT("\n"); break;
332 case MP_GETHOSTNAMESOURCEED2KLINK
: URIs
+= theApp
->CreateED2kLink( file
, true, true) + wxT("\n"); break;
333 case MP_GETHOSTNAMECRYPTSOURCEED2KLINK
: URIs
+= theApp
->CreateED2kLink( file
, true, true, true ) + wxT("\n"); break;
334 case MP_GETAICHED2KLINK
: URIs
+= theApp
->CreateED2kAICHLink( file
) + wxT("\n"); break;
337 index
= GetNextItem( index
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
340 if ( !URIs
.IsEmpty() ) {
341 theApp
->CopyTextToClipboard( URIs
.RemoveLast() );
346 void CSharedFilesCtrl::OnEditComment( wxCommandEvent
& WXUNUSED(event
) )
348 long index
= GetNextItem( -1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
351 CKnownFile
* file
= (CKnownFile
*)GetItemData( index
);
353 CCommentDialog
dialog( this, file
);
360 int CSharedFilesCtrl::SortProc(wxUIntPtr item1
, wxUIntPtr item2
, long sortData
)
362 CKnownFile
* file1
= (CKnownFile
*)item1
;
363 CKnownFile
* file2
= (CKnownFile
*)item2
;
365 int mod
= (sortData
& CMuleListCtrl::SORT_DES
) ? -1 : 1;
366 bool altSorting
= (sortData
& CMuleListCtrl::SORT_ALT
) > 0;
368 switch (sortData
& CMuleListCtrl::COLUMN_MASK
) {
370 case ID_SHARED_COL_NAME
:
371 return mod
* CmpAny(file1
->GetFileName(), file2
->GetFileName());
374 case ID_SHARED_COL_SIZE
:
375 return mod
* CmpAny( file1
->GetFileSize(), file2
->GetFileSize() );
378 case ID_SHARED_COL_TYPE
:
379 return mod
* GetFiletypeByName(file1
->GetFileName()).CmpNoCase(GetFiletypeByName( file2
->GetFileName()) );
382 case ID_SHARED_COL_PRIO
: {
383 int8 prioA
= file1
->GetUpPriority();
384 int8 prioB
= file2
->GetUpPriority();
386 // Work-around for PR_VERYLOW which has value 4. See KnownFile.h for that stupidity ...
387 return mod
* CmpAny( ( prioB
!= PR_VERYLOW
? prioB
: -1 ), ( prioA
!= PR_VERYLOW
? prioA
: -1 ) );
391 case ID_SHARED_COL_ID
:
392 return mod
* file1
->GetFileHash().Encode().Cmp( file2
->GetFileHash().Encode() );
394 // Sort by Requests this session.
395 case ID_SHARED_COL_REQ
:
397 return mod
* CmpAny( file1
->statistic
.GetAllTimeRequests(), file2
->statistic
.GetAllTimeRequests() );
399 return mod
* CmpAny( file1
->statistic
.GetRequests(), file2
->statistic
.GetRequests() );
402 // Sort by accepted requests. Ascending.
403 case ID_SHARED_COL_AREQ
:
405 return mod
* CmpAny( file1
->statistic
.GetAllTimeAccepts(), file2
->statistic
.GetAllTimeAccepts() );
407 return mod
* CmpAny( file1
->statistic
.GetAccepts(), file2
->statistic
.GetAccepts() );
410 // Sort by transferred. Ascending.
411 case ID_SHARED_COL_TRA
:
413 return mod
* CmpAny( file1
->statistic
.GetAllTimeTransferred(), file2
->statistic
.GetAllTimeTransferred() );
415 return mod
* CmpAny( file1
->statistic
.GetTransferred(), file2
->statistic
.GetTransferred() );
418 // Sort by Share Ratio. Ascending.
419 case ID_SHARED_COL_RTIO
:
420 return mod
* CmpAny( (double)file1
->statistic
.GetAllTimeTransferred() / file1
->GetFileSize(),
421 (double)file2
->statistic
.GetAllTimeTransferred() / file2
->GetFileSize() );
423 // Complete sources asc
424 case ID_SHARED_COL_CMPL
:
425 return mod
* CmpAny( file1
->m_nCompleteSourcesCount
, file2
->m_nCompleteSourcesCount
);
428 case ID_SHARED_COL_PATH
: {
429 if ( file1
->IsPartFile() && file2
->IsPartFile() )
431 if ( file1
->IsPartFile() )
433 if ( file2
->IsPartFile() )
436 return mod
* CmpAny(file1
->GetFilePath(), file2
->GetFilePath());
445 void CSharedFilesCtrl::UpdateItem(CKnownFile
* toupdate
)
447 long result
= FindItem( -1, reinterpret_cast<wxUIntPtr
>(toupdate
) );
452 if ( GetItemState( result
, wxLIST_STATE_SELECTED
) ) {
453 theApp
->amuledlg
->m_sharedfileswnd
->SelectionUpdated();
459 void CSharedFilesCtrl::ShowFilesCount()
461 wxStaticText
* label
= CastByName( wxT("sharedFilesLabel"), GetParent(), wxStaticText
);
463 label
->SetLabel(CFormat(_("Shared Files (%i)")) % GetItemCount());
464 label
->GetParent()->Layout();
465 // If file list was updated, the "selection" is involved too, if we chose to show clients for all files.
466 // So update client list here too.
467 theApp
->amuledlg
->m_sharedfileswnd
->SelectionUpdated();
471 void CSharedFilesCtrl::OnDrawItem( int item
, wxDC
* dc
, const wxRect
& rect
, const wxRect
& rectHL
, bool highlighted
)
473 CKnownFile
*file
= (CKnownFile
*)GetItemData(item
);
477 CMuleColour
newcol(GetFocus() ? wxSYS_COLOUR_HIGHLIGHT
: wxSYS_COLOUR_BTNSHADOW
);
478 dc
->SetBackground(newcol
.Blend(125).GetBrush());
479 dc
->SetTextForeground( CMuleColour(wxSYS_COLOUR_HIGHLIGHTTEXT
));
480 // The second blending goes over the first one.
481 dc
->SetPen(newcol
.Blend(65).GetPen());
483 dc
->SetBackground( CMuleColour(wxSYS_COLOUR_LISTBOX
).GetBrush() );
484 dc
->SetTextForeground(CMuleColour(wxSYS_COLOUR_WINDOWTEXT
));
485 dc
->SetPen(*wxTRANSPARENT_PEN
);
488 dc
->SetBrush(dc
->GetBackground());
489 dc
->DrawRectangle(rectHL
);
490 dc
->SetPen(*wxTRANSPARENT_PEN
);
492 // Offset based on the height of the fonts
493 const int textVOffset
= ( rect
.GetHeight() - dc
->GetCharHeight() ) / 2;
494 // Empty space to each side of a column
495 const int SPARE_PIXELS_HORZ
= 4;
497 // The leftmost position of the current column
500 for ( int i
= 0; i
< GetColumnCount(); ++i
) {
501 const int columnWidth
= GetColumnWidth(i
);
503 if (columnWidth
> 2*SPARE_PIXELS_HORZ
) {
505 columnLeft
+ SPARE_PIXELS_HORZ
, rect
.y
,
506 columnWidth
- 2 * SPARE_PIXELS_HORZ
, rect
.height
);
508 wxDCClipper
clipper(*dc
, columnRect
);
512 case ID_SHARED_COL_NAME
:
513 textBuffer
= file
->GetFileName().GetPrintable();
515 if (file
->GetFileRating() || file
->GetFileComment().Length()) {
516 int image
= Client_CommentOnly_Smiley
;
517 if (file
->GetFileRating()) {
518 image
= Client_InvalidRating_Smiley
+ file
->GetFileRating() - 1;
521 wxASSERT(image
>= Client_InvalidRating_Smiley
);
522 wxASSERT(image
<= Client_CommentOnly_Smiley
);
526 theApp
->amuledlg
->m_imagelist
.Draw(image
, *dc
, columnRect
.x
,
527 columnRect
.y
+ 1, wxIMAGELIST_DRAW_TRANSPARENT
);
529 // Move the text to the right
530 columnRect
.x
+= (imgWidth
+ 4);
535 case ID_SHARED_COL_SIZE
:
536 textBuffer
= CastItoXBytes(file
->GetFileSize());
539 case ID_SHARED_COL_TYPE
:
540 textBuffer
= GetFiletypeByName(file
->GetFileName());
543 case ID_SHARED_COL_PRIO
:
544 textBuffer
= PriorityToStr(file
->GetUpPriority(), file
->IsAutoUpPriority());
547 case ID_SHARED_COL_ID
:
548 textBuffer
= file
->GetFileHash().Encode();
551 case ID_SHARED_COL_REQ
:
552 textBuffer
= CFormat(wxT("%u (%u)"))
553 % file
->statistic
.GetRequests()
554 % file
->statistic
.GetAllTimeRequests();
557 case ID_SHARED_COL_AREQ
:
558 textBuffer
= CFormat(wxT("%u (%u)"))
559 % file
->statistic
.GetAccepts()
560 % file
->statistic
.GetAllTimeAccepts();
563 case ID_SHARED_COL_TRA
:
564 textBuffer
= CastItoXBytes(file
->statistic
.GetTransferred())
565 + wxT(" (") + CastItoXBytes(file
->statistic
.GetAllTimeTransferred()) + wxT(")");
568 case ID_SHARED_COL_RTIO
:
569 textBuffer
= CFormat(wxT("%.2f")) % ((double)file
->statistic
.GetAllTimeTransferred() / file
->GetFileSize());
572 case ID_SHARED_COL_PART
:
573 if ( file
->GetPartCount() ) {
574 wxRect
barRect(columnRect
.x
, columnRect
. y
+ 1,
575 columnRect
.width
, columnRect
.height
- 2);
577 DrawAvailabilityBar(file
, dc
, barRect
);
581 case ID_SHARED_COL_CMPL
:
582 if ( file
->m_nCompleteSourcesCountLo
== 0 ) {
583 if ( file
->m_nCompleteSourcesCountHi
) {
584 textBuffer
= CFormat(wxT("< %u")) % file
->m_nCompleteSourcesCountHi
;
586 textBuffer
= wxT("0");
588 } else if (file
->m_nCompleteSourcesCountLo
== file
->m_nCompleteSourcesCountHi
) {
589 textBuffer
= CFormat(wxT("%u")) % file
->m_nCompleteSourcesCountLo
;
591 textBuffer
= CFormat(wxT("%u - %u")) % file
->m_nCompleteSourcesCountLo
% file
->m_nCompleteSourcesCountHi
;
596 case ID_SHARED_COL_PATH
:
597 if ( file
->IsPartFile() ) {
598 textBuffer
= _("[PartFile]");
600 textBuffer
= file
->GetFilePath().GetPrintable();
604 if (!textBuffer
.IsEmpty()) {
605 dc
->DrawText(textBuffer
, columnRect
.x
, columnRect
.y
+ textVOffset
);
609 // Move to the next column
610 columnLeft
+= columnWidth
;
615 wxString
CSharedFilesCtrl::GetTTSText(unsigned item
) const
617 return reinterpret_cast<CKnownFile
*>(GetItemData(item
))->GetFileName().GetPrintable();
621 bool CSharedFilesCtrl::AltSortAllowed(unsigned column
) const
624 case ID_SHARED_COL_REQ
:
625 case ID_SHARED_COL_AREQ
:
626 case ID_SHARED_COL_TRA
:
635 void CSharedFilesCtrl::DrawAvailabilityBar(CKnownFile
* file
, wxDC
* dc
, const wxRect
& rect
) const
637 // Reference to the availability list
638 const ArrayOfUInts16
& list
= file
->IsPartFile() ?
639 ((CPartFile
*)file
)->m_SrcpartFrequency
:
640 file
->m_AvailPartFrequency
;
641 wxPen old_pen
= dc
->GetPen();
642 wxBrush old_brush
= dc
->GetBrush();
643 bool bFlat
= thePrefs::UseFlatBar();
645 wxRect barRect
= rect
;
646 if (!bFlat
) { // round bar has a black border, the bar itself is 1 pixel less on each border
652 static CBarShader s_ChunkBar
;
653 s_ChunkBar
.SetFileSize( file
->GetFileSize() );
654 s_ChunkBar
.SetHeight( barRect
.GetHeight() );
655 s_ChunkBar
.SetWidth( barRect
.GetWidth() );
656 s_ChunkBar
.Set3dDepth( CPreferences::Get3DDepth() );
658 for ( unsigned int i
= 0; i
< list
.size(); ++i
) {
659 uint64 start
= PARTSIZE
* static_cast<uint64
>(i
);
660 end
= PARTSIZE
* static_cast<uint64
>(i
+ 1);
661 s_ChunkBar
.FillRange(start
, end
, CMuleColour(list
[i
] ? 0 : 255, list
[i
] ? ((210-(22*( list
[i
] - 1 ) ) < 0) ? 0 : (210-(22*( list
[i
] - 1 ) ))) : 0, list
[i
] ? 255 : 0));
663 s_ChunkBar
.FillRange(end
+ 1, file
->GetFileSize() - 1, CMuleColour(255, 0, 0));
664 s_ChunkBar
.Draw(dc
, barRect
.x
, barRect
.y
, bFlat
);
668 dc
->SetPen( *wxBLACK_PEN
);
669 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
670 dc
->DrawRectangle(rect
);
673 dc
->SetPen( old_pen
);
674 dc
->SetBrush( old_brush
);
677 void CSharedFilesCtrl::OnRename( wxCommandEvent
& WXUNUSED(event
) )
679 int item
= GetNextItem( -1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
681 CKnownFile
* file
= (CKnownFile
*)GetItemData(item
);
683 wxString strNewName
= ::wxGetTextFromUser(
684 _("Enter new name for this file:"),
685 _("File rename"), file
->GetFileName().GetPrintable());
687 CPath newName
= CPath(strNewName
);
688 if (newName
.IsOk() && (newName
!= file
->GetFileName())) {
689 theApp
->sharedfiles
->RenameFile(file
, newName
);
695 void CSharedFilesCtrl::OnKeyPressed( wxKeyEvent
& event
)
697 if (event
.GetKeyCode() == WXK_F2
) {
707 void CSharedFilesCtrl::OnAddCollection( wxCommandEvent
& WXUNUSED(evt
) )
709 int item
= GetNextItem( -1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
711 CKnownFile
*file
= (CKnownFile
*)GetItemData(item
);
712 wxString CollectionFile
= file
->GetFilePath().JoinPaths(file
->GetFileName()).GetRaw();
713 CMuleCollection my_collection
;
714 if (my_collection
.Open( (std::string
)CollectionFile
.mb_str() )) {
715 //#warning This is probably not working on Unicode
716 for (size_t e
= 0; e
< my_collection
.GetFileCount(); ++e
) {
717 theApp
->downloadqueue
->AddLink(
718 wxString(my_collection
.GetEd2kLink(e
).c_str(), wxConvUTF8
));
725 // File_checked_for_headers