This repository was archived by the owner on Jul 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathChunkPanel.cpp
More file actions
56 lines (51 loc) · 1.57 KB
/
ChunkPanel.cpp
File metadata and controls
56 lines (51 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "ChunkPanel.hpp"
#include "common.hpp"
BEGIN_EVENT_TABLE(ChunkPanel, wxPanel)
EVT_BUTTON(ID_DeleteChunks, ChunkPanel::on_delete)
END_EVENT_TABLE()
ChunkPanel::ChunkPanel(wxWindow* parent, MetalinkEditor& editor)
: wxPanel(parent), editor_(editor)
{
create_widgets();
update();
}
void ChunkPanel::create_widgets()
{
// Create widgets
label1_ = new wxStaticText(this, wxID_ANY, wxT(""));
btn_delete_ = new wxButton(this, ID_DeleteChunks, wxT("Delete chunks"));
// Layout
wxBoxSizer* sizer2 = new wxBoxSizer(wxHORIZONTAL);
sizer2->Add(btn_delete_, 0, 0);
wxBoxSizer* sizer1 = new wxBoxSizer(wxVERTICAL);
sizer1->Add(label1_, 0, wxEXPAND | wxALL, 5);
sizer1->Add(sizer2, 0, wxEXPAND | wxALL, 5);
SetSizerAndFit(sizer1);
Layout();
}
void ChunkPanel::update()
{
MetalinkFile file = editor_.get_file();
long num = file.get_piece_hashes().size();
if(num == 0) {
label1_->SetLabel(wxT("This file has no chunk checksums."));
btn_delete_->Enable(false);
} else {
wxString type = file.get_piece_hash_type();
wxString msg;
msg << wxT("This file has ") << num;
msg << wxT(" chunk checksum");
if(num > 1) {
msg << wxT("s");
}
msg << wxT(" of type '") << type << wxT("'.");
label1_->SetLabel(msg);
btn_delete_->Enable(true);
}
}
void ChunkPanel::on_delete(wxCommandEvent& WXUNUSED(event))
{
MetalinkFile file = editor_.get_file();
file.set_piece_hash(wxT(""), 0, std::vector<wxString>());
editor_.set_file(file);
}