/[pcsx2_0.9.7]/trunk/pcsx2/gui/Panels/BiosSelectorPanel.cpp
ViewVC logotype

Contents of /trunk/pcsx2/gui/Panels/BiosSelectorPanel.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 280 - (show annotations) (download)
Thu Dec 23 12:02:12 2010 UTC (9 years, 2 months ago) by william
File size: 5389 byte(s)
re-commit (had local access denied errors when committing)
1 /* PCSX2 - PS2 Emulator for PCs
2 * Copyright (C) 2002-2010 PCSX2 Dev Team
3 *
4 * PCSX2 is free software: you can redistribute it and/or modify it under the terms
5 * of the GNU Lesser General Public License as published by the Free Software Found-
6 * ation, either version 3 of the License, or (at your option) any later version.
7 *
8 * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 * PURPOSE. See the GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along with PCSX2.
13 * If not, see <http://www.gnu.org/licenses/>.
14 */
15
16 #include "PrecompiledHeader.h"
17 #include "App.h"
18 #include "ConfigurationPanels.h"
19
20 #include "Utilities/ScopedPtr.h"
21 #include "ps2/BiosTools.h"
22
23 #include <wx/dir.h>
24 #include <wx/filepicker.h>
25 #include <wx/listbox.h>
26
27 using namespace pxSizerFlags;
28
29 // =====================================================================================================
30 // BaseSelectorPanel
31 // =====================================================================================================
32 Panels::BaseSelectorPanel::BaseSelectorPanel( wxWindow* parent )
33 : BaseApplicableConfigPanel( parent, wxVERTICAL )
34 {
35 Connect( wxEVT_COMMAND_DIRPICKER_CHANGED, wxFileDirPickerEventHandler (BaseSelectorPanel::OnFolderChanged) );
36 Connect( wxEVT_SHOW, wxShowEventHandler (BaseSelectorPanel::OnShow) );
37 }
38
39 Panels::BaseSelectorPanel::~BaseSelectorPanel() throw()
40 {
41 }
42
43 void Panels::BaseSelectorPanel::OnShow(wxShowEvent& evt)
44 {
45 evt.Skip();
46 if( !evt.GetShow() ) return;
47 OnShown();
48 }
49
50 void Panels::BaseSelectorPanel::OnShown()
51 {
52 if( !ValidateEnumerationStatus() )
53 DoRefresh();
54 }
55
56 bool Panels::BaseSelectorPanel::Show( bool visible )
57 {
58 if( visible )
59 OnShown();
60
61 return BaseApplicableConfigPanel::Show( visible );
62 }
63
64 void Panels::BaseSelectorPanel::RefreshSelections()
65 {
66 ValidateEnumerationStatus();
67 DoRefresh();
68 }
69
70 void Panels::BaseSelectorPanel::OnRefreshSelections( wxCommandEvent& evt )
71 {
72 evt.Skip();
73 RefreshSelections();
74 }
75
76 void Panels::BaseSelectorPanel::OnFolderChanged( wxFileDirPickerEvent& evt )
77 {
78 evt.Skip();
79 OnShown();
80 }
81
82 // =====================================================================================================
83 // BiosSelectorPanel
84 // =====================================================================================================
85 Panels::BiosSelectorPanel::BiosSelectorPanel( wxWindow* parent )
86 : BaseSelectorPanel( parent )
87 {
88 SetMinWidth( 480 );
89
90 m_ComboBox = new wxListBox( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_SINGLE | wxLB_SORT | wxLB_NEEDED_SB );
91 m_FolderPicker = new DirPickerPanel( this, FolderId_Bios,
92 _("BIOS Search Path:"), // static box label
93 _("Select folder with PS2 BIOS roms") // dir picker popup label
94 );
95
96 m_ComboBox->SetFont( wxFont( m_ComboBox->GetFont().GetPointSize()+1, wxFONTFAMILY_MODERN, wxNORMAL, wxNORMAL, false, L"Lucida Console" ) );
97 m_ComboBox->SetMinSize( wxSize( wxDefaultCoord, std::max( m_ComboBox->GetMinSize().GetHeight(), 96 ) ) );
98
99 m_FolderPicker->SetStaticDesc( _("Click the Browse button to select a different folder where PCSX2 will look for PS2 BIOS roms.") );
100
101 wxButton* refreshButton = new wxButton( this, wxID_ANY, _("Refresh list") );
102
103 *this += Label(_("Select a BIOS rom:"));
104 *this += m_ComboBox | StdExpand();
105 *this += refreshButton | pxBorder(wxLEFT, StdPadding);
106 *this += 8;
107 *this += m_FolderPicker | StdExpand();
108
109 Connect( refreshButton->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(BiosSelectorPanel::OnRefreshSelections) );
110 }
111
112 Panels::BiosSelectorPanel::~BiosSelectorPanel() throw ()
113 {
114 }
115
116 void Panels::BiosSelectorPanel::Apply()
117 {
118 // User never visited this tab, so there's nothing to apply.
119 if( !m_BiosList ) return;
120
121 int sel = m_ComboBox->GetSelection();
122 if( sel == wxNOT_FOUND )
123 {
124 throw Exception::CannotApplySettings(this)
125 .SetDiagMsg(L"User did not specify a valid BIOS selection.")
126 .SetUserMsg( pxE( "!Notice:BIOS:InvalidSelection",
127 L"Please select a valid BIOS. If you are unable to make a valid selection "
128 L"then press cancel to close the Configuration panel."
129 ) );
130 }
131
132 g_Conf->BaseFilenames.Bios = (*m_BiosList)[(int)m_ComboBox->GetClientData(sel)];
133 }
134
135 void Panels::BiosSelectorPanel::AppStatusEvent_OnSettingsApplied()
136 {
137 }
138
139 bool Panels::BiosSelectorPanel::ValidateEnumerationStatus()
140 {
141 bool validated = true;
142
143 // Impl Note: ScopedPtr used so that resources get cleaned up if an exception
144 // occurs during file enumeration.
145 ScopedPtr<wxArrayString> bioslist( new wxArrayString() );
146
147 if( m_FolderPicker->GetPath().Exists() )
148 wxDir::GetAllFiles( m_FolderPicker->GetPath().ToString(), bioslist, L"*.*", wxDIR_FILES );
149
150 if( !m_BiosList || (*bioslist != *m_BiosList) )
151 validated = false;
152
153 m_BiosList.SwapPtr( bioslist );
154
155 return validated;
156 }
157
158 void Panels::BiosSelectorPanel::DoRefresh()
159 {
160 if( !m_BiosList ) return;
161
162 m_ComboBox->Clear();
163
164 const wxFileName right( g_Conf->FullpathToBios() );
165
166 for( size_t i=0; i<m_BiosList->GetCount(); ++i )
167 {
168 wxString description;
169 if( !IsBIOS((*m_BiosList)[i], description) ) continue;
170 int sel = m_ComboBox->Append( description, (void*)i );
171
172 if( wxFileName((*m_BiosList)[i] ) == right )
173 m_ComboBox->SetSelection( sel );
174 }
175 }

  ViewVC Help
Powered by ViewVC 1.1.22