2 #include "rbutilCtrls.h"
3 #include "bootloaders.h"
4 #include "autodetection.h"
6 /////////////////////////////////////////////////////////////
8 ////////////////////////////////////////////////////////////////
10 /////////////////////////////////////////////
12 //////////////////////////////////////////////
14 BEGIN_EVENT_TABLE(ImageCtrl
, wxControl
)
15 EVT_PAINT(ImageCtrl::OnPaint
)
18 IMPLEMENT_DYNAMIC_CLASS(ImageCtrl
, wxControl
)
20 bool ImageCtrl::Create(wxWindow
* parent
, wxWindowID id
,
21 const wxPoint
& pos
, const wxSize
& size
, long style
,
22 const wxValidator
& validator
)
24 if (!wxControl::Create(parent
, id
, pos
, size
, style
, validator
)) return false;
29 void ImageCtrl::OnPaint(wxPaintEvent
& event
)
32 dc
.DrawBitmap(m_bitmap
,0,0,false);
35 void ImageCtrl::SetBitmap(wxBitmap bmp
)
42 wxSize
ImageCtrl::DoGetBestSize() const
45 bestsize
.x
= m_bitmap
.GetWidth();
46 bestsize
.y
= m_bitmap
.GetHeight();
52 /////////////////////////////////////////////
54 //////////////////////////////////////////////
56 BEGIN_EVENT_TABLE(ThemeCtrl
, wxPanel
)
57 EVT_LISTBOX(ID_THEME_LST
, ThemeCtrl::OnThemesLst
)
58 EVT_BUTTON(ID_THEME_SELECT_ALL
, ThemeCtrl::OnSelectAll
)
61 IMPLEMENT_DYNAMIC_CLASS(ThemeCtrl
, wxPanel
)
63 bool ThemeCtrl::Create(wxWindow
* parent
, wxWindowID id
,
64 const wxPoint
& pos
, const wxSize
& size
, long style
,
65 const wxString title
)
67 if (!wxPanel::Create(parent
, id
, pos
, size
, style
, title
)) return false;
71 GetSizer()->Fit(this);
73 GetSizer()->SetSizeHints(this);
77 void ThemeCtrl::CreateControls()
80 wxBoxSizer
* topSizer
= new wxBoxSizer(wxVERTICAL
);
81 this->SetSizer(topSizer
);
83 wxBoxSizer
* horizontalSizer
= new wxBoxSizer(wxHORIZONTAL
);
84 topSizer
->Add(horizontalSizer
, 0, wxALIGN_LEFT
|wxALL
, 5);
87 wxBoxSizer
* wxBoxSizer7
= new wxBoxSizer(wxVERTICAL
);
88 horizontalSizer
->Add(wxBoxSizer7
,0,wxGROW
| wxALL
,0);
90 wxStaticText
* m_desc
= new wxStaticText( this, wxID_STATIC
,
91 wxT("Select one or more Themes to install"), wxDefaultPosition
,
93 wxBoxSizer7
->Add(m_desc
, 0, wxALIGN_LEFT
|wxALL
, 5);
95 m_themeList
= new wxListBox(this,ID_THEME_LST
,wxDefaultPosition
,
96 wxDefaultSize
,0,NULL
,wxLB_EXTENDED
);
97 wxBoxSizer7
->Add(m_themeList
, 0, wxALIGN_LEFT
|wxALL
, 5);
99 m_selectAllThemes
= new wxButton(this, ID_THEME_SELECT_ALL
,
101 wxBoxSizer7
->Add(m_selectAllThemes
, 0, wxALIGN_LEFT
|wxALL
, 5);
104 wxBoxSizer
* wxBoxSizer9
= new wxBoxSizer(wxVERTICAL
);
105 horizontalSizer
->Add(wxBoxSizer9
,0,wxGROW
| wxALL
,0);
107 wxStaticText
* preview_desc
= new wxStaticText(this,wxID_ANY
,wxT("Preview:"));
108 wxBoxSizer9
->Add(preview_desc
,0,wxGROW
| wxALL
,5);
110 m_PreviewBitmap
= new ImageCtrl(this,ID_PREVIEW_BITMAP
);
111 wxBoxSizer9
->Add(m_PreviewBitmap
,0,wxALIGN_LEFT
| wxALL
,5);
113 wxStaticBox
* groupbox
= new wxStaticBox(this,wxID_ANY
,wxT("Selected Theme:"));
114 wxStaticBoxSizer
* styleSizer
= new wxStaticBoxSizer( groupbox
, wxVERTICAL
);
115 topSizer
->Add(styleSizer
,0,wxGROW
|wxALL
,0);
118 wxBoxSizer
* wxBoxSizer8
= new wxBoxSizer(wxHORIZONTAL
);
119 styleSizer
->Add(wxBoxSizer8
,0,wxGROW
| wxALL
,0);
122 wxStaticText
* size_desc
= new wxStaticText(this,wxID_ANY
,wxT("Filesize:"));
123 wxBoxSizer8
->Add(size_desc
,0,wxGROW
| wxALL
,5);
125 m_size
= new wxStaticText(this,ID_FILESIZE
,wxT(""));
126 wxBoxSizer8
->Add(m_size
,0,wxGROW
| wxALL
,5);
129 wxStaticText
* desc_desc
= new wxStaticText(this,wxID_ANY
,wxT("Description:"));
130 styleSizer
->Add(desc_desc
,0,wxGROW
| wxALL
,5);
132 m_themedesc
= new wxTextCtrl(this,ID_DESC
,wxT(""),wxDefaultPosition
, wxDefaultSize
, wxTE_MULTILINE
|wxTE_READONLY
);
133 styleSizer
->Add(m_themedesc
,0,wxGROW
| wxALL
,5);
136 topSizer
->SetSizeHints(this);
141 void ThemeCtrl::Init()
144 m_Themes_path
.Clear();
145 m_Themes_size
.Clear();
146 m_Themes_image
.Clear();
147 m_Themes_desc
.Clear();
151 void ThemeCtrl::setDevice(wxString device
)
154 int index
= gv
->plat_id
.Index(device
);
155 if(index
== -1) return;
157 if(gv
->plat_resolution
[index
] == m_currentResolution
)
160 m_currentResolution
= gv
->plat_resolution
[index
];
162 // load the themelist
164 m_size
->SetLabel(wxT(""));
165 m_themedesc
->SetValue(wxT(""));
166 m_themeList
->Clear();
168 //get correct Themes list
169 wxString src
,dest
,err
;
171 src
= gv
->themes_url
+ wxT("rbutil.php?res=") + m_currentResolution
;
172 dest
= gv
->stdpaths
->GetUserDataDir() + wxT("" PATH_SEP
"download" PATH_SEP
)
173 + m_currentResolution
+ wxT(".list");
175 if(DownloadURL(src
, dest
))
177 MESG_DIALOG(wxT("Unable to download themes list."));
181 //read and parse Themes list
182 wxString themelistraw
;
184 if(!themefile
.Open(dest
)) //open file
186 MESG_DIALOG(wxT("Unable to open themes list."));
189 if(!themefile
.ReadAll(&themelistraw
)) //read complete file
191 MESG_DIALOG(wxT("Unable to read themes list."));
194 wxRegEx
reAll(wxT("<body >(.+)</body>")); //extract body part
195 if(! reAll
.Matches(themelistraw
))
197 MESG_DIALOG(wxT("Themes list is in wrong Format."));
200 wxString lines
= reAll
.GetMatch(themelistraw
,1);
203 lines
.Replace(wxT("<br />"),wxT(""),true); //replace <br /> with nothing
204 lines
.Replace(wxT("\n"),wxT(""),true); //replace \n with nothing
205 lines
.Trim(true); //strip WS at end
206 lines
.Trim(false); //strip WS at beginning
207 wxStringTokenizer
tkz(lines
,wxT("|")); //tokenize it
209 while ( tkz
.HasMoreTokens() ) // read all entrys
211 m_Themes
.Add(tkz
.GetNextToken()); //Theme name
212 m_Themes_path
.Add(tkz
.GetNextToken()); //Theme path
213 m_Themes_size
.Add(tkz
.GetNextToken()); //File size
214 m_Themes_image
.Add(tkz
.GetNextToken()); //Screenshot
215 m_Themes_desc
.Add(tkz
.GetNextToken()); //Description
217 m_themeList
->Append(m_Themes
.Last());
220 this->GetSizer()->Layout();
221 this->GetSizer()->Fit(this);
222 this->GetSizer()->SetSizeHints(this);
223 m_parent
->GetSizer()->Layout();
224 m_parent
->GetSizer()->Fit(m_parent
);
225 m_parent
->GetSizer()->SetSizeHints(m_parent
);
229 void ThemeCtrl::OnThemesLst(wxCommandEvent
& event
)
234 void ThemeCtrl::ThemePreview()
236 // wxCriticalSectionLocker locker(m_ThemeSelectSection);
239 int numSelected
= m_themeList
->GetSelections(selected
);
240 if(numSelected
== 0) return;
242 int index
= selected
[0];
244 m_size
->SetLabel(m_Themes_size
[index
]);
245 m_themedesc
->SetValue(m_Themes_desc
[index
]);
246 // m_themedesc->Wrap(200); // wrap desc
250 int pos
= m_Themes_image
[index
].Find('/',true);
251 wxString filename
= m_Themes_image
[index
](pos
+1,m_Themes_image
[index
].Length());
253 dest
= gv
->stdpaths
->GetUserDataDir()
254 + wxT("" PATH_SEP
"download" PATH_SEP
)
255 + m_currentResolution
;
257 if(!wxDirExists(dest
))
260 //this is a URL no PATH_SEP
261 src
= gv
->themes_url
+ wxT("/data/") + m_currentResolution
+ wxT("/")
263 dest
= gv
->stdpaths
->GetUserDataDir() + wxT("" PATH_SEP
"download" PATH_SEP
)
264 + m_currentResolution
+ wxT("" PATH_SEP
) + filename
;
266 if(DownloadURL(src
, dest
))
268 MESG_DIALOG(wxT("Unable to download image."));
272 m_currentimage
= dest
;
274 bmp
.LoadFile(m_currentimage
,wxBITMAP_TYPE_PNG
);
275 m_PreviewBitmap
->SetBitmap(bmp
);
278 this->GetSizer()->Layout();
279 this->GetSizer()->Fit(this);
280 this->GetSizer()->SetSizeHints(this);
282 m_parent
->GetSizer()->Layout();
283 m_parent
->GetSizer()->Fit(m_parent
);
284 m_parent
->GetSizer()->SetSizeHints(m_parent
);
288 void ThemeCtrl::OnSelectAll(wxCommandEvent
& event
)
290 for(unsigned int i
=0; i
< m_themeList
->GetCount(); i
++)
291 m_themeList
->Select(i
);
295 wxArrayString
ThemeCtrl::getThemesToInstall()
297 wxArrayString themes
;
299 int numSelected
= m_themeList
->GetSelections(selected
);
301 for(int i
=0; i
< numSelected
; i
++)
303 themes
.Add(m_Themes_path
[selected
[i
]]);
309 /////////////////////////////////////////////
310 //// Ok Cancel Control
311 //////////////////////////////////////////////
313 BEGIN_EVENT_TABLE(OkCancelCtrl
, wxPanel
)
317 IMPLEMENT_DYNAMIC_CLASS(OkCancelCtrl
, wxPanel
)
319 bool OkCancelCtrl::Create(wxWindow
* parent
, wxWindowID id
,
320 const wxPoint
& pos
, const wxSize
& size
, long style
,
321 const wxString title
)
323 if (!wxPanel::Create(parent
, id
, pos
, size
, style
, title
)) return false;
326 GetSizer()->Fit(this);
327 GetSizer()->SetSizeHints(this);
331 void OkCancelCtrl::CreateControls()
334 wxBoxSizer
* topSizer
= new wxBoxSizer(wxHORIZONTAL
);
335 this->SetSizer(topSizer
);
338 m_OkBtn
= new wxButton ( this, wxID_OK
, wxT("&OK"),
339 wxDefaultPosition
, wxDefaultSize
, 0 );
340 topSizer
->Add(m_OkBtn
, 0, wxALL
, 5);
342 m_CancelBtn
= new wxButton ( this, wxID_CANCEL
,
343 wxT("&Cancel"), wxDefaultPosition
, wxDefaultSize
, 0 );
344 topSizer
->Add(m_CancelBtn
, 0, wxALL
, 5);
351 /////////////////////////////////////////////
353 //////////////////////////////////////////////
355 BEGIN_EVENT_TABLE(DeviceSelectorCtrl
, wxPanel
)
356 EVT_BUTTON(ID_AUTODETECT_BTN
, DeviceSelectorCtrl::OnAutoDetect
)
357 EVT_COMBOBOX(ID_DEVICE_CBX
,DeviceSelectorCtrl::OnComboBox
)
360 IMPLEMENT_DYNAMIC_CLASS(DeviceSelectorCtrl
, wxPanel
)
362 bool DeviceSelectorCtrl::Create(wxWindow
* parent
, wxWindowID id
,
363 const wxPoint
& pos
, const wxSize
& size
, long style
,
364 const wxString title
)
366 if (!wxPanel::Create(parent
, id
, pos
, size
, style
, title
)) return false;
369 GetSizer()->Fit(this);
370 GetSizer()->SetSizeHints(this);
374 void DeviceSelectorCtrl::CreateControls()
377 wxBoxSizer
* topSizer
= new wxBoxSizer(wxVERTICAL
);
378 this->SetSizer(topSizer
);
381 wxBoxSizer
* horizontalSizer
= new wxBoxSizer(wxHORIZONTAL
);
382 topSizer
->Add(horizontalSizer
, 0, wxALIGN_LEFT
|wxALL
, 5);
383 m_desc
= new wxStaticText( this, wxID_STATIC
,
384 wxT("Device:"), wxDefaultPosition
,
386 horizontalSizer
->Add(m_desc
, 0, wxALIGN_LEFT
|wxALL
, 5);
388 m_deviceCbx
= new wxComboBox(this, ID_DEVICE_CBX
,wxT("Select your Device"),
389 wxDefaultPosition
,wxDefaultSize
,gv
->plat_name
,wxCB_READONLY
);
391 m_deviceCbx
->SetToolTip(wxT("Select your Device."));
392 m_deviceCbx
->SetHelpText(wxT("Select your Device."));
394 horizontalSizer
->Add(m_deviceCbx
, 0, wxALIGN_LEFT
|wxALL
, 5);
396 wxButton
* m_autodetectBtn
= new wxButton(this, ID_AUTODETECT_BTN
, wxT("Autodetect"),
397 wxDefaultPosition
, wxDefaultSize
, 0, wxDefaultValidator
,
398 wxT("AutodetectBtn"));
400 m_autodetectBtn
->SetToolTip(wxT("Click here to autodetect your Device."));
401 m_autodetectBtn
->SetHelpText(wxT("Autodetection of the Device."));
402 // m_autodetectBtn->SetFocus();
404 horizontalSizer
->Add(m_autodetectBtn
,0,wxGROW
| wxALL
,5);
409 wxString
DeviceSelectorCtrl::getDevice()
411 return m_currentDevice
;
414 void DeviceSelectorCtrl::setDefault()
416 int index
= gv
->plat_id
.Index(gv
->curplat
);
417 if(index
== -1) return;
418 m_deviceCbx
->SetValue(gv
->plat_name
[index
]);
421 void DeviceSelectorCtrl::OnComboBox(wxCommandEvent
& event
)
423 int index
= gv
->plat_name
.Index(m_deviceCbx
->GetValue());
427 m_currentDevice
= wxT("");
431 gv
->curplat
= gv
->plat_id
[index
];
434 void DeviceSelectorCtrl::OnAutoDetect(wxCommandEvent
& event
)
440 void DeviceSelectorCtrl::AutoDetect()
444 UsbDeviceInfo device
= detectDevicesViaPatchers();
446 if( device
.status
== NODEVICE
)
448 WARN_DIALOG(wxT("No Device detected. (This function currently only works for Ipods and Sansas)."),
449 wxT("Detecting a Device"));
453 if( device
.status
== TOMANYDEVICES
)
455 WARN_DIALOG(wxT("More then one device detected, please connect only One"),
456 wxT("Detecting a Device"));
461 if (device
.status
== 0 ) /* everything is ok */
463 m_deviceCbx
->SetValue(gv
->plat_name
[device
.device_index
]);
464 gv
->curplat
=gv
->plat_id
[device
.device_index
];
466 if(device
.path
!= wxT(""))
468 gv
->curdestdir
= device
.path
;
475 /////////////////////////////////////////////
476 //// DevicePosition Selector
477 //////////////////////////////////////////////
479 BEGIN_EVENT_TABLE(DevicePositionCtrl
, wxPanel
)
480 EVT_BUTTON(ID_BROWSE_BTN
, DevicePositionCtrl::OnBrowseBtn
)
483 IMPLEMENT_DYNAMIC_CLASS(DevicePositionCtrl
, wxPanel
)
485 bool DevicePositionCtrl::Create(wxWindow
* parent
, wxWindowID id
,
486 const wxPoint
& pos
, const wxSize
& size
, long style
,
487 const wxString title
)
489 if (!wxPanel::Create(parent
, id
, pos
, size
, style
, title
)) return false;
492 GetSizer()->Fit(this);
493 GetSizer()->SetSizeHints(this);
497 void DevicePositionCtrl::CreateControls()
500 wxBoxSizer
* topSizer
= new wxBoxSizer(wxVERTICAL
);
501 this->SetSizer(topSizer
);
504 m_desc
= new wxStaticText( this, wxID_STATIC
,
505 wxT("Select your Device in the Filesystem"), wxDefaultPosition
,
507 topSizer
->Add(m_desc
, 0, wxALIGN_LEFT
|wxALL
, 5);
509 wxBoxSizer
* horizontalSizer
= new wxBoxSizer(wxHORIZONTAL
);
510 topSizer
->Add(horizontalSizer
, 0, wxGROW
|wxALL
, 5);
512 m_devicePos
= new wxTextCtrl(this,wxID_ANY
,gv
->curdestdir
);
513 m_devicePos
->SetToolTip(wxT("Type the folder where your Device is here"));
514 m_devicePos
->SetHelpText(wxT("Type the folder where your Device is here"));
515 horizontalSizer
->Add(m_devicePos
,0,wxGROW
| wxALL
,5);
517 m_browseBtn
= new wxButton(this, ID_BROWSE_BTN
, wxT("Browse"),
518 wxDefaultPosition
, wxDefaultSize
, 0, wxDefaultValidator
,
520 m_browseBtn
->SetToolTip(wxT("Browse for your Device"));
521 m_browseBtn
->SetHelpText(wxT("Browse for your Device"));
522 horizontalSizer
->Add(m_browseBtn
,0,wxGROW
| wxALL
,5);
529 wxString
DevicePositionCtrl::getDevicePos()
531 return m_devicePos
->GetValue();
535 void DevicePositionCtrl::setDefault()
537 m_devicePos
->SetValue(gv
->curdestdir
);
540 void DevicePositionCtrl::OnBrowseBtn(wxCommandEvent
& event
)
542 const wxString
& temp
= wxDirSelector(
543 wxT("Please select the location of your audio device"), gv
->curdestdir
,
544 0, wxDefaultPosition
, this);
548 m_devicePos
->SetValue(temp
);
553 /////////////////////////////////////////////
554 //// FirmwarePosition Selector
555 //////////////////////////////////////////////
557 BEGIN_EVENT_TABLE(FirmwarePositionCtrl
, wxPanel
)
558 EVT_BUTTON(ID_BROWSE_BTN
, FirmwarePositionCtrl::OnBrowseBtn
)
561 IMPLEMENT_DYNAMIC_CLASS(FirmwarePositionCtrl
, wxControl
)
563 bool FirmwarePositionCtrl::Create(wxWindow
* parent
, wxWindowID id
,
564 const wxPoint
& pos
, const wxSize
& size
, long style
,
565 const wxString title
)
567 if (!wxPanel::Create(parent
, id
, pos
, size
, style
, title
)) return false;
570 GetSizer()->Fit(this);
571 GetSizer()->SetSizeHints(this);
575 void FirmwarePositionCtrl::CreateControls()
578 wxBoxSizer
* topSizer
= new wxBoxSizer(wxVERTICAL
);
579 this->SetSizer(topSizer
);
582 m_desc
= new wxStaticText( this, wxID_STATIC
,
583 wxT("Select original Firmware from the Manufacturer"), wxDefaultPosition
,
585 topSizer
->Add(m_desc
, 0, wxALIGN_LEFT
|wxALL
, 5);
587 wxBoxSizer
* horizontalSizer
= new wxBoxSizer(wxHORIZONTAL
);
588 topSizer
->Add(horizontalSizer
, 0, wxALIGN_LEFT
|wxALL
, 5);
590 m_firmwarePos
= new wxTextCtrl(this,wxID_ANY
,gv
->curdestdir
);
591 m_firmwarePos
->SetToolTip(wxT("Type the folder where the original Firmware is here"));
592 m_firmwarePos
->SetHelpText(wxT("Type the folder where the original Firmware is here"));
593 horizontalSizer
->Add(m_firmwarePos
,0,wxGROW
| wxALL
,5);
595 m_browseBtn
= new wxButton(this, ID_BROWSE_BTN
, wxT("Browse"),
596 wxDefaultPosition
, wxDefaultSize
, 0, wxDefaultValidator
,
598 m_browseBtn
->SetToolTip(wxT("Browse for the original Firmware"));
599 m_browseBtn
->SetHelpText(wxT("Browse for the original Firmware"));
600 horizontalSizer
->Add(m_browseBtn
,0,wxGROW
| wxALL
,5);
606 wxString
FirmwarePositionCtrl::getFirmwarePos()
608 return m_firmwarePos
->GetValue();
612 void FirmwarePositionCtrl::setDefault()
614 m_firmwarePos
->SetValue(gv
->curfirmware
);
617 void FirmwarePositionCtrl::OnBrowseBtn(wxCommandEvent
& event
)
619 wxString temp
= wxFileSelector(
620 wxT("Please select the location of the original Firmware"), gv
->curdestdir
,wxT(""),wxT(""),wxT("*.hex"));
624 m_firmwarePos
->SetValue(temp
);