Added some temporary icons to the repository
[qemu-gui.git] / vmdialog.cpp
blob08706b4adabdd0edfcc4c065e2b35be7f3959cec
1 #include <wx/wx.h>
2 #include <wx/spinctrl.h>
3 #include "vm.h"
4 #include "vmdialog.h"
5 #include "guibuilder.h"
7 enum { ID_CHOOSE_DEVICE_BUTTON };
9 class QemuDeviceWidget : public wxPanel {
10 public:
11 QemuDeviceWidget(wxWindow *parent,wxString label) : wxPanel(parent){
12 wxGuiBuilder gb(wxT(
13 " H{'")+label+wxT("'|[------]|,1:selection ['Browse']:button}+ "
14 ));
16 gb << wxGbTextCtrl(wxT("selection"), &selection, wxID_ANY);
17 gb << wxGbButton(wxT("button"),NULL,ID_CHOOSE_DEVICE_BUTTON);
18 if(gb.Build(this, wxID_ANY)){
19 this->SetSizerAndFit(gb.GetSizer());
23 wxString GetValue(){
24 return selection->GetValue();
27 void SetValue(const wxString& value){
28 selection->SetValue(value);
31 protected:
32 virtual void DoSelection(){
33 wxString dirHome;
34 wxGetHomeDir(&dirHome);
36 wxFileDialog *dialog = new wxFileDialog(
37 this,
38 _("Choose a file"),
39 dirHome
42 if(dialog->ShowModal() == wxID_OK){
43 selection->SetValue(dialog->GetPath());
46 dialog->Destroy();
49 wxTextCtrl *selection;
50 private:
52 void OnChooseDevice(wxCommandEvent& WXUNUSED(event)){
53 DoSelection();
56 DECLARE_EVENT_TABLE()
59 BEGIN_EVENT_TABLE(QemuDeviceWidget,wxPanel)
60 EVT_BUTTON(ID_CHOOSE_DEVICE_BUTTON,QemuDeviceWidget::OnChooseDevice)
61 END_EVENT_TABLE()
63 class QemuDirectoryWidget : public QemuDeviceWidget {
64 public:
65 QemuDirectoryWidget(wxWindow *parent, wxString label) :
66 QemuDeviceWidget(parent,label){};
67 private:
68 void DoSelection(){
69 wxString dirHome;
70 wxGetHomeDir(&dirHome);
72 wxDirDialog *dialog = new wxDirDialog(
73 this,
74 _("Choose a directory"),
75 dirHome,
76 wxDD_DEFAULT_STYLE | wxDD_NEW_DIR_BUTTON
79 if(dialog->ShowModal() == wxID_OK){
80 selection->SetValue(dialog->GetPath());
83 dialog->Destroy();
87 QemuVMConfigDialog::QemuVMConfigDialog(wxWindow *parent,QemuVM *vm)
88 :wxPropertySheetDialog(parent, wxID_ANY, wxEmptyString)
90 this->vm = vm;
91 SetTitle(_("Edit virtual machine settings"));
92 CreateButtons(wxOK|wxCANCEL|wxHELP);
94 wxBookCtrlBase *notebook = GetBookCtrl();
95 notebook->AddPage(CreateGeneralPage(notebook),_("General"));
96 notebook->AddPage(CreateDevicePage(notebook),_("Devices"));
97 notebook->AddPage(CreateNetworkPage(notebook),_("Network"));
98 notebook->AddPage(CreateMiscPage(notebook),_("Misc"));
99 Load();
100 LayoutDialog();
103 QemuVMConfigDialog::~QemuVMConfigDialog(){
106 const wxString QemuVMConfigDialog::keyboardLayouts[] = {
107 wxT("ar"), wxT("de-ch"), wxT("es"), wxT("fo"), wxT("fr-ca"), wxT("hu"),
108 wxT("ja"), wxT("mk"), wxT("no"), wxT("pt-br"), wxT("sv"), wxT("da"),
109 wxT("en-gb"), wxT("et"), wxT("fr"), wxT("fr-ch"), wxT("is"), wxT("lt"),
110 wxT("nl"), wxT("pl"), wxT("ru"), wxT("th"), wxT("de"), wxT("en-us"),
111 wxT("fi"), wxT("fr-be"), wxT("hr"),wxT("it"), wxT("lv"), wxT("nl-be"),
112 wxT("pt"), wxT("sl"), wxT("tr")
115 void QemuVMConfigDialog::Load(){
116 title->SetValue(vm->GetTitle());
117 dir->SetValue(vm->GetPath());
118 smp->SetRange(1,255);
119 smp->SetValue(vm->GetSmp());
120 memory->SetRange(0,8*1024);
121 memory->SetValue(vm->GetMemory());
122 hda->SetValue(vm->GetHd(0));
123 hdb->SetValue(vm->GetHd(1));
124 hdc->SetValue(vm->GetHd(2));
125 hdd->SetValue(vm->GetHd(3));
126 cdrom->SetValue(vm->GetCdRom());
127 fda->SetValue(vm->GetFd(0));
128 fdb->SetValue(vm->GetFd(1));
129 smb->SetValue(vm->GetSMB());
130 tftp->SetValue(vm->GetTFTP());
131 wxString boot = vm->GetBoot();
132 boota->SetValue(boot.IsSameAs(wxT("a")));
133 bootc->SetValue(boot.IsSameAs(wxT("c")) || boot.IsEmpty());
134 bootd->SetValue(boot.IsSameAs(wxT("d")));
135 keyboard->SetStringSelection(vm->GetKeyboardLayout());
136 localtime->SetValue(vm->GetLocalTime());
137 win2khack->SetValue(vm->GetWin2kHack());
138 stdvga->SetValue(vm->GetStdVga());
139 noacpi->SetValue(vm->GetNoACPI());
140 snapshotmode->SetValue(vm->GetSnapshotMode());
141 vncdisplay->SetValue(vm->GetVNCDisplay());
142 vncdisplay->SetRange(-1,255);
143 cmdlineargs->SetValue(vm->GetCmdlineArguments());
146 void QemuVMConfigDialog::Save(){
147 vm->SetTitle(title->GetValue());
148 vm->SetSmp(smp->GetValue());
149 vm->SetMemory(memory->GetValue());
150 vm->SetHd(0,hda->GetValue());
151 vm->SetHd(1,hdb->GetValue());
152 vm->SetHd(2,hdc->GetValue());
153 vm->SetHd(3,hdd->GetValue());
154 vm->SetCdRom(cdrom->GetValue());
155 vm->SetFd(0,fda->GetValue());
156 vm->SetFd(1,fdb->GetValue());
157 vm->SetSMB(smb->GetValue());
158 vm->SetTFTP(tftp->GetValue());
160 wxString boot;
161 if(boota->GetValue())
162 boot = wxT("a");
163 else if(bootc->GetValue())
164 boot = wxT("c");
165 else
166 boot = wxT("d");
167 vm->SetBoot(boot);
169 vm->SetKeyboardLayout(keyboard->GetStringSelection());
170 vm->SetLocalTime(localtime->GetValue());
171 vm->SetWin2kHack(win2khack->GetValue());
172 vm->SetStdVga(stdvga->GetValue());
173 vm->SetNoACPI(noacpi->GetValue());
174 vm->SetSnapshotMode(snapshotmode->GetValue());
175 vm->SetVNCDisplay(vncdisplay->GetValue());
176 vm->SetCmdlineArguments(cmdlineargs->GetValue());
177 vm->SaveConfig();
180 wxPanel* QemuVMConfigDialog::CreateGeneralPage(wxWindow *parent){
181 wxPanel *panel = new wxPanel(parent);
182 wxGuiBuilder gb(wxString::FromAscii(
183 " V{ "
184 " V'Set your virtual machine title'{ "
185 " [----------------]+:title "
186 " }+ "
188 " V'Select the operating system'{ "
189 " ( ) 'Microsoft Windows'< "
190 " ( ) 'GNU/Linux'< "
191 " ( ) '*BSD'< "
192 " (*) 'Another'< "
193 " }+ "
195 " V'Set a directory'{ "
196 // " [----------------]+:directory "
197 " $1.0a+ "
198 " }+ "
199 " } "
201 gb << wxGbTextCtrl(wxT("title"), &title, wxID_ANY);
202 gb << wxGbWindowStub(1,dir = new QemuDirectoryWidget(panel,wxT("")));
203 if(gb.Build(panel, wxID_ANY)){
204 panel->SetSizerAndFit(gb.GetSizer());
206 return panel;
209 wxPanel* QemuVMConfigDialog::CreateDevicePage(wxWindow *parent){
210 wxPanel *panel = new wxPanel(parent);
211 wxGuiBuilder gb(wxString::FromAscii(
212 " V{ "
213 " %w< "
214 " H'CPU / RAM'{ "
215 " 'SMP:'|$1+ "
216 " 'RAM:'|$2+ "
217 " }+ "
219 " V'Harddisks'{ "
220 " $3.0a+ "
221 " $4.0a+ "
222 " $5.0a+ "
223 " $6.0a+ "
225 " H{'hda:'|[------]|,1:hda ['Browse']:button1}.0bt+ "
226 " H{'hdb:'|[------]|,1:hdb ['Browse']:button2}.0bt+ "
227 " H{'hdc:'|[------]|,1:hdc ['Browse']:button3}.0bt+ "
228 " H{'hdd:'|[------]|,1:hdd ['Browse']:button4}.0bt+ "
230 " }+ "
232 " V'CD-ROM'{ "
233 " $7.0a+ "
234 " }+ "
236 " V'Floppy disks'{ "
237 " $8.0a+ "
238 " $9.0a+ "
239 " }+ "
240 " } "
243 gb << wxGbWindowStub(1,smp = new wxSpinCtrl(panel));
244 gb << wxGbWindowStub(2,memory = new wxSpinCtrl(panel));
245 gb << wxGbWindowStub(3,hda = new QemuDeviceWidget(panel,wxT("hda:")));
246 gb << wxGbWindowStub(4,hdb = new QemuDeviceWidget(panel,wxT("hdb:")));
247 gb << wxGbWindowStub(5,hdc = new QemuDeviceWidget(panel,wxT("hdc:")));
248 gb << wxGbWindowStub(6,hdd = new QemuDeviceWidget(panel,wxT("hdd:")));
249 gb << wxGbWindowStub(7,cdrom=new QemuDeviceWidget(panel,wxT("cdrom:")));
250 gb << wxGbWindowStub(8,fda = new QemuDeviceWidget(panel,wxT("fda:")));
251 gb << wxGbWindowStub(9,fdb = new QemuDeviceWidget(panel,wxT("fdb:")));
253 if(gb.Build(panel, wxID_ANY)){
254 panel->SetSizerAndFit(gb.GetSizer());
257 return panel;
260 wxPanel* QemuVMConfigDialog::CreateNetworkPage(wxWindow *parent){
261 wxPanel *panel = new wxPanel(parent);
262 wxGuiBuilder gb(wxString::FromAscii(
263 " V{ "
264 " V'SMB'{ "
265 " $1.0a+ "
266 " }+ "
268 " V'TFTP'{ "
269 " $2.0a+ "
270 " }+ "
271 " } "
274 gb << wxGbWindowStub(1,smb = new QemuDirectoryWidget(panel,wxT("")));
275 gb << wxGbWindowStub(2,tftp= new QemuDirectoryWidget(panel,wxT("")));
277 if(gb.Build(panel, wxID_ANY)){
278 panel->SetSizerAndFit(gb.GetSizer());
281 return panel;
284 wxPanel* QemuVMConfigDialog::CreateMiscPage(wxWindow *parent){
285 wxPanel *panel = new wxPanel(parent);
286 wxGuiBuilder gb(wxString::FromAscii(
287 " V{ "
288 " %w< "
289 " H'Select the boot media'{ "
290 " ( ) 'Floppy disk':boota "
291 " (*) 'Hard disk':bootc "
292 " ( ) 'CD-ROM':bootd "
293 " }<+ "
295 " H'Keyboard layout'{ "
296 " $1+ "
297 " }+ "
299 " V'Various options'{ "
300 " [ ] 'Set the real time clock to local time [default=utc]':localtime "
301 " [ ] 'Enable win2k-hack, use it when installing Windows 2000\nto avoid a disk full bug':win2khack"
302 " [ ] 'Simulate a standard VGA card with Bochs VBE extensions\n(default is Cirrus Logic GD5446 PCI VGA). If your guest OS\nsupports the VESA 2.0 VBE extensions (e.g. Windows XP) and\nif you want to use high resolution modes (>= 1280x1024x16)\nthen you should use this option.':stdvga "
303 " [ ] 'Disable ACPI (Advanced Configuration and Power Interface)\nsupport. Use it if your guest OS complains about ACPI\nproblems (PC target machine only).':noacpi "
304 " [ ] 'Snapshot mode, write to temporary files instead of disk image files.':snapshotmode "
305 " }+ "
307 " H'VNC Display'{ "
308 " 'VNC display number:'|$2+ "
309 " }+ "
311 " H'Additional command line arguments'{ "
312 " [-------------]+,1:cmdlineargs "
313 " }+ "
314 " } "
317 gb << wxGbRadioButton(wxT("boota"), &boota, wxID_ANY);
318 gb << wxGbRadioButton(wxT("bootc"), &bootc, wxID_ANY);
319 gb << wxGbRadioButton(wxT("bootd"), &bootd, wxID_ANY);
320 wxArrayString layouts(
321 sizeof(keyboardLayouts) / sizeof(keyboardLayouts[0]),
322 keyboardLayouts
324 layouts.Sort();
325 gb << wxGbWindowStub(1,keyboard = new wxChoice(
326 panel,
327 wxID_ANY,
328 wxDefaultPosition,
329 wxDefaultSize,
330 layouts
332 gb << wxGbCheckBox(wxT("localtime"), &localtime, wxID_ANY);
333 gb << wxGbCheckBox(wxT("win2khack"), &win2khack, wxID_ANY);
334 gb << wxGbCheckBox(wxT("stdvga"), &stdvga, wxID_ANY);
335 gb << wxGbCheckBox(wxT("noacpi"), &noacpi, wxID_ANY);
336 gb << wxGbCheckBox(wxT("snapshotmode"), &snapshotmode, wxID_ANY);
337 gb << wxGbWindowStub(2,vncdisplay = new wxSpinCtrl(panel));
338 gb << wxGbTextCtrl(wxT("cmdlineargs"), &cmdlineargs, wxID_ANY);
339 if(gb.Build(panel, wxID_ANY)){
340 panel->SetSizerAndFit(gb.GetSizer());
343 return panel;