summaryrefslogtreecommitdiffstats
path: root/rbutil/wizard_pages.cpp
blob: 644a7ba4bd03e08ab534b9d2be76d9761c79e2ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * Module: rbutil
 * File: wizardpages.cpp
 *
 * Copyright (C) 2005 Christi Alice Scarborough
 *
 * All files in this archive are subject to the GNU General Public License.
 * See the file COPYING in the source tree root for full license agreement.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/

#include "wizard_pages.h"
#include "bootloaders.h"


#include <wx/regex.h>
#include <wx/tokenzr.h>

/////// Bootplatform page ///////////////////////////////////77
wxBootPlatformPage::wxBootPlatformPage(wxWizard *parent) : wxWizardPageSimple(parent)
{
    wxBoxSizer* WxBoxSizer1 = new wxBoxSizer(wxVERTICAL);

    wxStaticText* WxStaticText1 = new wxStaticText(this, wxID_ANY,
        wxT("Please select the model of audio device that you would like to"
        "\ninstall the Rockbox Bootloader on from the list below:"));
    WxBoxSizer1->Add(WxStaticText1,0,wxGROW | wxALL,5);

    wxArrayString arrayStringFor_WxListBox1;
    for (unsigned int i=0; i< gv->plat_name.GetCount(); i++) {
        if (gv->plat_needsbootloader[i])
        {
           if(gv->plat_autodetect[i])
           {
                if(arrayStringFor_WxListBox1.Index(gv->plat_combinedname[i]) == wxNOT_FOUND)
                    arrayStringFor_WxListBox1.Add(gv->plat_combinedname[i]);
           }
           else
           {
                arrayStringFor_WxListBox1.Add(gv->plat_name[i]);
           }
        }
    }

    BootPlatformListBox = new wxListBox(this, wxID_ANY, wxDefaultPosition,
        wxDefaultSize, arrayStringFor_WxListBox1, wxLB_SINGLE);
    WxBoxSizer1->Add(BootPlatformListBox,0,wxGROW | wxALL,5);

    SetSizer(WxBoxSizer1);
    WxBoxSizer1->Fit(this);

    for (unsigned int i=0; i< gv->plat_id.GetCount(); i++) {
        if (gv->plat_id[i] == gv->curplat) BootPlatformListBox->SetSelection(i);
    }

}

wxWizardPage * wxBootPlatformPage::GetNext() const
{
   if(gv->curbootloadermethod != wxT("fwpatcher")&& gv->curbootloadermethod != wxT("ipodpatcher"))
   {
       if(wxWizardPageSimple::GetNext()->GetNext() != NULL)  // not iriver hx0 and ipod, skip one page
           return wxWizardPageSimple::GetNext()->GetNext();
   }
   else if(gv->curbootloadermethod == wxT("ipodpatcher"))
   {
        if(wxWizardPageSimple::GetNext()->GetNext() != NULL)
            if(wxWizardPageSimple::GetNext()->GetNext()->GetNext() != NULL)
                return wxWizardPageSimple::GetNext()->GetNext()->GetNext(); //ipod, skip 2 pages
            else
                return wxWizardPageSimple::GetNext()->GetNext(); //ipod, skip 1 page (for uninstallation)
   }

   // all others , no skip
   return wxWizardPageSimple::GetNext();
}

bool wxBootPlatformPage::TransferDataFromWindow()
{
    if (BootPlatformListBox->GetSelection() == wxNOT_FOUND )
    {
        WARN_DIALOG(wxT("You must select an audio device type before proceeding"),
            wxT("Select Platform"));
        return false;
    } else
    {
        int idx = gv->plat_name.Index(BootPlatformListBox->GetStringSelection());
        if(idx == wxNOT_FOUND) idx =gv->plat_combinedname.Index(BootPlatformListBox->GetStringSelection());
        gv->curplatnum = idx;
        gv->curplat = gv->plat_id[gv->curplatnum];
        gv->curbootloadermethod = gv->plat_bootloadermethod[gv->curplatnum];
        gv->curbootloader = gv->plat_bootloadername[gv->curplatnum];

        return true;
    }
}
//// Plattfor Page //////////////////////////
wxPlatformPage::wxPlatformPage(wxWizard *parent) : wxWizardPageSimple(parent)
{
    wxBoxSizer* WxBoxSizer1 = new wxBoxSizer(wxVERTICAL);

    wxStaticText* WxStaticText1 = new wxStaticText(this, wxID_ANY,
        wxT("Please select the model of audio device that you would like to"
        "\ninstall Rockbox on from the list below:"));
    WxBoxSizer1->Add(WxStaticText1,0,wxGROW | wxALL,5);

    wxArrayString arrayStringFor_WxListBox1;
    PlatformListBox = new wxListBox(this, wxID_ANY, wxDefaultPosition,
        wxDefaultSize, gv->plat_name, wxLB_SINGLE);
    WxBoxSizer1->Add(PlatformListBox,0,wxGROW | wxALL,5);

    SetSizer(WxBoxSizer1);
    WxBoxSizer1->Fit(this);
    for (unsigned int i=0; i< gv->plat_id.GetCount(); i++) {
        if (gv->plat_id[i] == gv->curplat) PlatformListBox->SetSelection(i);
    }
}

