Added papirus skin and minor debian fixes
[amule.git] / src / PartFileConvertDlg.cpp
bloba082b95dbf3cdffeab11bf40eb0cef26ebaf3688
1 //
2 // This file is part of the aMule Project.
3 //
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 )
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.
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;
41 #ifndef __WINDOWS__
42 /* XPM */
43 static const char * convert_xpm[] = {
44 "16 16 9 1",
45 " c None",
46 ". c #B20000",
47 "+ c #FF0000",
48 "@ c #FF7F7F",
49 "# c #008000",
50 "$ c #33B200",
51 "% c #10E500",
52 "& c #59FE4C",
53 "* c #FFB2B2",
54 " . ",
55 " .+. ",
56 " .+@+. ",
57 " .+@+. ",
58 ". .+@+.#######",
59 ".. .+@+. #$%%&#",
60 ".+.+@+. #$%%#",
61 ".@+@+. #$%$%#",
62 ".@@+. #$%$#$#",
63 ".*@@+. #$%$# ##",
64 ".......#$%$# #",
65 " #$%$# ",
66 " #$%$# ",
67 " #$%$# ",
68 " #$# ",
69 " # "};
70 #endif /* ! __WINDOWS__ */
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)
81 END_EVENT_TABLE()
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));
98 #ifdef CLIENT_GUI
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);
104 #endif
107 // Static methods
109 void CPartFileConvertDlg::ShowGUI(wxWindow* parent)
111 if (s_convertgui) {
112 s_convertgui->Show(true);
113 s_convertgui->Raise();
114 } else {
115 s_convertgui = new CPartFileConvertDlg(parent);
116 s_convertgui->Show(true);
117 Notify_ConvertReaddAllJobs();
121 void CPartFileConvertDlg::CloseGUI()
123 if (s_convertgui) {
124 s_convertgui->Show(false);
125 s_convertgui->Destroy();
126 s_convertgui = NULL;
130 void CPartFileConvertDlg::UpdateProgress(float percent, wxString text, wxString header)
132 if (s_convertgui) {
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()
152 if (s_convertgui) {
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)
162 if (s_convertgui) {
163 // search jobitem in listctrl
164 long itemnr = s_convertgui->m_joblist->FindItem(-1, info.id);
165 // if it does not exist, add it
166 if (itemnr == -1) {
167 itemnr = s_convertgui->m_joblist->InsertItem(s_convertgui->m_joblist->GetItemCount(), info.folder.GetPrintable());
168 if (itemnr != -1) {
169 s_convertgui->m_joblist->SetItemData(itemnr, info.id);
172 // update columns
173 if (itemnr != -1) {
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) );
176 if (info.size > 0) {
177 s_convertgui->m_joblist->SetItem(itemnr, 2, CFormat(_("%s (Disk: %s)")) % CastItoXBytes(info.size) % CastItoXBytes(info.spaceneeded));
178 } else {
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)
188 if (s_convertgui) {
189 long itemnr = s_convertgui->m_joblist->FindItem(-1, id);
190 if (itemnr != -1) {
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))
218 CloseGUI();
221 void CPartFileConvertDlg::OnCloseButton(wxCommandEvent& WXUNUSED(event))
223 CloseGUI();
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);