/[pcsx2_0.9.7]/trunk/pcsx2/gui/Dialogs/FirstTimeWizard.cpp
ViewVC logotype

Contents of /trunk/pcsx2/gui/Dialogs/FirstTimeWizard.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: 8960 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 "System.h"
18 #include "Plugins.h"
19
20 #include "ModalPopups.h"
21 #include "Panels/ConfigurationPanels.h"
22 #include <wx/file.h>
23 #include <wx/filepicker.h>
24
25 using namespace Panels;
26 using namespace pxSizerFlags;
27
28 IMPLEMENT_DYNAMIC_CLASS(ApplicableWizardPage, wxWizardPageSimple)
29
30 ApplicableWizardPage::ApplicableWizardPage( wxWizard* parent, wxWizardPage* prev, wxWizardPage* next, const wxBitmap& bitmap )
31 : wxWizardPageSimple( parent, prev, next, bitmap )
32 {
33 }
34
35 // This is a hack feature substitute for prioritized apply events. This callback is issued prior
36 // to the apply chain being run, allowing a panel to do some pre-apply prepwork. PAnels implementing
37 // this function should not modify the g_conf state.
38 bool ApplicableWizardPage::PrepForApply()
39 {
40 return true;
41 }
42
43
44 // ----------------------------------------------------------------------------
45 Panels::SettingsDirPickerPanel::SettingsDirPickerPanel( wxWindow* parent )
46 : DirPickerPanel( parent, FolderId_Settings, _("Settings"), AddAppName(_("Select a folder for %s settings")) )
47 {
48 pxSetToolTip( this, pxEt( "!ContextTip:Folders:Settings",
49 L"This is the folder where PCSX2 saves your settings, including settings generated "
50 L"by most plugins (some older plugins may not respect this value)."
51 ) );
52
53 SetStaticDesc( pxE( "!Panel:Folders:Settings",
54 L"You may optionally specify a location for your PCSX2 settings here. If the location "
55 L"contains existing PCSX2 settings, you will be given the option to import or overwrite them."
56 ) );
57 }
58
59 // ----------------------------------------------------------------------------
60 FirstTimeWizard::UsermodePage::UsermodePage( wxWizard* parent ) :
61 ApplicableWizardPage( parent )
62 {
63 SetMinSize( wxSize(640, GetMinHeight()) );
64 SetSizer( new wxBoxSizer( wxVERTICAL ) );
65
66 wxPanelWithHelpers& panel( *new wxPanelWithHelpers( this, wxVERTICAL ) );
67
68 m_dirpick_settings = new SettingsDirPickerPanel( &panel );
69 m_panel_LangSel = new LanguageSelectionPanel( &panel );
70 m_panel_UserSel = new DocsFolderPickerPanel( &panel );
71
72 panel += panel.Heading(AddAppName(_("%s is starting from a new or unknown folder and needs to be configured."))).Bold();
73
74 panel += m_panel_LangSel | StdCenter();
75 panel += m_panel_UserSel | pxExpand.Border( wxALL, 8 );
76
77 panel += 6;
78 panel += m_dirpick_settings | SubGroup();
79
80 *this += panel | pxExpand;
81
82 Connect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler(UsermodePage::OnUsermodeChanged) );
83
84 Connect( m_panel_UserSel->GetDirPickerId(), wxEVT_COMMAND_DIRPICKER_CHANGED, wxCommandEventHandler(UsermodePage::OnCustomDirChanged) );
85 }
86
87 void FirstTimeWizard::UsermodePage::OnUsermodeChanged( wxCommandEvent& evt )
88 {
89 evt.Skip();
90 m_panel_UserSel->Apply();
91 g_Conf->Folders.ApplyDefaults();
92 m_dirpick_settings->Reset();
93 }
94
95 void FirstTimeWizard::UsermodePage::OnCustomDirChanged( wxCommandEvent& evt )
96 {
97 OnUsermodeChanged( evt );
98 }
99
100 bool FirstTimeWizard::UsermodePage::PrepForApply()
101 {
102 wxDirName path( PathDefs::GetDocuments(m_panel_UserSel->GetDocsMode()) );
103
104 if( path.FileExists() )
105 {
106 // FIXME: There's already a file by the same name.. not sure what we should do here.
107 throw Exception::BadStream( path.ToString() )
108 .SetDiagMsg(L"Targeted documents folder is already occupied by a file.")
109 .SetUserMsg(pxE( "!Notice:DocsFolderFileConflict",
110 L"PCSX2 cannot create a documents folder in the requested location. "
111 L"The path name matches an existing file. Delete the file or change the documents location, "
112 L"and then try again."
113 ));
114 }
115
116 if( !path.Exists() )
117 {
118 wxDialogWithHelpers dialog( NULL, _("Create folder?") );
119 dialog += dialog.Heading(AddAppName(_("%s will create the following folder for documents. You can change this setting later, at any time.")));
120 dialog += 12;
121 dialog += dialog.Heading( path.ToString() );
122
123 if( wxID_CANCEL == pxIssueConfirmation( dialog, MsgButtons().Custom(_("Create"), "create").Cancel(), L"CreateNewFolder" ) )
124 return false;
125 }
126 path.Mkdir();
127 return true;
128 }
129
130 // ----------------------------------------------------------------------------
131 FirstTimeWizard::FirstTimeWizard( wxWindow* parent )
132 : wxWizard( parent, wxID_ANY, AddAppName(_("%s First Time Configuration")) )
133 , m_page_usermode ( *new UsermodePage( this ) )
134 , m_page_plugins ( *new ApplicableWizardPage( this, &m_page_usermode ) )
135 , m_page_bios ( *new ApplicableWizardPage( this, &m_page_plugins ) )
136
137 , m_panel_PluginSel ( *new PluginSelectorPanel( &m_page_plugins ) )
138 , m_panel_BiosSel ( *new BiosSelectorPanel( &m_page_bios ) )
139 {
140 // Page 2 - Plugins Panel
141 // Page 3 - Bios Panel
142
143 m_page_plugins. SetSizer( new wxBoxSizer( wxVERTICAL ) );
144 m_page_bios. SetSizer( new wxBoxSizer( wxVERTICAL ) );
145
146 m_page_plugins += m_panel_PluginSel | StdExpand();
147 m_page_bios += m_panel_BiosSel | StdExpand();
148
149 // Temporary tutorial message for the BIOS, needs proof-reading!!
150 m_page_bios += 12;
151 m_page_bios += new pxStaticHeading( &m_page_bios,
152 pxE( "!Wizard:Bios:Tutorial",
153 L"PCSX2 requires a *legal* copy of the PS2 BIOS in order to run games.\n"
154 L"You cannot use a copy obtained from a friend or the Internet.\n"
155 L"You must dump the BIOS from your *own* Playstation 2 console."
156 )
157 ) | StdExpand();
158
159 // Assign page indexes as client data
160 m_page_usermode .SetClientData( (void*)0 );
161 m_page_plugins .SetClientData( (void*)1 );
162 m_page_bios .SetClientData( (void*)2 );
163
164 // Build the forward chain:
165 // (backward chain is built during initialization above)
166 m_page_usermode .SetNext( &m_page_plugins );
167 m_page_plugins .SetNext( &m_page_bios );
168
169 GetPageAreaSizer() += m_page_usermode;
170 GetPageAreaSizer() += m_page_plugins;
171
172 // this doesn't descent from wxDialogWithHelpers, so we need to explicitly
173 // fit and center it. :(
174
175 Connect( wxEVT_WIZARD_PAGE_CHANGED, wxWizardEventHandler (FirstTimeWizard::OnPageChanged) );
176 Connect( wxEVT_WIZARD_PAGE_CHANGING, wxWizardEventHandler (FirstTimeWizard::OnPageChanging) );
177 Connect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEventHandler (FirstTimeWizard::OnDoubleClicked) );
178
179 Connect( pxID_RestartWizard, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( FirstTimeWizard::OnRestartWizard ) );
180 }
181
182 FirstTimeWizard::~FirstTimeWizard() throw()
183 {
184
185 }
186
187 void FirstTimeWizard::OnRestartWizard( wxCommandEvent& evt )
188 {
189 EndModal( pxID_RestartWizard );
190 evt.Skip();
191 }
192
193 static void _OpenConsole()
194 {
195 g_Conf->ProgLogBox.Visible = true;
196 wxGetApp().OpenProgramLog();
197 }
198
199 int FirstTimeWizard::ShowModal()
200 {
201 if( IsDebugBuild ) wxGetApp().PostIdleMethod( _OpenConsole );
202 return _parent::ShowModal();
203 }
204
205 void FirstTimeWizard::OnDoubleClicked( wxCommandEvent& evt )
206 {
207 wxWindow* forwardButton = FindWindow( wxID_FORWARD );
208 if( forwardButton == NULL ) return;
209
210 wxCommandEvent nextpg( wxEVT_COMMAND_BUTTON_CLICKED, wxID_FORWARD );
211 nextpg.SetEventObject( forwardButton );
212 forwardButton->GetEventHandler()->ProcessEvent( nextpg );
213 }
214
215 void FirstTimeWizard::OnPageChanging( wxWizardEvent& evt )
216 {
217 if( evt.GetPage() == NULL ) return; // safety valve!
218
219 int page = (int)evt.GetPage()->GetClientData();
220
221 if( evt.GetDirection() )
222 {
223 // Moving forward:
224 // Apply settings from the current page...
225
226 if( page >= 0 )
227 {
228 if( ApplicableWizardPage* page = wxDynamicCast( GetCurrentPage(), ApplicableWizardPage ) )
229 {
230 if( !page->PrepForApply() || !page->GetApplyState().ApplyAll() )
231 {
232 evt.Veto();
233 return;
234 }
235 }
236 }
237
238 if( page == 0 )
239 {
240 if( wxFile::Exists( GetSettingsFilename() ) )
241 {
242 // Asks the user if they want to import or overwrite the existing settings.
243
244 Dialogs::ImportSettingsDialog modal( this );
245 if( modal.ShowModal() != wxID_OK )
246 {
247 evt.Veto();
248 return;
249 }
250 }
251 }
252 }
253 else
254 {
255 // Moving Backward:
256 // Some specific panels need per-init actions canceled.
257
258 if( page == 1 )
259 {
260 m_panel_PluginSel.CancelRefresh();
261 }
262 }
263 }
264
265 void FirstTimeWizard::OnPageChanged( wxWizardEvent& evt )
266 {
267 // Plugin Selector needs a special OnShow hack, because Wizard child panels don't
268 // receive any Show events >_<
269 if( (sptr)evt.GetPage() == (sptr)&m_page_plugins )
270 m_panel_PluginSel.OnShown();
271
272 else if( (sptr)evt.GetPage() == (sptr)&m_page_bios )
273 m_panel_BiosSel.OnShown();
274 }

  ViewVC Help
Powered by ViewVC 1.1.22