bool wxPlatformPage::TransferDataFromWindow()
{
    if (PlatformListBox->GetSelection() == wxNOT_FOUND )
    {
        WARN_DIALOG(wxT("You must select an audio device type before proceeding"),
            wxT("Select Platform"));
        return false;
    } else
    {
        gv->curplatnum = PlatformListBox->GetSelection();
        gv->curplat = gv->plat_id[gv->curplatnum];
        gv->curresolution = gv->plat_resolution[gv->curplatnum];
        return true;
    }
}


//////////////// ThemeImage Dialog /////////////////
BEGIN_EVENT_TABLE(wxThemeImageDialog,wxDialog)
   EVT_PAINT(wxThemeImageDialog::OnPaint)
   EVT_CLOSE(wxThemeImageDialog::OnClose)
END_EVENT_TABLE();
wxThemeImageDialog::wxThemeImageDialog(wxWindow* parent,wxWindowID id,wxString title,wxBitmap bmp)  :
   wxDialog(parent, id, title)
{
    wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
    m_bitmap = bmp;

    sizerTop->SetMinSize(64,64);

    SetSizer(sizerTop);

    sizerTop->SetSizeHints(this);
    sizerTop->Fit(this);

}

void wxThemeImageDialog::OnClose(wxCloseEvent& event)
{
    event.Veto();
    this->Show(false);
}

void wxThemeImageDialog::SetImage(wxBitmap bmp)
{
    m_bitmap = bmp;
    this->GetSizer()->SetMinSize(m_bitmap.GetWidth(),m_bitmap.GetHeight());
    this->GetSizer()->Fit(this);
    Layout();
    Refresh();
}

void wxThemeImageDialog::OnPaint(wxPaintEvent& WXUNUSED(event))
{
    wxPaintDC dc( this );
    dc.DrawBitmap( m_bitmap, 0, 0, true /* use mask */ );
}

////////////////// Themes page ////////////////////////
BEGIN_EVENT_TABLE(wxThemesPage,wxWizardPageSimple)
	EVT_WIZARD_PAGE_CHANGED          (wxID_ANY, wxThemesPage::OnPageShown)
	EVT_WIZARD_PAGE_CHANGING         (wxID_ANY, wxThemesPage::OnWizardPageChanging)
	EVT_LISTBOX                      (ID_LISTBOX,wxThemesPage::OnListBox)
	EVT_BUTTON                       (ID_PREVIEW_BTN, wxThemesPage::OnPreviewBtn)
	EVT_CHECKBOX                     (ID_INSTALLCHECKBOX, wxThemesPage::OnCheckBox)
END_EVENT_TABLE();

wxThemesPage::wxThemesPage(wxWizard *parent) : wxWizardPageSimple(parent)
{
    m_parent = parent;

    myImageDialog = new wxThemeImageDialog(this,wxID_ANY,wxT("Preview"),NULL);
    myImageDialog->Show(false);

    wxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);

    wxStaticText* WxStaticText1 = new wxStaticText(this, wxID_ANY,
        wxT("Please select the Theme you would like to"
        "\ninstall on your Device from the list below:"));
    mainSizer->Add(WxStaticText1,0,wxGROW | wxALL,5);

    // create theme listbox
    wxArrayString list;
    for(int i = 0; i< 35;i++)
        list.Add(wxT(""));
    ThemesListBox= new wxListBox(this, ID_LISTBOX, wxDefaultPosition,
        wxDefaultSize,list, wxLB_SINGLE);
    mainSizer->Add(ThemesListBox,10,wxGROW | wxALL,5);

    // create groupbox
    wxStaticBox* groupbox= new wxStaticBox(this,wxID_ANY,wxT("Selected Theme:"));
    wxBoxSizer* styleSizer = new wxStaticBoxSizer( groupbox, wxVERTICAL );
    mainSizer->Add(styleSizer,11,wxGROW | wxALL,5);

    // horizontal sizer
    wxBoxSizer* wxBoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
    styleSizer->Add(wxBoxSizer2,0,wxGROW | wxALL,0);

    // preview button
    m_previewBtn = new wxButton(this, ID_PREVIEW_BTN, wxT("Preview"),
         wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator,
        wxT("PreviewBtn"));
    wxBoxSizer2->Add(m_previewBtn,0,wxGROW | wxALL,5);

    // checkbox for Install
    m_InstallCheckBox= new wxCheckBox(this,ID_INSTALLCHECKBOX,wxT("Install")
        ,wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator,
        wxT("InstallCheckbox"));
    wxBoxSizer2->Add(m_InstallCheckBox,0,wxGROW | wxALL,5);

    // horizontal sizer
    wxBoxSizer* wxBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
    styleSizer->Add(wxBoxSizer3,0,wxGROW | wxALL,0);

    // File size
    wxStaticText* size= new wxStaticText(this,wxID_ANY,wxT("Filesize:"));
    wxBoxSizer3->Add(size,0,wxGROW | wxALL,5);

    m_size= new wxStaticText(this,wxID_ANY,wxT(""));
    wxBoxSizer3->Add(m_size,0,wxGROW | wxALL,5);

    // Description
    wxStaticText* desc= new wxStaticText(this,wxID_ANY,wxT("Description:"));
    styleSizer->Add(desc,0,wxGROW | wxALL,5);

    m_desc= new wxStaticText(this,wxID_ANY,wxT(""));
    styleSizer->Add(m_desc,0,wxGROW | wxALL,5);

    SetSizer(mainSizer);
    mainSizer->Fit(this);

}

