2 // This file is part of the aMule Project.
4 // Copyright (c) 2003-2011 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
)
76 EVT_BUTTON(IDC_ADDITEM
, CPartFileConvertDlg::OnAddFolder
)
77 EVT_BUTTON(IDC_RETRY
, CPartFileConvertDlg::RetrySel
)
78 EVT_BUTTON(IDC_CONVREMOVE
, CPartFileConvertDlg::RemoveSel
)
79 EVT_BUTTON(wxID_CANCEL
, CPartFileConvertDlg::OnCloseButton
)
80 EVT_CLOSE(CPartFileConvertDlg::OnClose
)
83 CPartFileConvertDlg::CPartFileConvertDlg(wxWindow
* parent
)
84 : wxDialog(parent
, -1, _("Import partfiles"), wxDefaultPosition
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
)
86 convertDlg(this, true, true);
88 m_joblist
= CastChild(IDC_JOBLIST
, wxListCtrl
);
89 m_pb_current
= CastChild(IDC_CONV_PB_CURRENT
, wxGauge
);
91 m_joblist
->InsertColumn(0, _("File name"), wxLIST_FORMAT_LEFT
, 200);
92 m_joblist
->InsertColumn(1, _("State"), wxLIST_FORMAT_LEFT
, 100);
93 m_joblist
->InsertColumn(2, _("Size"), wxLIST_FORMAT_LEFT
, 100);
94 m_joblist
->InsertColumn(3, _("Filehash"), wxLIST_FORMAT_LEFT
, 100);
96 SetIcon(wxICON(convert
));
99 // There's no remote directory browser (yet), thus disable the
100 // directory selector unless we're using a localhost connection
101 if (!theApp
->m_connect
->IsConnectedToLocalHost()) {
102 CastChild(IDC_ADDITEM
, wxButton
)->Enable(false);
109 void CPartFileConvertDlg::ShowGUI(wxWindow
* parent
)
112 s_convertgui
->Show(true);
113 s_convertgui
->Raise();
115 s_convertgui
= new CPartFileConvertDlg(parent
);
116 s_convertgui
->Show(true);
117 Notify_ConvertReaddAllJobs();
121 void CPartFileConvertDlg::CloseGUI()
124 s_convertgui
->Show(false);
125 s_convertgui
->Destroy();
130 void CPartFileConvertDlg::UpdateProgress(float percent
, wxString text
, wxString header
)
133 s_convertgui
->m_pb_current
->SetValue((int)percent
);
134 wxString buffer
= CFormat(wxT("%.2f %%")) % percent
;
135 wxStaticText
* percentlabel
= dynamic_cast<wxStaticText
*>(s_convertgui
->FindWindow(IDC_CONV_PROZENT
));
136 percentlabel
->SetLabel(buffer
);
138 if (!text
.IsEmpty()) {
139 dynamic_cast<wxStaticText
*>(s_convertgui
->FindWindow(IDC_CONV_PB_LABEL
))->SetLabel(text
);
142 percentlabel
->GetParent()->Layout();
144 if (!header
.IsEmpty()) {
145 dynamic_cast<wxStaticBoxSizer
*>(IDC_CURJOB
)->GetStaticBox()->SetLabel(header
);
150 void CPartFileConvertDlg::ClearInfo()
153 dynamic_cast<wxStaticBoxSizer
*>(IDC_CURJOB
)->GetStaticBox()->SetLabel(_("Waiting..."));
154 dynamic_cast<wxStaticText
*>(s_convertgui
->FindWindow(IDC_CONV_PROZENT
))->SetLabel(wxEmptyString
);
155 s_convertgui
->m_pb_current
->SetValue(0);
156 dynamic_cast<wxStaticText
*>(s_convertgui
->FindWindow(IDC_CONV_PB_LABEL
))->SetLabel(wxEmptyString
);
160 void CPartFileConvertDlg::UpdateJobInfo(ConvertInfo
& info
)
163 // search jobitem in listctrl
164 long itemnr
= s_convertgui
->m_joblist
->FindItem(-1, info
.id
);
165 // if it does not exist, add it
167 itemnr
= s_convertgui
->m_joblist
->InsertItem(s_convertgui
->m_joblist
->GetItemCount(), info
.folder
.GetPrintable());
169 s_convertgui
->m_joblist
->SetItemData(itemnr
, info
.id
);
174 s_convertgui
->m_joblist
->SetItem(itemnr
, 0, info
.filename
.IsOk() ? info
.folder
.GetPrintable() : info
.filename
.GetPrintable() );
175 s_convertgui
->m_joblist
->SetItem(itemnr
, 1, GetConversionState(info
.state
) );
177 s_convertgui
->m_joblist
->SetItem(itemnr
, 2, CFormat(_("%s (Disk: %s)")) % CastItoXBytes(info
.size
) % CastItoXBytes(info
.spaceneeded
));
179 s_convertgui
->m_joblist
->SetItem(itemnr
, 2, wxEmptyString
);
181 s_convertgui
->m_joblist
->SetItem(itemnr
, 3, info
.filehash
);
186 void CPartFileConvertDlg::RemoveJobInfo(unsigned id
)
189 long itemnr
= s_convertgui
->m_joblist
->FindItem(-1, id
);
191 s_convertgui
->m_joblist
->DeleteItem(itemnr
);
196 // 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
));
216 void CPartFileConvertDlg::OnClose(wxCloseEvent
& WXUNUSED(event
))
221 void CPartFileConvertDlg::OnCloseButton(wxCommandEvent
& WXUNUSED(event
))
226 void CPartFileConvertDlg::RemoveSel(wxCommandEvent
& WXUNUSED(event
))
228 if (m_joblist
->GetSelectedItemCount() == 0) return;
230 long itemnr
= m_joblist
->GetNextItem(-1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
231 while (itemnr
!= -1) {
232 Notify_ConvertRemoveJob(m_joblist
->GetItemData(itemnr
));
233 itemnr
= m_joblist
->GetNextItem(itemnr
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
237 void CPartFileConvertDlg::RetrySel(wxCommandEvent
& WXUNUSED(event
))
239 if (m_joblist
->GetSelectedItemCount() == 0) return;
241 long itemnr
= m_joblist
->GetNextItem(-1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
242 while (itemnr
!= -1) {
243 Notify_ConvertRetryJob(m_joblist
->GetItemData(itemnr
));
244 itemnr
= m_joblist
->GetNextItem(itemnr
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);