4 #include "guibuilder.h"
5 #include "icons/wizard.xpm"
8 ID_CHOOSE_DIRECTORY_BUTTON
11 class NewVMNameWizardPage
: public wxWizardPageSimple
14 NewVMNameWizardPage(wxWizard
*parent
) : wxWizardPageSimple(parent
){
16 title = new wxTextCtrl(this, -1, wxT(""), wxPoint(24,64), wxSize(361,21), 0, wxDefaultValidator, wxT("title"));
18 wxStaticBox *WxStaticBox2 = new wxStaticBox(this, -1, wxT("Virtual machine title"), wxPoint(13,45), wxSize(390,55));
20 wxButton *button = new wxButton(this, CHOOSE_DIRECTORY_BUTTON, wxT("Browse"), wxPoint(310,135), wxSize(75,25), 0, wxDefaultValidator, wxT("directoryButton"));
22 directory = new wxTextCtrl(this, -1, wxT(""), wxPoint(24,136), wxSize(278,21), 0, wxDefaultValidator, wxT("directory"));
24 wxStaticBox *WxStaticBox1 = new wxStaticBox(this, -1, wxT("Location"), wxPoint(13,118), wxSize(390,55));
26 wxGuiBuilder
gb(wxString::FromAscii(
28 " H'Set your virtual machine title'{ "
29 " [----------------]+,1:title "
32 " V'Select the operating system'{ "
33 " ( ) 'Microsoft Windows'< "
39 " H'Set a directory'{ "
40 " [------],1:directory ['Browse']:button "
45 gb
<< wxGbTextCtrl(wxT("title"), &title
, wxID_ANY
);
46 gb
<< wxGbTextCtrl(wxT("directory"), &directory
, wxID_ANY
);
47 gb
<< wxGbButton(wxT("button"),NULL
,ID_CHOOSE_DIRECTORY_BUTTON
);
48 if(gb
.Build(this, wxID_ANY
)){
49 this->SetSizerAndFit(gb
.GetSizer());
53 void OnWizardPageChanging(wxWizardEvent
& event
)
55 // if we go backwards don't check
56 if(!event
.GetDirection())
59 if(!title
->GetValue())
62 _("You need to specify a name for your virtual machine."),
63 _("Required information missing"),
64 wxICON_WARNING
| wxOK
,
72 if(!directory
->GetValue())
75 _("You need to specify a directory for your virtual machine."),
76 _("Required information missing"),
77 wxICON_WARNING
| wxOK
,
80 directory
->SetFocus();
85 if(!wxDirExists(directory
->GetValue())){
86 wxMessageBox(_("The specified directory doesn't exists."),
88 wxICON_ERROR
| wxOK
, this);
94 if(!f
.Create(GetFileName(),true)){
95 wxMessageBox(_("The specified directory/file isn't writeable."),
97 wxICON_ERROR
| wxOK
, this);
103 void ChooseDirectory(wxCommandEvent
& WXUNUSED(event
)){
105 wxGetHomeDir(&dirHome
);
107 wxDirDialog
dialog(this, _("Choose a directory for your VM"),dirHome
,
108 wxDD_DEFAULT_STYLE
| wxDD_NEW_DIR_BUTTON
);
110 if (dialog
.ShowModal() == wxID_OK
)
112 directory
->SetValue(dialog
.GetPath());
117 return title
->GetValue();
120 wxString
GetFileName(){
122 file
= directory
->GetValue() << wxT("/") << title
->GetValue() << wxT(".qvmc");
128 wxTextCtrl
*directory
;
129 DECLARE_EVENT_TABLE();
132 BEGIN_EVENT_TABLE(NewVMNameWizardPage
,wxWizardPageSimple
)
133 EVT_BUTTON(ID_CHOOSE_DIRECTORY_BUTTON
,NewVMNameWizardPage::ChooseDirectory
)
134 EVT_WIZARD_PAGE_CHANGING(wxID_ANY
,NewVMNameWizardPage::OnWizardPageChanging
)
137 QemuUINewVMWizard::QemuUINewVMWizard(wxFrame
*frame
)
138 :wxWizard(frame
,wxID_ANY
,_("New Virtual Machine")){
140 this->welcome
= new wxWizardPageSimple(this,NULL
,NULL
,wxBitmap(QEMU_NEW_VM_WIZARD_IMAGE
));
142 /* wxStaticText *text = */ new wxStaticText(welcome
, wxID_ANY
,
143 _("This wizard will guide you through the steps of creating \n"
144 "a new virtual machine."),
145 wxPoint(5,5),wxSize(390,100)
148 page1
= new NewVMNameWizardPage(this);
149 wxWizardPageSimple::Chain(welcome
,page1
);
151 // allow the wizard to size itself around the pages
152 this->GetPageAreaSizer()->Add(welcome
);
153 this->GetPageAreaSizer()->Add(page1
);
156 void QemuUINewVMWizard::OnWizardCancel(wxWizardEvent
& event
)
158 if(wxMessageBox(_("Do you really want to cancel?"), _("Question"),
159 wxICON_QUESTION
| wxYES_NO
, this) != wxYES
){
164 QemuVM
* QemuUINewVMWizard::RunIt(){
165 if(RunWizard(this->welcome
)){
166 QemuVM
*vm
= new QemuVM(page1
->GetFileName());
167 vm
->SetTitle(page1
->GetTitle());
175 BEGIN_EVENT_TABLE(QemuUINewVMWizard
, wxWizard
)
176 EVT_WIZARD_CANCEL(wxID_ANY
, QemuUINewVMWizard::OnWizardCancel
)