bool wxThemesPage::TransferDataFromWindow()
{
    gv->themesToInstall.Clear();

    for(int i=0; i < m_installTheme.GetCount(); i++)
    {
        if(m_installTheme[i])
        {
            gv->themesToInstall.Add(m_Themes_path[i]);
        }
    }

    return true;

}

void wxThemesPage::OnWizardPageChanging(wxWizardEvent& event)
{
   if(event.GetDirection())  // going forwards in the Wizard
   {
        if(gv->themesToInstall.GetCount() == 0)
        {
            WARN_DIALOG(wxT("You have not selected a Theme to Install"), wxT("Select a Theme"));
            event.Veto();
        }
   }
}

void wxThemesPage::OnCheckBox(wxCommandEvent& event)
{
    int index = ThemesListBox->GetSelection();         //get Index
    if(index == wxNOT_FOUND)
        return;

    m_installTheme[index]= ! m_installTheme[index];    // Toggle install

}

void wxThemesPage::OnListBox(wxCommandEvent& event)
{
    int index = ThemesListBox->GetSelection();  //get Index
    if(index == wxNOT_FOUND)
        return;

    m_desc->SetLabel(m_Themes_desc[index]);     //set Desc
    m_desc->Wrap(270);                       // wrap desc
    m_size->SetLabel(m_Themes_size[index]+wxT(" kb"));  //set file size
    m_InstallCheckBox->SetValue(m_installTheme[index]);  // set the install checkbox

    this->GetSizer()->Layout();

    if(myImageDialog->IsShown())
    {
        wxString src,dest;

        int pos = m_Themes_image[index].Find('/',true);
        wxString filename = m_Themes_image[index](pos+1,m_Themes_image[index].Length());

        dest.Printf(wxT("%s" PATH_SEP "download" PATH_SEP "%s"),
                gv->stdpaths->GetUserDataDir().c_str(),gv->curresolution.c_str());

        if(!wxDirExists(dest))
            wxMkdir(dest);

        //this is a URL no PATH_SEP
        src.Printf(wxT("%s/data/%s/%s"),gv->themes_url.c_str(),gv->curresolution.c_str(),filename.c_str());
        dest.Printf(wxT("%s" PATH_SEP "download" PATH_SEP "%s" PATH_SEP "%s"),
            gv->stdpaths->GetUserDataDir().c_str(),gv->curresolution.c_str(),filename.c_str());

        if(DownloadURL(src, dest))
        {
            MESG_DIALOG(wxT("Unable to download image."));
            return;
        }

        wxBitmap bmp;
        bmp.LoadFile(dest,wxBITMAP_TYPE_PNG);
        myImageDialog->SetImage(bmp);
    }

}

void wxThemesPage::OnPreviewBtn(wxCommandEvent& event)
{

    int index = ThemesListBox->GetSelection();
    if(index == wxNOT_FOUND)
        return;

    wxString src,dest;

    int pos = m_Themes_image[index].Find('/',true);
    wxString filename = m_Themes_image[index](pos+1,m_Themes_image[index].Length());

    dest.Printf(wxT("%s" PATH_SEP "download" PATH_SEP "%s"),
            gv->stdpaths->GetUserDataDir().c_str(),gv->curresolution.c_str());

    if(!wxDirExists(dest))
        wxMkdir(dest);

    //this is a URL no PATH_SEP
    src.Printf(wxT("%s/data/%s/%s"),gv->themes_url.c_str(),gv->curresolution.c_str(),filename.c_str());
    dest.Printf(wxT("%s" PATH_SEP "download" PATH_SEP "%s" PATH_SEP "%s"),
        gv->stdpaths->GetUserDataDir().c_str(),gv->curresolution.c_str(),filename.c_str());

    if(DownloadURL(src, dest))
    {
        MESG_DIALOG(wxT("Unable to download image."));
        return;
    }

    wxBitmap bmp;
    bmp.LoadFile(dest,wxBITMAP_TYPE_PNG);

    myImageDialog->SetImage(bmp);

    myImageDialog->Show(true);

}

