2 #include "rbutilCtrls.h"
3 #include "bootloaders.h"
5 /////////////////////////////////////////////////////////////
7 ////////////////////////////////////////////////////////////////
9 /////////////////////////////////////////////
11 //////////////////////////////////////////////
13 BEGIN_EVENT_TABLE(ImageCtrl
, wxControl
)
14 EVT_PAINT(ImageCtrl::OnPaint
)
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;
28 void ImageCtrl::OnPaint(wxPaintEvent
& event
)
31 dc
.DrawBitmap(m_bitmap
,0,0,false);
34 void ImageCtrl::SetBitmap(wxBitmap bmp
)
41 wxSize
ImageCtrl::DoGetBestSize() const
44 bestsize
.x
= m_bitmap
.GetWidth();
45 bestsize
.y
= m_bitmap
.GetHeight();
51 /////////////////////////////////////////////
53 //////////////////////////////////////////////
55 BEGIN_EVENT_TABLE(ThemeCtrl
, wxControl
)
56 EVT_LISTBOX(ID_THEME_LST
, ThemeCtrl::OnThemesLst
)
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;
69 GetSizer()->Fit(this);
71 GetSizer()->SetSizeHints(this);
75 void ThemeCtrl::CreateControls()
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);
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
,
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);
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);
112 wxBoxSizer
* wxBoxSizer8
= new wxBoxSizer(wxHORIZONTAL
);
113 styleSizer
->Add(wxBoxSizer8
,0,wxGROW
| wxALL
,0);
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);
123 wxStaticText
* desc_desc
= new wxStaticText(this,wxID_ANY
,wxT("Description:"));
124 styleSizer
->Add(desc_desc
,0,wxGROW
| wxALL
,5);
126 m_themedesc
= new wxStaticText(this,ID_DESC
,wxT(""));
127 styleSizer
->Add(m_themedesc
,0,wxGROW
| wxALL
,5);
130 topSizer
->SetSizeHints(this);
135 void ThemeCtrl::Init()
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
)
154 m_currentResolution
= gv
->plat_resolution
[index
];
156 // load the themelist
158 m_size
->SetLabel(wxT(""));
159 m_themedesc
->SetLabel(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."));
175 //read and parse Themes list
176 wxString themelistraw
;
178 if(!themefile
.Open(dest
)) //open file
180 MESG_DIALOG(wxT("Unable to open themes list."));
183 if(!themefile
.ReadAll(&themelistraw
)) //read complete file
185 MESG_DIALOG(wxT("Unable to read themes list."));
188 wxRegEx
reAll(wxT("<body >(.+)</body>")); //extract body part
189 if(! reAll
.Matches(themelistraw
))
191 MESG_DIALOG(wxT("Themes list is in wrong Format."));
194 wxString lines
= reAll
.GetMatch(themelistraw
,1);
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);
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
->SetLabel(m_Themes_desc
[index
]);
235 m_themedesc
->Wrap(200); // wrap desc
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
))
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."));
259 m_currentimage
= dest
;
261 bmp
.LoadFile(m_currentimage
,wxBITMAP_TYPE_PNG
);
262 m_PreviewBitmap
->SetBitmap(bmp
);
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
;
280 int numSelected
= m_themeList
->GetSelections(selected
);
282 for(int i
=0; i
< numSelected
; i
++)
284 themes
.Add(m_Themes_path
[selected
[i
]]);
290 /////////////////////////////////////////////
291 //// Ok Cancel Control
292 //////////////////////////////////////////////
294 BEGIN_EVENT_TABLE(OkCancelCtrl
, wxControl
)
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;
307 GetSizer()->Fit(this);
308 GetSizer()->SetSizeHints(this);
312 void OkCancelCtrl::CreateControls()
315 wxBoxSizer
* topSizer
= new wxBoxSizer(wxHORIZONTAL
);
316 this->SetSizer(topSizer
);
319 m_OkBtn
= new wxButton ( this, wxID_OK
, wxT("&OK"),
320 wxDefaultPosition
, wxDefaultSize
, 0 );
321 topSizer
->Add(m_OkBtn
, 0, wxALL
, 5);
323 m_CancelBtn
= new wxButton ( this, wxID_CANCEL
,
324 wxT("&Cancel"), wxDefaultPosition
, wxDefaultSize
, 0 );
325 topSizer
->Add(m_CancelBtn
, 0, wxALL
, 5);
332 /////////////////////////////////////////////
334 //////////////////////////////////////////////
336 BEGIN_EVENT_TABLE(DeviceSelectorCtrl
, wxControl
)
337 EVT_BUTTON(ID_AUTODETECT_BTN
, DeviceSelectorCtrl::OnAutoDetect
)
338 EVT_COMBOBOX(ID_DEVICE_CBX
,DeviceSelectorCtrl::OnComboBox
)
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;
350 GetSizer()->Fit(this);
351 GetSizer()->SetSizeHints(this);
355 void DeviceSelectorCtrl::CreateControls()
358 wxBoxSizer
* topSizer
= new wxBoxSizer(wxVERTICAL
);
359 this->SetSizer(topSizer
);
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
,
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);
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());
407 m_currentDevice
= wxT("");
411 gv
->curplat
= gv
->plat_id
[index
];
414 void DeviceSelectorCtrl::OnAutoDetect(wxCommandEvent
& event
)
417 int n
= ipod_scan(&ipod
);
420 wxString
temp(ipod
.targetname
,wxConvUTF8
);
421 int index
= gv
->plat_bootloadername
.Index(temp
); // use the bootloader names..
422 m_deviceCbx
->SetValue(gv
->plat_name
[index
]);
423 gv
->curplat
=gv
->plat_id
[index
];
428 WARN_DIALOG(wxT("More then one Ipod device detected, please connect only One"),
429 wxT("Detecting a Device"));
433 struct sansa_t sansa
;
434 int n2
= sansa_scan(&sansa
);
437 int index
= gv
->plat_id
.Index(wxT("sansae200"));
438 m_deviceCbx
->SetValue(gv
->plat_name
[index
]);
439 gv
->curplat
=gv
->plat_id
[index
];
444 WARN_DIALOG(wxT("More then one Sansa device detected, please connect only One"),
445 wxT("Detecting a Device"));
449 WARN_DIALOG(wxT("No Device detected. (This function currently only works for Ipods and Sansas)."),
450 wxT("Detecting a Device"));
455 /////////////////////////////////////////////
456 //// DevicePosition Selector
457 //////////////////////////////////////////////
459 BEGIN_EVENT_TABLE(DevicePositionCtrl
, wxControl
)
460 EVT_BUTTON(ID_BROWSE_BTN
, DevicePositionCtrl::OnBrowseBtn
)
463 IMPLEMENT_DYNAMIC_CLASS(DevicePositionCtrl
, wxControl
)
465 bool DevicePositionCtrl::Create(wxWindow
* parent
, wxWindowID id
,
466 const wxPoint
& pos
, const wxSize
& size
, long style
,
467 const wxValidator
& validator
)
469 if (!wxControl::Create(parent
, id
, pos
, size
, style
, validator
)) return false;
472 GetSizer()->Fit(this);
473 GetSizer()->SetSizeHints(this);
477 void DevicePositionCtrl::CreateControls()
480 wxBoxSizer
* topSizer
= new wxBoxSizer(wxVERTICAL
);
481 this->SetSizer(topSizer
);
484 m_desc
= new wxStaticText( this, wxID_STATIC
,
485 wxT("Select your Device in the Filesystem"), wxDefaultPosition
,
487 topSizer
->Add(m_desc
, 0, wxALIGN_LEFT
|wxALL
, 5);
489 wxBoxSizer
* horizontalSizer
= new wxBoxSizer(wxHORIZONTAL
);
490 topSizer
->Add(horizontalSizer
, 0, wxGROW
|wxALL
, 5);
492 m_devicePos
= new wxTextCtrl(this,wxID_ANY
,gv
->curdestdir
);
493 m_devicePos
->SetToolTip(wxT("Select your Devicefolder"));
494 m_devicePos
->SetHelpText(wxT("Select your Devicefolder"));
495 horizontalSizer
->Add(m_devicePos
,0,wxGROW
| wxALL
,5);
497 m_browseBtn
= new wxButton(this, ID_BROWSE_BTN
, wxT("Browse"),
498 wxDefaultPosition
, wxDefaultSize
, 0, wxDefaultValidator
,
500 m_browseBtn
->SetToolTip(wxT("Browse for your Device"));
501 m_browseBtn
->SetHelpText(wxT("Browse for your Device"));
502 horizontalSizer
->Add(m_browseBtn
,0,wxGROW
| wxALL
,5);
509 wxString
DevicePositionCtrl::getDevicePos()
511 return m_devicePos
->GetValue();
515 void DevicePositionCtrl::setDefault()
517 m_devicePos
->SetValue(gv
->curdestdir
);
520 void DevicePositionCtrl::OnBrowseBtn(wxCommandEvent
& event
)
522 const wxString
& temp
= wxDirSelector(
523 wxT("Please select the location of your audio device"), gv
->curdestdir
);
527 m_devicePos
->SetValue(temp
);
532 /////////////////////////////////////////////
533 //// FirmwarePosition Selector
534 //////////////////////////////////////////////
536 BEGIN_EVENT_TABLE(FirmwarePositionCtrl
, wxControl
)
537 EVT_BUTTON(ID_BROWSE_BTN
, FirmwarePositionCtrl::OnBrowseBtn
)
540 IMPLEMENT_DYNAMIC_CLASS(FirmwarePositionCtrl
, wxControl
)
542 bool FirmwarePositionCtrl::Create(wxWindow
* parent
, wxWindowID id
,
543 const wxPoint
& pos
, const wxSize
& size
, long style
,
544 const wxValidator
& validator
)
546 if (!wxControl::Create(parent
, id
, pos
, size
, style
, validator
)) return false;
549 GetSizer()->Fit(this);
550 GetSizer()->SetSizeHints(this);
554 void FirmwarePositionCtrl::CreateControls()
557 wxBoxSizer
* topSizer
= new wxBoxSizer(wxVERTICAL
);
558 this->SetSizer(topSizer
);
561 m_desc
= new wxStaticText( this, wxID_STATIC
,
562 wxT("Select original Firmware form the Manufacturer"), wxDefaultPosition
,
564 topSizer
->Add(m_desc
, 0, wxALIGN_LEFT
|wxALL
, 5);
566 wxBoxSizer
* horizontalSizer
= new wxBoxSizer(wxHORIZONTAL
);
567 topSizer
->Add(horizontalSizer
, 0, wxALIGN_LEFT
|wxALL
, 5);
569 m_firmwarePos
= new wxTextCtrl(this,wxID_ANY
,gv
->curdestdir
);
570 m_firmwarePos
->SetToolTip(wxT("Select the original Firmware"));
571 m_firmwarePos
->SetHelpText(wxT("Select the original Firmware"));
572 horizontalSizer
->Add(m_firmwarePos
,0,wxGROW
| wxALL
,5);
574 m_browseBtn
= new wxButton(this, ID_BROWSE_BTN
, wxT("Browse"),
575 wxDefaultPosition
, wxDefaultSize
, 0, wxDefaultValidator
,
577 m_browseBtn
->SetToolTip(wxT("Browse for the original Firmware"));
578 m_browseBtn
->SetHelpText(wxT("Browse for the original Firmware"));
579 horizontalSizer
->Add(m_browseBtn
,0,wxGROW
| wxALL
,5);
585 wxString
FirmwarePositionCtrl::getFirmwarePos()
587 return m_firmwarePos
->GetValue();
591 void FirmwarePositionCtrl::setDefault()
593 m_firmwarePos
->SetValue(gv
->curfirmware
);
596 void FirmwarePositionCtrl::OnBrowseBtn(wxCommandEvent
& event
)
598 wxString temp
= wxFileSelector(
599 wxT("Please select the location of the original Firmware"), gv
->curdestdir
,wxT(""),wxT(""),wxT("*.hex"));
603 m_firmwarePos
->SetValue(temp
);