Upstream tarball 10153
[amule.git] / src / CommentDialogLst.cpp
blob4ef2979e2ddb4721e189e24e5ba0c29b5972530c
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
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 FileRatingList list;
89 m_file->GetRatingAndComments(list);
90 for (FileRatingList::const_iterator it = list.begin(); it != list.end(); ++it) {
91 if (!thePrefs::IsCommentFiltered(it->Comment)) {
92 m_list->InsertItem(count, it->UserName);
93 m_list->SetItem(count, 1, it->FileName);
94 m_list->SetItem(count, 2, (it->Rating != -1) ? GetRateString(it->Rating) : wxString(wxT("on")));
95 m_list->SetItem(count, 3, it->Comment);
96 m_list->SetItemPtrData(count, reinterpret_cast<wxUIntPtr>(new SFileRating(*it)));
97 ++count;
101 wxString info;
102 if (count == 0) {
103 info = _("No comments");
104 } else {
105 info = wxString::Format(wxPLURAL("%u comment", "%u comments", count), count);
108 FindWindow(IDC_CMSTATUS)->SetLabel(info);
109 FindWindow(IDC_CMSTATUS)->GetParent()->Layout();
111 m_file->UpdateFileRatingCommentAvail();
115 void CCommentDialogLst::ClearList()
117 size_t count = m_list->GetItemCount();
118 for (size_t i = 0; i < count; ++i) {
119 delete (SFileRating*)m_list->GetItemData(i);
122 m_list->DeleteAllItems();
126 int CCommentDialogLst::SortProc(wxUIntPtr item1, wxUIntPtr item2, long sortData)
128 SFileRating* file1 = (SFileRating*)item1;
129 SFileRating* file2 = (SFileRating*)item2;
131 int mod = (sortData & CMuleListCtrl::SORT_DES) ? -1 : 1;
133 switch (sortData & CMuleListCtrl::COLUMN_MASK) {
134 case 0: return mod * file1->UserName.Cmp(file2->UserName);
135 case 1: return mod * file1->FileName.Cmp(file2->FileName);
136 case 2: return mod * (file1->Rating - file2->Rating);
137 case 3: return mod * file1->Comment.Cmp(file2->Comment);
138 default:
139 return 0;
142 // File_checked_for_headers