void wxThemesPage::OnPageShown(wxWizardEvent& event)
{
    // clear Theme info
    m_Themes.Clear();
    m_Themes_image.Clear();
    m_Themes_path.Clear();
    m_Themes_desc.Clear();
    m_Themes_size.Clear();
    m_installTheme.Clear();
    m_desc->SetLabel(wxT(""));
    m_size->SetLabel(wxT(""));
    m_InstallCheckBox->SetValue(false);

    //get correct Themes list
    wxString src,dest,err;

    src.Printf(wxT("%srbutil.php?res=%s"),gv->themes_url.c_str(),gv->curresolution.c_str());
    dest.Printf(wxT("%s" PATH_SEP "download" PATH_SEP "%s.list"),
        gv->stdpaths->GetUserDataDir().c_str(),gv->curresolution.c_str());

    if(DownloadURL(src, dest))
    {
        MESG_DIALOG(wxT("Unable to download themes list."));
        return;
    }

    //read and parse Themes list
    wxString themelistraw;
    wxFFile themefile;
    if(!themefile.Open(dest))       //open file
    {
        MESG_DIALOG(wxT("Unable to open themes list."));
        return;
    }
    if(!themefile.ReadAll(&themelistraw))  //read complete file
    {
        MESG_DIALOG(wxT("Unable to read themes list."));
        return;
    }
    wxRegEx reAll(wxT("<body >(.+)</body>"));  //extract body part
    if(! reAll.Matches(themelistraw))
    {
        MESG_DIALOG(wxT("Themes list is in wrong Format."));
        return;
    }
    wxString lines = reAll.GetMatch(themelistraw,1);

    // prepare text
    lines.Replace(wxT("<br />"),wxT(""),true);   //replace <br /> with nothing
    lines.Replace(wxT("\n"),wxT(""),true);   //replace \n with nothing
    lines.Trim(true);                         //strip WS at end
    lines.Trim(false);                         //strip WS at beginning
    wxStringTokenizer tkz(lines,wxT("|"));   //tokenize it

    while ( tkz.HasMoreTokens() )           // read all entrys
    {
        m_Themes.Add(tkz.GetNextToken());         //Theme name
        m_Themes_path.Add(tkz.GetNextToken());    //Theme path
        m_Themes_size.Add(tkz.GetNextToken());    //File size
        m_Themes_image.Add(tkz.GetNextToken());   //Screenshot
        m_Themes_desc.Add(tkz.GetNextToken());    //Description
        m_installTheme.Add(false);                //Theme should be installed ?
    }

    // set ThemeList
    ThemesListBox->Set(m_Themes);
}

 //////////////////// Ipod Locaction Page /////////////////////////////
BEGIN_EVENT_TABLE(wxIpodLocationPage,wxWizardPageSimple)
	EVT_BUTTON   (ID_IPODLOCATION_BTN, wxIpodLocationPage::OnIpodLocationBtn)
	EVT_WIZARD_PAGE_CHANGING(wxID_ANY, wxIpodLocationPage::OnWizardPageChanging)
END_EVENT_TABLE();

