Use new vnc syntax (with a colon).
[qemu-gui.git] / wizard.cpp
blobe3c31b41058ab40f0ea649b340a5ca53b39789cd
1 #include <wx/wx.h>
2 #include "wizard.h"
3 #include "vm.h"
4 #include "guibuilder.h"
5 #include "icons/wizard.xpm"
7 enum {
8 ID_CHOOSE_DIRECTORY_BUTTON
9 };
11 class NewVMNameWizardPage : public wxWizardPageSimple
13 public:
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(
27 " V{ "
28 " H'Set your virtual machine title'{ "
29 " [----------------]+,1:title "
30 " }+ "
31 " "
32 " V'Select the operating system'{ "
33 " ( ) 'Microsoft Windows'< "
34 " ( ) 'GNU/Linux'< "
35 " ( ) '*BSD'< "
36 " (*) 'Another'< "
37 " }+ "
38 " "
39 " H'Set a directory'{ "
40 " [------],1:directory ['Browse']:button "
41 " }+ "
42 " } "
43 ));
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())
57 return;
59 if(!title->GetValue())
61 wxMessageBox(
62 _("You need to specify a name for your virtual machine."),
63 _("Required information missing"),
64 wxICON_WARNING | wxOK,
65 this
67 title->SetFocus();
68 event.Veto();
69 return;
72 if(!directory->GetValue())
74 wxMessageBox(
75 _("You need to specify a directory for your virtual machine."),
76 _("Required information missing"),
77 wxICON_WARNING | wxOK,
78 this
80 directory->SetFocus();
81 event.Veto();
82 return;
85 if(!wxDirExists(directory->GetValue())){
86 wxMessageBox(_("The specified directory doesn't exists."),
87 _("Error"),
88 wxICON_ERROR | wxOK, this);
89 event.Veto();
90 return;
93 wxFile f;
94 if(!f.Create(GetFileName(),true)){
95 wxMessageBox(_("The specified directory/file isn't writeable."),
96 _("Error"),
97 wxICON_ERROR | wxOK, this);
98 event.Veto();
99 return;
103 void ChooseDirectory(wxCommandEvent& WXUNUSED(event)){
104 wxString dirHome;
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());
116 wxString GetTitle(){
117 return title->GetValue();
120 wxString GetFileName(){
121 wxString file;
122 file = directory->GetValue() << wxT("/") << title->GetValue() << wxT(".qvmc");
123 return file;
126 private:
127 wxTextCtrl *title;
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)
135 END_EVENT_TABLE()
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 ){
160 event.Veto();
164 QemuVM* QemuUINewVMWizard::RunIt(){
165 if(RunWizard(this->welcome)){
166 QemuVM *vm = new QemuVM(page1->GetFileName());
167 vm->SetTitle(page1->GetTitle());
168 vm->SaveConfig();
169 return vm;
172 return NULL;
175 BEGIN_EVENT_TABLE(QemuUINewVMWizard, wxWizard)
176 EVT_WIZARD_CANCEL(wxID_ANY, QemuUINewVMWizard::OnWizardCancel)
177 END_EVENT_TABLE()