Upstream tarball 20080609
[amule.git] / src / CommentDialogLst.cpp
blob194fb2d7de390f51ca681299c0e56933a056e884
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 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
26 #include "CommentDialogLst.h" // Interface declarations
27 #include "muuli_wdr.h" // Needed for commentLstDlg
28 #include "PartFile.h" // Needed for CPartFile
29 #include <common/Format.h> // Needed for CFormat
30 #include "MuleListCtrl.h" // Needed for CMuleListCtrl
31 #include "Preferences.h"
32 #include "amule.h" // Needed for theApp
36 BEGIN_EVENT_TABLE(CCommentDialogLst,wxDialog)
37 EVT_BUTTON(IDCOK,CCommentDialogLst::OnBnClickedApply)
38 EVT_BUTTON(IDCREF,CCommentDialogLst::OnBnClickedRefresh)
39 END_EVENT_TABLE()
43 * Constructor
45 CCommentDialogLst::CCommentDialogLst(wxWindow*parent, CPartFile* file)
47 wxDialog(parent, -1, wxString(_("File Comments")),
48 wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),
49 m_file(file)
51 wxSizer* content = commentLstDlg(this, true);
52 content->Show(this, true);
54 m_list = CastChild(IDC_LST, CMuleListCtrl);
55 m_list->InsertColumn(0, _("Username"), wxLIST_FORMAT_LEFT, 130);
56 m_list->InsertColumn(1, _("File Name"), wxLIST_FORMAT_LEFT, 130);
57 m_list->InsertColumn(2, _("Rating"), wxLIST_FORMAT_LEFT, 80);
58 m_list->InsertColumn(3, _("Comment"), wxLIST_FORMAT_LEFT, 340);
59 m_list->SetSortFunc(SortProc);
61 UpdateList();
65 CCommentDialogLst::~CCommentDialogLst()
67 ClearList();
71 void CCommentDialogLst::OnBnClickedApply(wxCommandEvent& WXUNUSED(evt))
73 EndModal(0);
77 void CCommentDialogLst::OnBnClickedRefresh(wxCommandEvent& WXUNUSED(evt))
79 UpdateList();
83 void CCommentDialogLst::UpdateList()
85 int count = 0;
86 ClearList();
88 const FileRatingList &list = m_file->GetRatingAndComments();
89 for (FileRatingList::const_iterator it = list.begin(); it != list.end(); ++it) {
90 if (!thePrefs::IsCommentFiltered(it->Comment)) {
91 m_list->InsertItem(count, it->UserName);
92 m_list->SetItem(count, 1, it->FileName);
93 m_list->SetItem(count, 2, (it->Rating != -1) ? GetRateString(it->Rating) : wxString(wxT("on")));
94 m_list->SetItem(count, 3, it->Comment);
95 m_list->SetItemPtrData(count, reinterpret_cast<wxUIntPtr>(new SFileRating(*it)));
96 ++count;
100 wxString info;
101 if (count == 0) {
102 info = _("No comments");
103 } else {
104 info = wxString::Format(wxPLURAL("%u comment", "%u comments", count), count);
107 FindWindow(IDC_CMSTATUS)->SetLabel(info);
108 FindWindow(IDC_CMSTATUS)->GetParent()->Layout();
110 m_file->UpdateFileRatingCommentAvail();
114 void CCommentDialogLst::ClearList()
116 size_t count = m_list->GetItemCount();
117 for (size_t i = 0; i < count; ++i) {
118 delete (SFileRating*)m_list->GetItemData(i);
121 m_list->DeleteAllItems();
125 int CCommentDialogLst::SortProc(wxUIntPtr item1, wxUIntPtr item2, long sortData)
127 SFileRating* file1 = (SFileRating*)item1;
128 SFileRating* file2 = (SFileRating*)item2;
130 int mod = (sortData & CMuleListCtrl::SORT_DES) ? -1 : 1;
132 switch (sortData & CMuleListCtrl::COLUMN_MASK) {
133 case 0: return mod * file1->UserName.Cmp(file2->UserName);
134 case 1: return mod * file1->FileName.Cmp(file2->FileName);
135 case 2: return mod * (file1->Rating - file2->Rating);
136 case 3: return mod * file1->Comment.Cmp(file2->Comment);
137 default:
138 return 0;
141 // File_checked_for_headers