wxIpodLocationPage::wxIpodLocationPage(wxWizard* parent) : wxWizardPageSimple(parent)
{

    wxBoxSizer* WxBoxSizer1 = new wxBoxSizer(wxVERTICAL);

    // Header text
    IpodLocationLabel = new wxStaticText(this, wxID_ANY,
        wxT("Rockbox utility needs to know the device where your ipod\n"
            "device is located on your computer. Use the\n"
            "Scan Button:"));
    WxBoxSizer1->Add(IpodLocationLabel,0,wxGROW | wxALL, 5);

    // device location
   	wxBoxSizer* WxBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
   	WxBoxSizer1->Add(WxBoxSizer3,0,
        wxGROW | wxALIGN_CENTER_VERTICAL | wxALL, 5);

  	IpodLocationText = new wxStaticText(this, wxID_ANY, wxT(""),
        wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
    WxBoxSizer3->Add(IpodLocationText,1,
        wxGROW | wxALIGN_CENTER_VERTICAL | wxALL, 5);

    IpodLocationBtn = new wxButton(this, ID_IPODLOCATION_BTN, wxT("Scan"),
        wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator,
        wxT("IpodLocationBtn"));
   	IpodLocationBtn->SetToolTip(wxT("Scan for your Ipod"));
   	WxBoxSizer3->Add(IpodLocationBtn,0,wxALIGN_CENTER_VERTICAL | wxALL, 5);

     // Extra text
    IpodLocationExtraText = new wxStaticText(this,wxID_ANY, wxT(""));
    WxBoxSizer1->Add(IpodLocationExtraText,0,wxGROW | wxALL, 5);

   	SetSizer(WxBoxSizer1);
    WxBoxSizer1->Fit(this);
}

wxWizardPage* wxIpodLocationPage::GetPrev() const
{
    if(gv->curbootloadermethod == wxT("ipodpatcher"))   //if ipod, skip previous
    {
        if(wxWizardPageSimple::GetPrev()->GetPrev() != NULL)
            return wxWizardPageSimple::GetPrev()->GetPrev();

    }
}

void wxIpodLocationPage::OnWizardPageChanging(wxWizardEvent& event)
{
   if(event.GetDirection())  // going forwards in the Wizard
   {
       if(gv->curbootloadermethod==wxT("ipodpatcher"))
       {
            if(IpodLocationText->GetLabel() == wxT("no Ipod found") ||
                    IpodLocationText->GetLabel() ==wxT("More than 1 Ipod found") ||
                    IpodLocationText->GetLabel() ==wxT(""))
            {
                WARN_DIALOG(wxT("No valid ipod found!"), wxT("Select Location"));
                event.Veto();       //stop pagechanging
            }
       }
   }
}

void wxIpodLocationPage::OnIpodLocationBtn(wxCommandEvent& event)
{
    wxLogVerbose(wxT("=== begin wxIpodLocationPage::OnIpodLocationBtn"));
    struct ipod_t ipod;
    int n = ipod_scan(&ipod);
    gv->curbootloader=wxT("");

    if(n == 0)
      IpodLocationText->SetLabel(wxT("no Ipod found"));
    else if( n==1)
    {
      gv->curbootloader=wxT("bootloader-");
      gv->curbootloader.Append(wxString(ipod.targetname, wxConvUTF8));
      IpodLocationText->SetLabel(wxString(ipod.modelstr, wxConvUTF8));
    }
    else
      IpodLocationText->SetLabel(wxT("More than 1 Ipod found"));

    if(ipod.macpod)
      IpodLocationExtraText->SetLabel(wxT("This Ipod is a Mac formated Ipod\n"
                                      "Rockbox will not work on this.\n"
                                      "You have to convert it first to Fat32"));
    wxLogVerbose(wxT("=== end wxIpodLocationPage::OnIpodLocationBtn"));

}

BEGIN_EVENT_TABLE(wxBootLocationPage,wxWizardPageSimple)
	EVT_BUTTON   (ID_BOOTLOCATION_BTN, wxBootLocationPage::OnBootLocationBtn)
	EVT_WIZARD_PAGE_CHANGING(wxID_ANY, wxBootLocationPage::OnWizardPageChanging)
	EVT_WIZARD_PAGE_CHANGED (wxID_ANY, wxBootLocationPage::OnPageShown)
END_EVENT_TABLE();

wxBootLocationPage::wxBootLocationPage(wxWizard* parent) : wxWizardPageSimple(parent)
    {

    wxBoxSizer* WxBoxSizer1 = new wxBoxSizer(wxVERTICAL);

    // Header text
    BootLocationLabel = new wxStaticText(this, wxID_ANY,
        wxT("Rockbox utility needs to know the folder where your audio\n"
            "device is located on your computer.  Currently Rockbox utility\n"
            "is configured to use the following location:"));
    WxBoxSizer1->Add(BootLocationLabel,0,wxGROW | wxALL, 5);

    // device location
   	wxBoxSizer* WxBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
   	WxBoxSizer1->Add(WxBoxSizer3,0,
        wxGROW | wxALIGN_CENTER_VERTICAL | wxALL, 5);

    if (gv->curdestdir == wxT("")) gv->curdestdir = wxT("<none>");
  	BootLocationText = new wxStaticText(this, wxID_ANY, gv->curdestdir,
        wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
    WxBoxSizer3->Add(BootLocationText,1,
        wxGROW | wxALIGN_CENTER_VERTICAL | wxALL, 5);

   	BootLocationBtn = new wxButton(this, ID_BOOTLOCATION_BTN, wxT("Change"),
        wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator,
        wxT("BootLocationBtn"));
   	BootLocationBtn->SetToolTip(wxT("Select the location of your audio device"));
   	WxBoxSizer3->Add(BootLocationBtn,0,wxALIGN_CENTER_VERTICAL | wxALL, 5);


    BootLocationInfo = new wxStaticText(this, wxID_ANY, wxT(""),
        wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
    WxBoxSizer1->Add(BootLocationInfo,0,
        wxGROW | wxALIGN_CENTER_VERTICAL | wxALL, 5);

   	SetSizer(WxBoxSizer1);
    WxBoxSizer1->Fit(this);
}

wxWizardPage* wxBootLocationPage::GetPrev() const
{
    if(gv->curbootloadermethod != wxT("fwpatcher"))
    {
        if(wxWizardPageSimple::GetPrev()->GetPrev() != NULL)
            return wxWizardPageSimple::GetPrev()->GetPrev();

    }

    return wxWizardPageSimple::GetPrev();
}

wxWizardPage* wxBootLocationPage::GetNext() const
{
    if(gv->curbootloadermethod == wxT("ipodpatcher"))
    {
        return wxWizardPageSimple::GetNext();  // if ipod then this is not the last page
    }
    else return NULL;  // else this is the last page
}

void wxBootLocationPage::OnPageShown(wxWizardEvent& event)
{
   if(gv->curplat == wxT("h10") || gv->curplat == wxT("h10_5gb"))
   {
      BootLocationInfo->SetLabel(wxT("Your Device needs to be in UMS Mode. \n\n"
                                     "If it is an MTP device, you can do this by \n"
                                     "reseting you Device via the Pinhole,or disconnecting the Battery \n"
                                     "then connecting it via the Data cable with the PC. \n"
                                     "Then press and hold Next,push the Power button, and \n"
                                     "continue to hold the Next button until the \n"
                                     "USB-Connected Screen appears." ));
   }
   else
   {
      BootLocationInfo->SetLabel(wxT(""));
   }

}

void wxBootLocationPage::OnWizardPageChanging(wxWizardEvent& event)
{
   if(event.GetDirection())  // going forwards in the Wizard
   {
      if(!wxDirExists(BootLocationText->GetLabel()))
      {
          WARN_DIALOG(wxT("You have not selected a valid location for your audio "
                    "device"), wxT("Select Location"));
           event.Veto();
      }

   }
}

bool wxBootLocationPage::TransferDataFromWindow()
{
    gv->curdestdir = BootLocationText->GetLabel();
    return true;

}


void wxBootLocationPage::OnBootLocationBtn(wxCommandEvent& event)
{
   const wxString& temp = wxDirSelector(
        wxT("Please select the location of your audio device"), gv->curdestdir);
   wxLogVerbose(wxT("=== begin wxBootLocationPage::OnBootLocationBtn(event)"));
   if (!temp.empty())
   {
           BootLocationText->SetLabel(temp);
   }
   wxLogVerbose(wxT("=== end wxBootLocationPage::OnBootLocationBtn"));

}


BEGIN_EVENT_TABLE(wxFirmwareLocationPage,wxWizardPageSimple)
	EVT_BUTTON   (ID_FIRMWARELOCATION_BTN, wxFirmwareLocationPage::OnFirmwareFilenameBtn)
	EVT_WIZARD_PAGE_CHANGING(wxID_ANY, wxFirmwareLocationPage::OnWizardPageChanging)
END_EVENT_TABLE();

wxFirmwareLocationPage::wxFirmwareLocationPage(wxWizard* parent) : wxWizardPageSimple(parent)
{

    wxBoxSizer* WxBoxSizer1 = new wxBoxSizer(wxVERTICAL);

    // Header text
    FirmwareLocationText = new wxStaticText(this, wxID_ANY,
        wxT("For this step Rockbox Utility needs an original Firmware.\n"
             "You can download this from the Manufacturers Website."));
    WxBoxSizer1->Add(FirmwareLocationText,0,wxGROW | wxALL, 5);

    // Filename text
    wxBoxSizer* WxBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
   	WxBoxSizer1->Add(WxBoxSizer4,0,
        wxGROW | wxALIGN_CENTER_VERTICAL | wxALL, 5);

    FirmwareLocationFilename = new wxStaticText(this, wxID_ANY, gv->curfirmware,
        wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
    WxBoxSizer4->Add(FirmwareLocationFilename,1,
        wxGROW | wxALIGN_CENTER_VERTICAL | wxALL, 5);

    // Button
    FirmwareLocationBtn = new wxButton(this, ID_FIRMWARELOCATION_BTN, wxT("Explore"),
        wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator,
        wxT("FirmwareLocationBtn"));
    FirmwareLocationBtn->SetToolTip(wxT("Select the location of the downloaded Firmware"));
    WxBoxSizer4->Add(FirmwareLocationBtn,0,wxALIGN_CENTER_VERTICAL | wxALL, 5);


   	SetSizer(WxBoxSizer1);
    WxBoxSizer1->Fit(this);
}

void wxFirmwareLocationPage::OnWizardPageChanging(wxWizardEvent& event)
{
   if(event.GetDirection())  // going forwards in the Wizard
   {
        if( !wxFileExists(gv->curfirmware))
        {
            WARN_DIALOG(wxT("You have not selected a valid location for the firmware "
                      "file"), wxT("Select File"));
            event.Veto();
        }
   }

}

void wxFirmwareLocationPage::OnFirmwareFilenameBtn(wxCommandEvent& event)
{
     wxString temp = wxFileSelector(
        wxT("Please select the location of the original Firmware"), gv->curdestdir,wxT(""),wxT(""),wxT("*.hex"));
       wxLogVerbose(wxT("=== begin wxFirmwareLocationPage::OnFirmwareFilenameBtn(event)"));
       if (!temp.empty())
       {
           gv->curfirmware=temp;
           if(temp.Length() > 30)
           {
                temp.Remove(0, temp.Length()-30);
                temp.Prepend(wxT("..."));
           }
           FirmwareLocationFilename->SetLabel(temp);
       }
       wxLogVerbose(wxT("=== end wxFirmwareLocationPage::OnFirmwareFilenameBtn"));
}

BEGIN_EVENT_TABLE(wxLocationPage,wxWizardPageSimple)
	EVT_BUTTON   (ID_LOCATION_BTN, wxLocationPage::OnLocationBtn)
	EVT_WIZARD_PAGE_CHANGING(wxID_ANY, wxLocationPage::OnWizardPageChanging)
	EVT_WIZARD_PAGE_CHANGED(wxID_ANY, wxLocationPage::OnPageShown)
END_EVENT_TABLE();

wxLocationPage::wxLocationPage(wxWizard* parent) : wxWizardPageSimple(parent)
    {
    wxBoxSizer* WxBoxSizer1 = new wxBoxSizer(wxVERTICAL);

    wxStaticText* WxStaticText1 = new wxStaticText(this, wxID_ANY,
        wxT("Rockbox utility needs to know the folder where your audio\n"
            "device is located on your computer.  Currently Rockbox utility\n"
            "is configured to use the following location:"));
    WxBoxSizer1->Add(WxStaticText1,0,wxGROW | wxALL, 5);

   	wxBoxSizer* WxBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
   	WxBoxSizer1->Add(WxBoxSizer3,0,
        wxGROW | wxALIGN_CENTER_VERTICAL | wxALL, 5);

    if (gv->curdestdir == wxT("")) gv->curdestdir = wxT("<none>");
  	LocationText = new wxStaticText(this, wxID_ANY, gv->curdestdir,
        wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
    WxBoxSizer3->Add(LocationText,1,
        wxGROW | wxALIGN_CENTER_VERTICAL | wxALL, 5);

   	wxButton* LocationBtn = new wxButton(this, ID_LOCATION_BTN, wxT("Change"),
        wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator,
        wxT("LocationBtn"));
   	LocationBtn->SetToolTip(wxT("Select the location of your audio device"));
   	WxBoxSizer3->Add(LocationBtn,0,wxALIGN_CENTER_VERTICAL | wxALL, 5);

   	LocationInfo = new wxStaticText(this, wxID_ANY, wxT(""),
        wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
    WxBoxSizer1->Add(LocationInfo,0,wxGROW | wxALL, 5);

   	SetSizer(WxBoxSizer1);
    WxBoxSizer1->Fit(this);
}


void wxLocationPage::OnPageShown(wxWizardEvent& event)
{
   if(gv->curplat == wxT("h10") || gv->curplat == wxT("h10_5gb"))
   {
      LocationInfo->SetLabel(wxT("Your Device needs to be in UMS Mode. \n\n"
                                     "If it is an MTP device, you can do this by \n"
                                     "reseting you Device via the Pinhole,or disconnecting the Battery \n"
                                     "then connecting it via the Data cable with the PC. \n"
                                     "Then press and hold Next,push the Power button, and \n"
                                     "continue to hold the Next button until the \n"
                                     "USB-Connected Screen appears." ));
   }
   else
   {
      LocationInfo->SetLabel(wxT(""));
   }


}

void wxLocationPage::OnWizardPageChanging(wxWizardEvent& event)
{
   if(event.GetDirection())  // going forwards in the Wizard
   {
        if(!wxDirExists(LocationText->GetLabel()))
        {
              WARN_DIALOG(wxT("You have not selected a valid location for your audio "
            "device"), wxT("Select Location"));
            event.Veto();
        }
   }
}

bool wxLocationPage::TransferDataFromWindow()
{
    gv->curdestdir = LocationText->GetLabel();
    return true;
}

void wxLocationPage::OnLocationBtn(wxCommandEvent& event)
{
    const wxString& temp = wxDirSelector(
        wxT("Please select the location of your audio device"), gv->curdestdir);
    wxLogVerbose(wxT("=== begin wxLocationPage::OnLocationBtn(event)"));
    if (!temp.empty())
    {
        LocationText->SetLabel(temp);
    }
    wxLogVerbose(wxT("=== end wxLocationPage::OnLocationBtn"));
}

BEGIN_EVENT_TABLE(wxBuildPage,wxWizardPageSimple)
	EVT_RADIOBOX                     (ID_BUILD_BOX, wxBuildPage::OnBuildBox)
	EVT_WIZARD_PAGE_CHANGED          (wxID_ANY, wxBuildPage::OnPageShown)
END_EVENT_TABLE();


wxBuildPage::wxBuildPage(wxWizard *parent) : wxWizardPageSimple(parent)
{
    wxString buf;

    wxBoxSizer* WxBoxSizer1 = new wxBoxSizer(wxVERTICAL);

    wxStaticText* WxStaticText1 = new wxStaticText(this, wxID_ANY,
    wxT("Please select the Rockbox version you would like "
        "to install on your audio\ndevice:"));
    WxBoxSizer1->Add(WxStaticText1,0,wxGROW | wxALL,5);

    wxArrayString* array = new wxArrayString();
    buf.Printf(wxT("Rockbox stable version (%s)") , gv->last_release.c_str());
    array->Add(buf);
    array->Add(wxT("Archived Build"));
    array->Add(wxT("Current Build "));

    BuildRadioBox = new wxRadioBox(this, ID_BUILD_BOX, wxT("Version"),
        wxDefaultPosition, wxDefaultSize, *array, 0, wxRA_SPECIFY_ROWS);
    WxBoxSizer1->Add(BuildRadioBox, 0, wxGROW | wxALL, 5);
    delete array;

    wxStaticBox* WxStaticBox1 = new wxStaticBox(this, wxID_ANY, wxT("Details:"));
    wxStaticBoxSizer* WxStaticBoxSizer2 = new wxStaticBoxSizer(WxStaticBox1,
        wxVERTICAL);
    DetailText = new wxStaticText(this, wxID_ANY, wxT(""));
    WxBoxSizer1->Add(WxStaticBoxSizer2, 1, wxGROW | wxALL, 5);
    WxStaticBoxSizer2->Add(DetailText, 1, wxGROW | wxALL, 5);

    wxStaticText* WxStaticText2 = new wxStaticText(this, wxID_ANY,
        wxT("Rockbox Utility stores copies of Rockbox it has downloaded on the\n"
        "local hard disk to save network traffic.  If your local copy is\n"
        "no longer working, tick this box to download a fresh copy.") );
    WxBoxSizer1->Add(WxStaticText2, 0 , wxALL, 5);

    NoCacheCheckBox = new wxCheckBox(this, wxID_ANY,
        wxT("Don't use locally cached copies of Rockbox") );
    WxBoxSizer1->Add(NoCacheCheckBox, 0, wxALL, 5);

    SetSizer(WxBoxSizer1);
    WxBoxSizer1->Fit(this);
    WxBoxSizer1->SetSizeHints(this);
}

bool wxBuildPage::TransferDataFromWindow()
{
    gv->curbuild = BuildRadioBox->GetSelection();
    gv->nocache = (gv->curbuild == BUILD_BLEEDING) ? true :
                  NoCacheCheckBox->IsChecked();
    return true;
}

void wxBuildPage::OnBuildBox(wxCommandEvent& event)
{
    wxString str;

    switch(BuildRadioBox->GetSelection() )
    {
         case BUILD_RELEASE:
            str = _("This is the last released version of Rockbox, and is the\n"
               "recommended version to install.");
            NoCacheCheckBox->Enable();
            break;
         case BUILD_DAILY:
            str = _("These are automatically built each day from the current\n"
                "development source code.  This generally has more features\n"
                "than the last release but may be much less stable.  Features\n"
                "may change regularly.");
            NoCacheCheckBox->Enable();
            break;
        case BUILD_BLEEDING:
            str = _("This is the absolute up to the minute Rockbox built after\n"
                "the last change was made.\n\n"
                "Note:  This option will always download a fresh copy from the\n"
                "web server.\n");
            NoCacheCheckBox->Enable(false);
            break;
        default:
            break;
    }

    DetailText->SetLabel(str);
}

void wxBuildPage::OnPageShown(wxWizardEvent& event)
{
    wxCommandEvent updateradiobox(wxEVT_COMMAND_RADIOBOX_SELECTED,
        ID_BUILD_BOX);

    if (gv->plat_released[gv->curplatnum] )
    {
        BuildRadioBox->Enable(BUILD_RELEASE, true);
        BuildRadioBox->SetSelection(BUILD_RELEASE);
    } else {
        BuildRadioBox->Enable(BUILD_RELEASE, false);
        BuildRadioBox->SetSelection(BUILD_DAILY);

    }

    wxPostEvent(this, updateradiobox);
}

wxFullUninstallPage::wxFullUninstallPage(wxWizard* parent) :
    wxWizardPageSimple(parent)
{
    wxString buf;

	wxBoxSizer* WxBoxSizer1 = new wxBoxSizer(wxVERTICAL);

    wxStaticText* WxStaticText1 = new wxStaticText(this, wxID_ANY,
        wxT("Rockbox Utility normally uninstalls Rockbox using an uninstall\n"
          "file created during installation.  This means that when Rockbox is\n"
          "uninstalled all your configuration files are preserved.  However,\n"
          "you can also perform a full uninstall, which will completely\n"
          "remove all traces of Rockbox from your system, and can be used\n"
          "even if Rockbox was previously installed manually.\n\n"
          "Archos users will need to reinstall any firmware upgrades obtained\n"
          "from Archos after a full uninstall."));
    WxBoxSizer1->Add(WxStaticText1,0,wxGROW | wxALL,5);

    FullCheckBox = new wxCheckBox(this, wxID_ANY,
        wxT("Perform a full uninstall"));
    WxBoxSizer1->Add(FullCheckBox, 0, wxALL, 5);

    SetSizer(WxBoxSizer1);
    WxBoxSizer1->Fit(this);
    WxBoxSizer1->SetSizeHints(this);
}

bool wxFullUninstallPage::TransferDataFromWindow()
{
    gv->curisfull = FullCheckBox->IsChecked();
    return true;
}