Hungarian translation update by Imre herceg (FS #6888)
[Rockbox.git] / rbutil / rbutilCtrls.cpp
blob007bd6e17d531650f4f1b92bfeb495ccff37ffc9
2 #include "rbutilCtrls.h"
3 #include "bootloaders.h"
5 /////////////////////////////////////////////////////////////
6 //// Controls
7 ////////////////////////////////////////////////////////////////
9 /////////////////////////////////////////////
10 //// Image Ctrl
11 //////////////////////////////////////////////
13 BEGIN_EVENT_TABLE(ImageCtrl, wxControl)
14 EVT_PAINT(ImageCtrl::OnPaint)
15 END_EVENT_TABLE()
17 IMPLEMENT_DYNAMIC_CLASS(ImageCtrl, wxControl)
19 bool ImageCtrl::Create(wxWindow* parent, wxWindowID id,
20 const wxPoint& pos, const wxSize& size, long style,
21 const wxValidator& validator)
23 if (!wxControl::Create(parent, id, pos, size, style, validator)) return false;
25 return true;
28 void ImageCtrl::OnPaint(wxPaintEvent& event)
30 wxPaintDC dc(this);
31 dc.DrawBitmap(m_bitmap,0,0,false);
34 void ImageCtrl::SetBitmap(wxBitmap bmp)
36 m_bitmap = bmp;
37 Refresh();
41 wxSize ImageCtrl::DoGetBestSize() const
43 wxSize bestsize;
44 bestsize.x = m_bitmap.GetWidth();
45 bestsize.y = m_bitmap.GetHeight();
46 return bestsize;
51 /////////////////////////////////////////////
52 //// Theme Control
53 //////////////////////////////////////////////
55 BEGIN_EVENT_TABLE(ThemeCtrl, wxControl)
56 EVT_LISTBOX(ID_THEME_LST, ThemeCtrl::OnThemesLst)
57 END_EVENT_TABLE()
59 IMPLEMENT_DYNAMIC_CLASS(ThemeCtrl, wxControl)
61 bool ThemeCtrl::Create(wxWindow* parent, wxWindowID id,
62 const wxPoint& pos, const wxSize& size, long style,
63 const wxValidator& validator)
65 if (!wxControl::Create(parent, id, pos, size, style, validator)) return false;
67 CreateControls();
69 GetSizer()->Fit(this);
71 GetSizer()->SetSizeHints(this);
72 return true;
75 void ThemeCtrl::CreateControls()
77 // A top-level sizer
78 wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
79 this->SetSizer(topSizer);
81 wxBoxSizer* horizontalSizer = new wxBoxSizer(wxHORIZONTAL);
82 topSizer->Add(horizontalSizer, 0, wxALIGN_LEFT|wxALL, 5);
84 //Device Selection
85 wxBoxSizer* wxBoxSizer7 = new wxBoxSizer(wxVERTICAL);
86 horizontalSizer->Add(wxBoxSizer7,0,wxGROW | wxALL,0);
88 wxStaticText* m_desc = new wxStaticText( this, wxID_STATIC,
89 wxT("Select one or more Themes to install"), wxDefaultPosition,
90 wxDefaultSize, 0 );
91 wxBoxSizer7->Add(m_desc, 0, wxALIGN_LEFT|wxALL, 5);
93 m_themeList = new wxListBox(this,ID_THEME_LST,wxDefaultPosition,
94 wxDefaultSize,0,NULL,wxLB_EXTENDED);
95 wxBoxSizer7->Add(m_themeList, 0, wxALIGN_LEFT|wxALL, 5);
97 // Preview Picture
98 wxBoxSizer* wxBoxSizer9 = new wxBoxSizer(wxVERTICAL);
99 horizontalSizer->Add(wxBoxSizer9,0,wxGROW | wxALL,0);
101 wxStaticText* preview_desc= new wxStaticText(this,wxID_ANY,wxT("Preview:"));
102 wxBoxSizer9->Add(preview_desc,0,wxGROW | wxALL,5);
104 m_PreviewBitmap = new ImageCtrl(this,ID_PREVIEW_BITMAP );
105 wxBoxSizer9->Add(m_PreviewBitmap,0,wxALIGN_LEFT | wxALL,5);
107 wxStaticBox* groupbox= new wxStaticBox(this,wxID_ANY,wxT("Selected Theme:"));
108 wxStaticBoxSizer* styleSizer = new wxStaticBoxSizer( groupbox, wxVERTICAL );
109 topSizer->Add(styleSizer,0,wxGROW|wxALL,0);
111 // horizontal sizer
112 wxBoxSizer* wxBoxSizer8 = new wxBoxSizer(wxHORIZONTAL);
113 styleSizer->Add(wxBoxSizer8,0,wxGROW | wxALL,0);
115 // File size
116 wxStaticText* size_desc= new wxStaticText(this,wxID_ANY,wxT("Filesize:"));
117 wxBoxSizer8->Add(size_desc,0,wxGROW | wxALL,5);
119 m_size= new wxStaticText(this,ID_FILESIZE,wxT(""));
120 wxBoxSizer8->Add(m_size,0,wxGROW | wxALL,5);
122 // Description
123 wxStaticText* desc_desc= new wxStaticText(this,wxID_ANY,wxT("Description:"));
124 styleSizer->Add(desc_desc,0,wxGROW | wxALL,5);
126 m_themedesc= new wxTextCtrl(this,ID_DESC,wxT(""),wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY);
127 styleSizer->Add(m_themedesc,0,wxGROW | wxALL,5);
129 topSizer->Fit(this);
130 topSizer->SetSizeHints(this);
131 Layout();
135 void ThemeCtrl::Init()
137 m_Themes.Clear();
138 m_Themes_path.Clear();
139 m_Themes_size.Clear();
140 m_Themes_image.Clear();
141 m_Themes_desc.Clear();
145 void ThemeCtrl::setDevice(wxString device)
148 int index = gv->plat_id.Index(device);
149 if(index == -1) return;
151 if(gv->plat_resolution[index] == m_currentResolution)
152 return;
153 else
154 m_currentResolution = gv->plat_resolution[index];
156 // load the themelist
157 Init();
158 m_size->SetLabel(wxT(""));
159 m_themedesc->SetValue(wxT(""));
160 m_themeList->Clear();
162 //get correct Themes list
163 wxString src,dest,err;
165 src.Printf(wxT("%srbutil.php?res=%s"),gv->themes_url.c_str(),m_currentResolution.c_str());
166 dest.Printf(wxT("%s" PATH_SEP "download" PATH_SEP "%s.list"),
167 gv->stdpaths->GetUserDataDir().c_str(),m_currentResolution.c_str());
169 if(DownloadURL(src, dest))
171 MESG_DIALOG(wxT("Unable to download themes list."));
172 return;
175 //read and parse Themes list
176 wxString themelistraw;
177 wxFFile themefile;
178 if(!themefile.Open(dest)) //open file
180 MESG_DIALOG(wxT("Unable to open themes list."));
181 return;
183 if(!themefile.ReadAll(&themelistraw)) //read complete file
185 MESG_DIALOG(wxT("Unable to read themes list."));
186 return;
188 wxRegEx reAll(wxT("<body >(.+)</body>")); //extract body part
189 if(! reAll.Matches(themelistraw))
191 MESG_DIALOG(wxT("Themes list is in wrong Format."));
192 return;
194 wxString lines = reAll.GetMatch(themelistraw,1);
196 // prepare text
197 lines.Replace(wxT("<br />"),wxT(""),true); //replace <br /> with nothing
198 lines.Replace(wxT("\n"),wxT(""),true); //replace \n with nothing
199 lines.Trim(true); //strip WS at end
200 lines.Trim(false); //strip WS at beginning
201 wxStringTokenizer tkz(lines,wxT("|")); //tokenize it
203 while ( tkz.HasMoreTokens() ) // read all entrys
205 m_Themes.Add(tkz.GetNextToken()); //Theme name
206 m_Themes_path.Add(tkz.GetNextToken()); //Theme path
207 m_Themes_size.Add(tkz.GetNextToken()); //File size
208 m_Themes_image.Add(tkz.GetNextToken()); //Screenshot
209 m_Themes_desc.Add(tkz.GetNextToken()); //Description
211 m_themeList->Append(m_Themes.Last());
214 this->GetSizer()->Layout();
215 this->GetSizer()->Fit(this);
216 this->GetSizer()->SetSizeHints(this);
217 m_parent->GetSizer()->Layout();
218 m_parent->GetSizer()->Fit(m_parent);
219 m_parent->GetSizer()->SetSizeHints(m_parent);
223 void ThemeCtrl::OnThemesLst(wxCommandEvent& event)
225 // wxCriticalSectionLocker locker(m_ThemeSelectSection);
227 wxArrayInt selected;
228 int numSelected = m_themeList->GetSelections(selected);
229 if(numSelected == 0) return;
231 int index = selected[0];
233 m_size->SetLabel(m_Themes_size[index]);
234 m_themedesc->SetValue(m_Themes_desc[index]);
235 // m_themedesc->Wrap(200); // wrap desc
237 wxString src,dest;
239 int pos = m_Themes_image[index].Find('/',true);
240 wxString filename = m_Themes_image[index](pos+1,m_Themes_image[index].Length());
242 dest.Printf(wxT("%s" PATH_SEP "download" PATH_SEP "%s"),
243 gv->stdpaths->GetUserDataDir().c_str(),m_currentResolution.c_str());
245 if(!wxDirExists(dest))
246 wxMkdir(dest);
248 //this is a URL no PATH_SEP
249 src.Printf(wxT("%s/data/%s/%s"),gv->themes_url.c_str(),m_currentResolution.c_str(),filename.c_str());
250 dest.Printf(wxT("%s" PATH_SEP "download" PATH_SEP "%s" PATH_SEP "%s"),
251 gv->stdpaths->GetUserDataDir().c_str(),m_currentResolution.c_str(),filename.c_str());
253 if(DownloadURL(src, dest))
255 MESG_DIALOG(wxT("Unable to download image."));
256 return;
259 m_currentimage = dest;
260 wxBitmap bmp;
261 bmp.LoadFile(m_currentimage,wxBITMAP_TYPE_PNG);
262 m_PreviewBitmap->SetBitmap(bmp);
264 Refresh();
265 this->GetSizer()->Layout();
266 this->GetSizer()->Fit(this);
267 this->GetSizer()->SetSizeHints(this);
269 m_parent->GetSizer()->Layout();
270 m_parent->GetSizer()->Fit(m_parent);
271 m_parent->GetSizer()->SetSizeHints(m_parent);
276 wxArrayString ThemeCtrl::getThemesToInstall()
278 wxArrayString themes;
279 wxArrayInt selected;
280 int numSelected = m_themeList->GetSelections(selected);
282 for(int i=0; i < numSelected; i++)
284 themes.Add(m_Themes_path[selected[i]]);
286 return themes;
290 /////////////////////////////////////////////
291 //// Ok Cancel Control
292 //////////////////////////////////////////////
294 BEGIN_EVENT_TABLE(OkCancelCtrl, wxControl)
296 END_EVENT_TABLE()
298 IMPLEMENT_DYNAMIC_CLASS(OkCancelCtrl, wxControl)
300 bool OkCancelCtrl::Create(wxWindow* parent, wxWindowID id,
301 const wxPoint& pos, const wxSize& size, long style,
302 const wxValidator& validator)
304 if (!wxControl::Create(parent, id, pos, size, style, validator)) return false;
306 CreateControls();
307 GetSizer()->Fit(this);
308 GetSizer()->SetSizeHints(this);
309 return true;
312 void OkCancelCtrl::CreateControls()
314 // A top-level sizer
315 wxBoxSizer* topSizer = new wxBoxSizer(wxHORIZONTAL);
316 this->SetSizer(topSizer);
318 // The OK button
319 m_OkBtn = new wxButton ( this, wxID_OK, wxT("&OK"),
320 wxDefaultPosition, wxDefaultSize, 0 );
321 topSizer->Add(m_OkBtn, 0, wxALL, 5);
322 // The Cancel button
323 m_CancelBtn = new wxButton ( this, wxID_CANCEL,
324 wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
325 topSizer->Add(m_CancelBtn, 0, wxALL, 5);
327 Layout();
332 /////////////////////////////////////////////
333 //// Device Selector
334 //////////////////////////////////////////////
336 BEGIN_EVENT_TABLE(DeviceSelectorCtrl, wxControl)
337 EVT_BUTTON(ID_AUTODETECT_BTN, DeviceSelectorCtrl::OnAutoDetect)
338 EVT_COMBOBOX(ID_DEVICE_CBX,DeviceSelectorCtrl::OnComboBox)
339 END_EVENT_TABLE()
341 IMPLEMENT_DYNAMIC_CLASS(DeviceSelectorCtrl, wxControl)
343 bool DeviceSelectorCtrl::Create(wxWindow* parent, wxWindowID id,
344 const wxPoint& pos, const wxSize& size, long style,
345 const wxValidator& validator)
347 if (!wxControl::Create(parent, id, pos, size, style, validator)) return false;
349 CreateControls();
350 GetSizer()->Fit(this);
351 GetSizer()->SetSizeHints(this);
352 return true;
355 void DeviceSelectorCtrl::CreateControls()
357 // A top-level sizer
358 wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
359 this->SetSizer(topSizer);
361 //Device Selection
363 wxBoxSizer* horizontalSizer = new wxBoxSizer(wxHORIZONTAL);
364 topSizer->Add(horizontalSizer, 0, wxALIGN_LEFT|wxALL, 5);
365 m_desc = new wxStaticText( this, wxID_STATIC,
366 wxT("Device:"), wxDefaultPosition,
367 wxDefaultSize, 0 );
368 horizontalSizer->Add(m_desc, 0, wxALIGN_LEFT|wxALL, 5);
370 m_deviceCbx = new wxComboBox(this, ID_DEVICE_CBX,wxT(""),
371 wxDefaultPosition,wxDefaultSize,gv->plat_name,wxCB_READONLY);
373 m_deviceCbx->SetToolTip(wxT("Select your Device."));
374 m_deviceCbx->SetHelpText(wxT("Select your Device."));
376 horizontalSizer->Add(m_deviceCbx, 0, wxALIGN_LEFT|wxALL, 5);
378 wxButton* m_autodetectBtn = new wxButton(this, ID_AUTODETECT_BTN, wxT("Autodetect"),
379 wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator,
380 wxT("AutodetectBtn"));
382 m_autodetectBtn->SetToolTip(wxT("Autodetection of the Device."));
383 m_autodetectBtn->SetHelpText(wxT("Autodetection of the Device."));
385 horizontalSizer->Add(m_autodetectBtn,0,wxGROW | wxALL,5);
386 Layout();
390 wxString DeviceSelectorCtrl::getDevice()
392 return m_currentDevice;
395 void DeviceSelectorCtrl::setDefault()
397 int index = gv->plat_id.Index(gv->curplat);
398 if(index == -1) return;
399 m_deviceCbx->SetValue(gv->plat_name[index]);
402 void DeviceSelectorCtrl::OnComboBox(wxCommandEvent& event)
404 int index = gv->plat_name.Index(m_deviceCbx->GetValue());
406 if(index == -1)
408 m_currentDevice = wxT("");
409 return;
412 gv->curplat = gv->plat_id[index];
415 void DeviceSelectorCtrl::OnAutoDetect(wxCommandEvent& event)
417 struct ipod_t ipod;
418 int n = ipod_scan(&ipod);
419 if(n == 1)
421 wxString temp(ipod.targetname,wxConvUTF8);
422 int index = gv->plat_bootloadername.Index(temp); // use the bootloader names..
423 m_deviceCbx->SetValue(gv->plat_name[index]);
424 gv->curplat=gv->plat_id[index];
425 return;
427 else if (n > 1)
429 WARN_DIALOG(wxT("More then one Ipod device detected, please connect only One"),
430 wxT("Detecting a Device"));
431 return;
434 struct sansa_t sansa;
435 int n2 = sansa_scan(&sansa);
436 if(n2==1)
438 int index = gv->plat_id.Index(wxT("sansae200"));
439 m_deviceCbx->SetValue(gv->plat_name[index]);
440 gv->curplat=gv->plat_id[index];
441 return;
443 else if (n2 > 1)
445 WARN_DIALOG(wxT("More then one Sansa device detected, please connect only One"),
446 wxT("Detecting a Device"));
447 return;
450 WARN_DIALOG(wxT("No Device detected. (This function currently only works for Ipods and Sansas)."),
451 wxT("Detecting a Device"));
452 return;
456 /////////////////////////////////////////////
457 //// DevicePosition Selector
458 //////////////////////////////////////////////
460 BEGIN_EVENT_TABLE(DevicePositionCtrl, wxControl)
461 EVT_BUTTON(ID_BROWSE_BTN, DevicePositionCtrl::OnBrowseBtn)
462 END_EVENT_TABLE()
464 IMPLEMENT_DYNAMIC_CLASS(DevicePositionCtrl, wxControl)
466 bool DevicePositionCtrl::Create(wxWindow* parent, wxWindowID id,
467 const wxPoint& pos, const wxSize& size, long style,
468 const wxValidator& validator)
470 if (!wxControl::Create(parent, id, pos, size, style, validator)) return false;
472 CreateControls();
473 GetSizer()->Fit(this);
474 GetSizer()->SetSizeHints(this);
475 return true;
478 void DevicePositionCtrl::CreateControls()
480 // A top-level sizer
481 wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
482 this->SetSizer(topSizer);
484 //Device Selection
485 m_desc = new wxStaticText( this, wxID_STATIC,
486 wxT("Select your Device in the Filesystem"), wxDefaultPosition,
487 wxDefaultSize, 0 );
488 topSizer->Add(m_desc, 0, wxALIGN_LEFT|wxALL, 5);
490 wxBoxSizer* horizontalSizer = new wxBoxSizer(wxHORIZONTAL);
491 topSizer->Add(horizontalSizer, 0, wxGROW|wxALL, 5);
493 m_devicePos = new wxTextCtrl(this,wxID_ANY,gv->curdestdir);
494 m_devicePos->SetToolTip(wxT("Select your Devicefolder"));
495 m_devicePos->SetHelpText(wxT("Select your Devicefolder"));
496 horizontalSizer->Add(m_devicePos,0,wxGROW | wxALL,5);
498 m_browseBtn = new wxButton(this, ID_BROWSE_BTN, wxT("Browse"),
499 wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator,
500 wxT("BrowseBtn"));
501 m_browseBtn->SetToolTip(wxT("Browse for your Device"));
502 m_browseBtn->SetHelpText(wxT("Browse for your Device"));
503 horizontalSizer->Add(m_browseBtn,0,wxGROW | wxALL,5);
505 topSizer->Fit(this);
506 Layout();
510 wxString DevicePositionCtrl::getDevicePos()
512 return m_devicePos->GetValue();
516 void DevicePositionCtrl::setDefault()
518 m_devicePos->SetValue(gv->curdestdir);
521 void DevicePositionCtrl::OnBrowseBtn(wxCommandEvent& event)
523 const wxString& temp = wxDirSelector(
524 wxT("Please select the location of your audio device"), gv->curdestdir);
526 if (!temp.empty())
528 m_devicePos->SetValue(temp);
533 /////////////////////////////////////////////
534 //// FirmwarePosition Selector
535 //////////////////////////////////////////////
537 BEGIN_EVENT_TABLE(FirmwarePositionCtrl, wxControl)
538 EVT_BUTTON(ID_BROWSE_BTN, FirmwarePositionCtrl::OnBrowseBtn)
539 END_EVENT_TABLE()
541 IMPLEMENT_DYNAMIC_CLASS(FirmwarePositionCtrl, wxControl)
543 bool FirmwarePositionCtrl::Create(wxWindow* parent, wxWindowID id,
544 const wxPoint& pos, const wxSize& size, long style,
545 const wxValidator& validator)
547 if (!wxControl::Create(parent, id, pos, size, style, validator)) return false;
549 CreateControls();
550 GetSizer()->Fit(this);
551 GetSizer()->SetSizeHints(this);
552 return true;
555 void FirmwarePositionCtrl::CreateControls()
557 // A top-level sizer
558 wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
559 this->SetSizer(topSizer);
561 //Device Selection
562 m_desc = new wxStaticText( this, wxID_STATIC,
563 wxT("Select original Firmware from the Manufacturer"), wxDefaultPosition,
564 wxDefaultSize, 0 );
565 topSizer->Add(m_desc, 0, wxALIGN_LEFT|wxALL, 5);
567 wxBoxSizer* horizontalSizer = new wxBoxSizer(wxHORIZONTAL);
568 topSizer->Add(horizontalSizer, 0, wxALIGN_LEFT|wxALL, 5);
570 m_firmwarePos = new wxTextCtrl(this,wxID_ANY,gv->curdestdir);
571 m_firmwarePos->SetToolTip(wxT("Select the original Firmware"));
572 m_firmwarePos->SetHelpText(wxT("Select the original Firmware"));
573 horizontalSizer->Add(m_firmwarePos,0,wxGROW | wxALL,5);
575 m_browseBtn = new wxButton(this, ID_BROWSE_BTN, wxT("Browse"),
576 wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator,
577 wxT("BrowseBtn"));
578 m_browseBtn->SetToolTip(wxT("Browse for the original Firmware"));
579 m_browseBtn->SetHelpText(wxT("Browse for the original Firmware"));
580 horizontalSizer->Add(m_browseBtn,0,wxGROW | wxALL,5);
582 Layout();
586 wxString FirmwarePositionCtrl::getFirmwarePos()
588 return m_firmwarePos->GetValue();
592 void FirmwarePositionCtrl::setDefault()
594 m_firmwarePos->SetValue(gv->curfirmware);
597 void FirmwarePositionCtrl::OnBrowseBtn(wxCommandEvent& event)
599 wxString temp = wxFileSelector(
600 wxT("Please select the location of the original Firmware"), gv->curdestdir,wxT(""),wxT(""),wxT("*.hex"));
602 if (!temp.empty())
604 m_firmwarePos->SetValue(temp);