66import platformSpecific .unixSpecific
77import subprocess
88from dialogExecution .vhdExistsDialog import VhdAlreadyExists
9+ from dialogExecution .vmExistsDialog import VmAlreadyExistsDialog
910
1011class EditVirtualMachineDialog (QDialog , Ui_Dialog ):
1112 def __init__ (self , parent = None ):
1213 super ().__init__ (parent )
1314 self .setupUi (self )
1415 self .connectSignalsSlots ()
1516 self .vmSpecs = self .readTempVmFile ()
17+ self .setWindowTitle (f"EmuGUI - Edit { self .vmSpecs [0 ]} " )
1618
1719 if platform .system () == "Windows" :
1820 tempVmDef = platformSpecific .windowsSpecific .windowsTempVmStarterFile ()
@@ -34,6 +36,7 @@ def connectSignalsSlots(self):
3436 self .pushButton_19 .clicked .connect (self .close )
3537 self .pushButton_21 .clicked .connect (self .close )
3638 self .pushButton_23 .clicked .connect (self .close )
39+ self .pushButton_26 .clicked .connect (self .close )
3740
3841 self .pushButton_3 .clicked .connect (self .archSystem )
3942
@@ -52,17 +55,23 @@ def connectSignalsSlots(self):
5255 self .pushButton_18 .clicked .connect (self .vhdMenu )
5356
5457 self .pushButton_17 .clicked .connect (self .extBios )
55- self .pushButton_25 .clicked .connect (self .extBios )
58+ self .pushButton_25 .clicked .connect (self .vgaNetworkMenu )
5659
57- self .pushButton_24 .clicked .connect (self .win2kHacker )
60+ self .pushButton_24 .clicked .connect (self .soundCard )
61+ self .pushButton_28 .clicked .connect (self .extBios )
5862
59- self .pushButton_22 .clicked .connect (self .extBios )
63+ self .pushButton_22 .clicked .connect (self .linuxVMSpecific )
64+ self .pushButton_27 .clicked .connect (self .linuxVMSpecific )
65+
66+ self .pushButton .clicked .connect (self .linuxKernelBrowseLocation )
67+
68+ self .pushButton_32 .clicked .connect (self .linuxInitridBrowseLocation )
6069
6170 self .pushButton_13 .clicked .connect (self .vhdBrowseLocation )
6271
63- self .pushButton_20 .clicked .connect (self .finishCreation )
72+ self .pushButton_30 .clicked .connect (self .win2kHacker )
6473
65- self .pushButton .clicked .connect (self .biosBrowseLocation )
74+ self .pushButton_20 .clicked .connect (self .finishCreation )
6675
6776 def machineCpuI386Amd64 (self , machine , cpu ):
6877 i = 0
@@ -190,20 +199,75 @@ def readTempVmFile(self):
190199
191200 self .lineEdit_2 .setText (vmSpecs [11 ])
192201
202+ i = 0
203+
204+ while i < self .comboBox_12 .count ():
205+ if self .comboBox_12 .itemText (i ) == vmSpecs [12 ]:
206+ self .comboBox_12 .setCurrentIndex (i )
207+ break
208+
209+ i += 1
210+
211+ self .lineEdit_4 .setText (vmSpecs [13 ])
212+ self .lineEdit_5 .setText (vmSpecs [14 ])
213+ self .lineEdit_7 .setText (vmSpecs [15 ])
214+
193215 return vmSpecs
194216
195217 def archSystem (self ):
196- if self .comboBox .currentText () == "i386" :
197- self .stackedWidget .setCurrentIndex (1 )
218+ if platform .system () == "Windows" :
219+ connection = platformSpecific .windowsSpecific .setupWindowsBackend ()
220+
221+ else :
222+ connection = platformSpecific .unixSpecific .setupUnixBackend ()
198223
199- elif self .comboBox .currentText () == "x86_64" :
200- self .stackedWidget .setCurrentIndex (1 )
224+ cursor = connection .cursor ()
225+
226+ check_vm_name = f"""
227+ SELECT name FROM virtualmachines
228+ WHERE name = "{ self .lineEdit .text ()} ";
229+ """
230+
231+ try :
232+ cursor .execute (check_vm_name )
233+ connection .commit ()
234+ result = cursor .fetchall ()
235+
236+ try :
237+ qemu_img_slot = str (result [0 ])
238+
239+ if self .lineEdit .text () != self .vmSpecs [0 ]:
240+ dialog2 = VmAlreadyExistsDialog (self )
241+ dialog2 .exec ()
242+
243+ else :
244+ if self .comboBox .currentText () == "i386" :
245+ self .stackedWidget .setCurrentIndex (1 )
246+
247+ elif self .comboBox .currentText () == "x86_64" :
248+ self .stackedWidget .setCurrentIndex (1 )
201249
202- elif self .comboBox .currentText () == "ppc" :
203- self .stackedWidget .setCurrentIndex (2 )
250+ elif self .comboBox .currentText () == "ppc" :
251+ self .stackedWidget .setCurrentIndex (2 )
204252
205- elif self .comboBox .currentText () == "mips64el" :
206- self .stackedWidget .setCurrentIndex (3 )
253+ elif self .comboBox .currentText () == "mips64el" :
254+ self .stackedWidget .setCurrentIndex (3 )
255+
256+ except :
257+ if self .comboBox .currentText () == "i386" :
258+ self .stackedWidget .setCurrentIndex (1 )
259+
260+ elif self .comboBox .currentText () == "x86_64" :
261+ self .stackedWidget .setCurrentIndex (1 )
262+
263+ elif self .comboBox .currentText () == "ppc" :
264+ self .stackedWidget .setCurrentIndex (2 )
265+
266+ elif self .comboBox .currentText () == "mips64el" :
267+ self .stackedWidget .setCurrentIndex (3 )
268+
269+ except sqlite3 .Error as e :
270+ print (f"The SQLite module encountered an error: { e } ." )
207271
208272 def vhdMenu (self ):
209273 self .stackedWidget .setCurrentIndex (4 )
@@ -232,14 +296,44 @@ def vgaNetworkMenu(self):
232296 def extBios (self ):
233297 self .stackedWidget .setCurrentIndex (6 )
234298
235- def biosBrowseLocation (self ):
236- filename = QFileDialog .getExistingDirectory (parent = self , caption = 'Select the location of the desired external BIOS' , dir = '.' )
299+ def soundCard (self ):
300+ self .stackedWidget .setCurrentIndex (7 )
301+
302+ def linuxVMSpecific (self ):
303+ self .stackedWidget .setCurrentIndex (8 )
304+
305+ def linuxKernelBrowseLocation (self ):
306+ filename , filter = QFileDialog .getOpenFileName (parent = self , caption = 'Select Linux kernel' , dir = '.' , filter = 'All files (*.*)' )
237307
238308 if filename :
239- self .lineEdit_3 .setText (filename )
309+ self .lineEdit_4 .setText (filename )
310+
311+ try :
312+ file = open (filename , "r" )
313+ file .close ()
314+ dialog = VhdAlreadyExists (self )
315+ dialog .exec ()
316+
317+ except :
318+ pass
319+
320+ def linuxInitridBrowseLocation (self ):
321+ filename , filter = QFileDialog .getOpenFileName (parent = self , caption = 'Select Linux initrid image' , dir = '.' , filter = 'IMG files (*.img);;All files (*.*)' )
322+
323+ if filename :
324+ self .lineEdit_5 .setText (filename )
325+
326+ try :
327+ file = open (filename , "r" )
328+ file .close ()
329+ dialog = VhdAlreadyExists (self )
330+ dialog .exec ()
331+
332+ except :
333+ pass
240334
241335 def win2kHacker (self ):
242- self .stackedWidget .setCurrentIndex (7 )
336+ self .stackedWidget .setCurrentIndex (9 )
243337
244338 def finishCreation (self ):
245339 if platform .system () == "Windows" :
@@ -340,7 +434,10 @@ def finishCreation(self):
340434
341435 insert_into_vm_database = f"""
342436 UPDATE virtualmachines
343- SET name = "{ self .lineEdit .text ()} ", architecture = "{ self .comboBox .currentText ()} ", machine = "{ machine } ", cpu = "{ cpu } ", ram = { ram } , hda = "{ vhd } ", vga = "{ self .comboBox_10 .currentText ()} ", net = "{ networkAdapter } ", usbtablet = { usbtablet } , win2k = { win2k } , dirbios = "{ ext_bios_dir } ", additionalargs = "{ add_args } "
437+ SET name = "{ self .lineEdit .text ()} ", architecture = "{ self .comboBox .currentText ()} ", machine = "{ machine } ", cpu = "{ cpu } ",
438+ ram = { ram } , hda = "{ vhd } ", vga = "{ self .comboBox_10 .currentText ()} ", net = "{ networkAdapter } ", usbtablet = { usbtablet } ,
439+ win2k = { win2k } , dirbios = "{ ext_bios_dir } ", additionalargs = "{ add_args } ", sound = "{ self .comboBox_12 .currentText ()} ",
440+ linuxkernel = "{ self .lineEdit_4 .text ()} ", linuxinitrid = "{ self .lineEdit_5 .text ()} ", linuxcmd = "{ self .lineEdit_7 .text ()} "
344441 WHERE name = "{ self .vmSpecs [0 ]} ";
345442 """
346443
0 commit comments