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 "PartFileConvertDlg.h"
28 #include <common/Format.h>
29 #include <common/Path.h>
30 #include "DataToText.h"
31 #include "OtherFunctions.h"
32 #include "PartFileConvert.h"
33 #include "GuiEvents.h"
35 #include <wx/stdpaths.h>
36 #include "muuli_wdr.h"
38 CPartFileConvertDlg
* CPartFileConvertDlg::s_convertgui
= NULL
;
43 static const char * convert_xpm
[] = {
70 #endif /* ! __WXMSW__ */
72 // Modeless Dialog Implementation
73 // CPartFileConvertDlg dialog
75 BEGIN_EVENT_TABLE(CPartFileConvertDlg
, wxDialog
)
77 EVT_BUTTON(IDC_ADDITEM
, CPartFileConvertDlg::OnAddFolder
)
79 EVT_BUTTON(IDC_RETRY
, CPartFileConvertDlg::RetrySel
)
80 EVT_BUTTON(IDC_CONVREMOVE
, CPartFileConvertDlg::RemoveSel
)
81 EVT_BUTTON(wxID_CANCEL
, CPartFileConvertDlg::OnCloseButton
)
82 EVT_CLOSE(CPartFileConvertDlg::OnClose
)
85 CPartFileConvertDlg::CPartFileConvertDlg(wxWindow
* parent
)
86 : wxDialog(parent
, -1, _("Import partfiles"), wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
)
88 convertDlg(this, true, true);
90 m_joblist
= CastChild(IDC_JOBLIST
, wxListCtrl
);
91 m_pb_current
= CastChild(IDC_CONV_PB_CURRENT
, wxGauge
);
93 m_joblist
->InsertColumn(0, _("File name"), wxLIST_FORMAT_LEFT
, 200);
94 m_joblist
->InsertColumn(1, _("State"), wxLIST_FORMAT_LEFT
, 100);
95 m_joblist
->InsertColumn(2, _("Size"), wxLIST_FORMAT_LEFT
, 100);
96 m_joblist
->InsertColumn(3, _("Filehash"), wxLIST_FORMAT_LEFT
, 100);
98 SetIcon(wxICON(convert
));
101 // There's no remote directory browser (yet)
102 CastChild(IDC_ADDITEM
, wxButton
)->Enable(false);
108 void CPartFileConvertDlg::ShowGUI(wxWindow
* parent
)
111 s_convertgui
->Show(true);
112 s_convertgui
->Raise();
114 s_convertgui
= new CPartFileConvertDlg(parent
);
115 s_convertgui
->Show(true);
116 Notify_ConvertReaddAllJobs();
120 void CPartFileConvertDlg::CloseGUI()
123 s_convertgui
->Show(false);
124 s_convertgui
->Destroy();
129 void CPartFileConvertDlg::UpdateProgress(float percent
, wxString text
, wxString header
)
132 s_convertgui
->m_pb_current
->SetValue((int)percent
);
133 wxString buffer
= wxString::Format(wxT("%.2f %%"), percent
);
134 wxStaticText
* percentlabel
= dynamic_cast<wxStaticText
*>(s_convertgui
->FindWindow(IDC_CONV_PROZENT
));
135 percentlabel
->SetLabel(buffer
);
137 if (!text
.IsEmpty()) {
138 dynamic_cast<wxStaticText
*>(s_convertgui
->FindWindow(IDC_CONV_PB_LABEL
))->SetLabel(text
);
141 percentlabel
->GetParent()->Layout();
143 if (!header
.IsEmpty()) {
144 dynamic_cast<wxStaticBoxSizer
*>(IDC_CURJOB
)->GetStaticBox()->SetLabel(header
);
149 void CPartFileConvertDlg::ClearInfo()
152 dynamic_cast<wxStaticBoxSizer
*>(IDC_CURJOB
)->GetStaticBox()->SetLabel(_("Waiting..."));
153 dynamic_cast<wxStaticText
*>(s_convertgui
->FindWindow(IDC_CONV_PROZENT
))->SetLabel(wxEmptyString
);
154 s_convertgui
->m_pb_current
->SetValue(0);
155 dynamic_cast<wxStaticText
*>(s_convertgui
->FindWindow(IDC_CONV_PB_LABEL
))->SetLabel(wxEmptyString
);
159 void CPartFileConvertDlg::UpdateJobInfo(ConvertInfo
& info
)
162 // search jobitem in listctrl
163 long itemnr
= s_convertgui
->m_joblist
->FindItem(-1, info
.id
);
164 // if it does not exist, add it
166 itemnr
= s_convertgui
->m_joblist
->InsertItem(s_convertgui
->m_joblist
->GetItemCount(), info
.folder
.GetPrintable());
168 s_convertgui
->m_joblist
->SetItemData(itemnr
, info
.id
);
173 s_convertgui
->m_joblist
->SetItem(itemnr
, 0, info
.filename
.IsOk() ? info
.folder
.GetPrintable() : info
.filename
.GetPrintable() );
174 s_convertgui
->m_joblist
->SetItem(itemnr
, 1, GetConversionState(info
.state
) );
176 s_convertgui
->m_joblist
->SetItem(itemnr
, 2, CFormat(_("%s (Disk: %s)")) % CastItoXBytes(info
.size
) % CastItoXBytes(info
.spaceneeded
));
178 s_convertgui
->m_joblist
->SetItem(itemnr
, 2, wxEmptyString
);
180 s_convertgui
->m_joblist
->SetItem(itemnr
, 3, info
.filehash
);
185 void CPartFileConvertDlg::RemoveJobInfo(unsigned id
)
188 long itemnr
= s_convertgui
->m_joblist
->FindItem(-1, id
);
190 s_convertgui
->m_joblist
->DeleteItem(itemnr
);
195 // CPartFileConvertDlg message handlers
198 void CPartFileConvertDlg::OnAddFolder(wxCommandEvent
& WXUNUSED(event
))
200 // TODO: use MuleRemoteDirSelector
201 wxString folder
= ::wxDirSelector(
202 _("Please choose a folder to search for temporary downloads! (subfolders will be included)"),
203 wxStandardPaths::Get().GetDocumentsDir(), wxDD_DEFAULT_STYLE
,
204 wxDefaultPosition
, this);
205 if (!folder
.IsEmpty()) {
206 int reply
= wxMessageBox(_("Do you want the source files of succesfully imported downloads be deleted?"),
207 _("Remove sources?"),
208 wxYES_NO
| wxCANCEL
| wxICON_QUESTION
, this);
209 if (reply
!= wxCANCEL
) {
210 // TODO: use notification
211 CPartFileConvert::ScanFolderToAdd(CPath(folder
), (reply
== wxYES
));
217 void CPartFileConvertDlg::OnClose(wxCloseEvent
& WXUNUSED(event
))
222 void CPartFileConvertDlg::OnCloseButton(wxCommandEvent
& WXUNUSED(event
))
227 void CPartFileConvertDlg::RemoveSel(wxCommandEvent
& WXUNUSED(event
))
229 if (m_joblist
->GetSelectedItemCount() == 0) return;
231 long itemnr
= m_joblist
->GetNextItem(-1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
232 while (itemnr
!= -1) {
233 Notify_ConvertRemoveJob(m_joblist
->GetItemData(itemnr
));
234 itemnr
= m_joblist
->GetNextItem(itemnr
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
238 void CPartFileConvertDlg::RetrySel(wxCommandEvent
& WXUNUSED(event
))
240 if (m_joblist
->GetSelectedItemCount() == 0) return;
242 long itemnr
= m_joblist
->GetNextItem(-1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
243 while (itemnr
!= -1) {
244 Notify_ConvertRetryJob(m_joblist
->GetItemData(itemnr
));
245 itemnr
= m_joblist
->GetNextItem(itemnr
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);