1 /****************************************************************************
2 **
3 ** Copyright (C) 2008-2010 Andrey Rijov <ANDron142@yandex.ru>
4 ** Copyirght (C) 2016 Tobias Gläßer
5 **
6 ** This file is part of AQEMU.
7 **
8 ** This program is free software; you can redistribute it and/or modify
9 ** it under the terms of the GNU General Public License as published by
10 ** the Free Software Foundation; either version 2 of the License.
11 **
12 ** This program is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ** GNU General Public License for more details.
16 **
17 ** You should have received a copy of the GNU General Public License
18 ** along with this program; if not, write to the Free Software
19 ** Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 ** Boston, MA 02110-1301, USA.
21 **
22 ****************************************************************************/
23
24 #include <QFileInfo>
25 #include <QMessageBox>
26 #include <QMenu>
27
28 #include "Device_Manager_Widget.h"
29 #include "Add_New_Device_Window.h"
30 #include "Utils.h"
31 #include "Create_HDD_Image_Window.h"
32 #include "System_Info.h"
33
Device_Manager_Widget(QWidget * parent)34 Device_Manager_Widget::Device_Manager_Widget( QWidget *parent )
35 : QWidget( parent )
36 {
37 ui.setupUi( this );
38
39 Enabled = true;
40
41 HDA_Info = new HDD_Image_Info();
42 HDB_Info = new HDD_Image_Info();
43 HDC_Info = new HDD_Image_Info();
44 HDD_Info = new HDD_Image_Info();
45
46 connect( HDA_Info, SIGNAL(Completed(bool)),
47 this, SLOT(Update_HDA(bool)) );
48
49 connect( HDB_Info, SIGNAL(Completed(bool)),
50 this, SLOT(Update_HDB(bool)) );
51
52 connect( HDC_Info, SIGNAL(Completed(bool)),
53 this, SLOT(Update_HDC(bool)) );
54
55 connect( HDD_Info, SIGNAL(Completed(bool)),
56 this, SLOT(Update_HDD(bool)) );
57
58 pw = new Properties_Window( this );
59 Context_Menu = new QMenu( ui.Devices_List );
60
61 ui.Devices_List->setSpacing( 3 );
62 ui.Devices_List->setFlow( QListView::TopToBottom );
63 ui.Devices_List->setViewMode( QListView::ListMode );
64 }
65
~Device_Manager_Widget()66 Device_Manager_Widget::~Device_Manager_Widget()
67 {
68 delete pw;
69 delete Context_Menu;
70
71 delete HDA_Info;
72 delete HDB_Info;
73 delete HDC_Info;
74 delete HDD_Info;
75 }
76
Set_VM(const Virtual_Machine & vm)77 void Device_Manager_Widget::Set_VM( const Virtual_Machine &vm )
78 {
79 ui.Devices_List->clear();
80 ui.Label_Connected_To->setText( "" );
81
82 if( vm.Get_Current_Emulator_Devices()->PSO_Drive ) ui.TB_Add_Device->setEnabled( true );
83
84 Floppy1 = VM_Storage_Device( vm.Get_FD0() );
85 Floppy2 = VM_Storage_Device( vm.Get_FD1() );
86 CD_ROM = VM_Storage_Device( vm.Get_CD_ROM() );
87
88 HDA = VM_HDD( vm.Get_HDA() );
89 HDB = VM_HDD( vm.Get_HDB() );
90 HDC = VM_HDD( vm.Get_HDC() );
91 HDD = VM_HDD( vm.Get_HDD() );
92
93 if( QFile::exists(HDA.Get_File_Name()) )
94 HDA_Info->Update_Disk_Info( HDA.Get_File_Name() );
95
96 if( QFile::exists(HDB.Get_File_Name()) )
97 HDB_Info->Update_Disk_Info( HDB.Get_File_Name() );
98
99 if( QFile::exists(HDC.Get_File_Name()) )
100 HDC_Info->Update_Disk_Info( HDC.Get_File_Name() );
101
102 if( QFile::exists(HDD.Get_File_Name()) )
103 HDD_Info->Update_Disk_Info( HDD.Get_File_Name() );
104
105 Storage_Devices.clear();
106
107 for( int ix = 0; ix < vm.Get_Storage_Devices_List().count(); ++ix )
108 {
109 Storage_Devices << vm.Get_Storage_Devices_List()[ix];
110 }
111
112 Update_Icons();
113 Update_Enabled_Actions();
114
115 Current_Machine_Devices = vm.Get_Current_Emulator_Devices();
116 }
117
Set_Enabled(bool on)118 void Device_Manager_Widget::Set_Enabled( bool on )
119 {
120 Enabled = on;
121
122 ui.Label_Add_Devices->setEnabled( on );
123 ui.TB_Add_Floppy->setEnabled( on );
124 ui.TB_Add_CDROM->setEnabled( on );
125 ui.TB_Add_HDD->setEnabled( on );
126 ui.TB_Add_Device->setEnabled( on );
127
128 ui.Label_Manage_Devices->setEnabled( on );
129 ui.TB_Edit_Device->setEnabled( on );
130 ui.TB_Delete_Device->setEnabled( on );
131 ui.TB_Format_HDD->setEnabled( on );
132 ui.TB_Quick_Format->setEnabled( on );
133
134 ui.Label_View_Mode->setEnabled( on );
135 ui.TB_Icon_Mode->setEnabled( on );
136 ui.TB_List_Mode->setEnabled( on );
137
138 //ui.Label_Devices_List->setEnabled( on );
139 ui.Label_Information->setEnabled( on );
140 ui.Label_Connected_To->setEnabled( on );
141 }
142
Update_Enabled_Actions()143 void Device_Manager_Widget::Update_Enabled_Actions()
144 {
145 // Adds
146 if( Floppy1.Get_Enabled() && Floppy2.Get_Enabled() )
147 {
148 ui.actionAdd_Floppy->setEnabled( false );
149 ui.TB_Add_Floppy->setEnabled( false );
150 }
151 else
152 {
153 ui.actionAdd_Floppy->setEnabled( true );
154 ui.TB_Add_Floppy->setEnabled( true );
155 }
156
157 if( CD_ROM.Get_Enabled() )
158 {
159 ui.actionAdd_CD_ROM->setEnabled( false );
160 ui.TB_Add_CDROM->setEnabled( false );
161 }
162 else
163 {
164 ui.actionAdd_CD_ROM->setEnabled( true );
165 ui.TB_Add_CDROM->setEnabled( true );
166 }
167
168 if( HDA.Get_Enabled() && HDB.Get_Enabled() &&
169 HDC.Get_Enabled() && HDD.Get_Enabled() )
170 {
171 ui.actionAdd_HDD->setEnabled( false );
172 ui.TB_Add_HDD->setEnabled( false );
173 }
174 else if( HDA.Get_Enabled() && HDB.Get_Enabled() &&
175 HDD.Get_Enabled() && CD_ROM.Get_Enabled() )
176 {
177 ui.actionAdd_HDD->setEnabled( false );
178 ui.TB_Add_HDD->setEnabled( false );
179 }
180 else
181 {
182 ui.actionAdd_HDD->setEnabled( true );
183 ui.TB_Add_HDD->setEnabled( true );
184 }
185
186 // Update Information
187 if( ui.Devices_List->currentItem() != NULL )
188 {
189 // item type
190 if( ui.Devices_List->currentItem()->data(512).toString() == "fd1" ||
191 ui.Devices_List->currentItem()->data(512).toString() == "fd2" )
192 {
193 ui.TB_Edit_Device->setEnabled( true );
194 ui.actionProperties->setEnabled( true );
195
196 ui.TB_Delete_Device->setEnabled( true );
197 ui.actionDelete->setEnabled( true );
198
199 ui.TB_Format_HDD->setEnabled( false );
200 ui.actionFormat_HDD->setEnabled( false );
201
202 ui.TB_Quick_Format->setEnabled( false );
203 ui.actionQuick_Format->setEnabled( false );
204
205 if( ui.Devices_List->currentItem()->data(512).toString() == "fd1" )
206 {
207 if( It_Host_Device(Floppy1.Get_File_Name()) )
208 {
209 ui.Label_Connected_To->setText( tr("Type: Host Device") );
210 }
211 else
212 {
213 QFileInfo fd_img = QFileInfo( Floppy1.Get_File_Name() );
214
215 if( fd_img.exists() )
216 {
217 qint64 size_in_bytes = fd_img.size();
218
219 if( size_in_bytes <= 0 )
220 {
221 ui.Label_Connected_To->setText( tr("Type: Image") + "\n" +
222 tr("On Disk Size: ") + QString::number(0) + tr("KB") );
223 }
224 else
225 {
226 ui.Label_Connected_To->setText( tr("Type: Image") + "\n" +
227 tr("On Disk Size: ") + QString::number((int)size_in_bytes / 1024.0) + tr("KB") );
228 }
229 }
230 else
231 {
232 ui.Label_Connected_To->setText( tr("Type: Image") + "\n" +
233 tr("On Disk Size: ") + QString::number(0) + tr("KB") );
234 }
235 }
236 }
237 else
238 {
239 if( It_Host_Device(Floppy2.Get_File_Name()) )
240 {
241 ui.Label_Connected_To->setText( tr("Type: Host Device") );
242 }
243 else
244 {
245 QFileInfo fd_img = QFileInfo( Floppy2.Get_File_Name() );
246
247 if( fd_img.exists() )
248 {
249 qint64 size_in_bytes = fd_img.size();
250
251 if( size_in_bytes <= 0 )
252 {
253 ui.Label_Connected_To->setText( tr("Type: Image") + "\n" +
254 tr("On Disk Size: ") + QString::number(0) + tr("KB") );
255 }
256 else
257 {
258 ui.Label_Connected_To->setText( tr("Type: Image") + "\n" +
259 tr("On Disk Size: ") + QString::number((int)size_in_bytes / 1024.0) + tr("KB") );
260 }
261 }
262 else
263 {
264 ui.Label_Connected_To->setText( tr("Type: Image") + "\n" +
265 tr("On Disk Size: ") + QString::number(0) + tr("MB") );
266 }
267 }
268 }
269 }
270 else if( ui.Devices_List->currentItem()->data(512).toString() == "cd" )
271 {
272 ui.TB_Edit_Device->setEnabled( true );
273 ui.actionProperties->setEnabled( true );
274
275 ui.TB_Delete_Device->setEnabled( true );
276 ui.actionDelete->setEnabled( true );
277
278 ui.TB_Format_HDD->setEnabled( false );
279 ui.actionFormat_HDD->setEnabled( false );
280
281 ui.TB_Quick_Format->setEnabled( false );
282 ui.actionQuick_Format->setEnabled( false );
283
284 if( It_Host_Device(CD_ROM.Get_File_Name()) )
285 {
286 ui.Label_Connected_To->setText( tr("Type: Host Device") );
287 }
288 else
289 {
290 QFileInfo cd_img = QFileInfo( CD_ROM.Get_File_Name() );
291
292 if( cd_img.exists() )
293 {
294 qint64 size_in_bytes = cd_img.size();
295
296 if( size_in_bytes <= 0 )
297 {
298 ui.Label_Connected_To->setText( tr("Type: Image") + "\n" +
299 tr("On Disk Size: ") + QString::number(0) + tr("MB") );
300 }
301 else
302 {
303 ui.Label_Connected_To->setText( tr("Type: Image") + "\n" +
304 tr("On Disk Size: ") + QString::number((float)(size_in_bytes / 1024.0 / 1024.0), 'f', 2) + tr("MB") );
305 }
306 }
307 else
308 {
309 ui.Label_Connected_To->setText( tr("Type: Image") + "\n" +
310 tr("On Disk Size: ") + QString::number(0) + tr("MB") );
311 }
312 }
313 }
314 else if( ui.Devices_List->currentItem()->data(512).toString() == "hda" ||
315 ui.Devices_List->currentItem()->data(512).toString() == "hdb" ||
316 ui.Devices_List->currentItem()->data(512).toString() == "hdc" ||
317 ui.Devices_List->currentItem()->data(512).toString() == "hdd" )
318 {
319 ui.TB_Edit_Device->setEnabled( true );
320 ui.actionProperties->setEnabled( true );
321
322 ui.TB_Delete_Device->setEnabled( true );
323 ui.actionDelete->setEnabled( true );
324
325 ui.TB_Format_HDD->setEnabled( true );
326 ui.actionFormat_HDD->setEnabled( true );
327
328 ui.TB_Quick_Format->setEnabled( true );
329 ui.actionQuick_Format->setEnabled( true );
330
331 if( ui.Devices_List->currentItem()->data(512).toString() == "hda" )
332 {
333 HDA_Info->Update_Disk_Info( HDA.Get_File_Name() );
334
335 ui.Label_Connected_To->setText( tr("Image Virtual Size: ") + QString::number(HDA.Get_Virtual_Size().Size) +
336 Get_TR_Size_Suffix(HDA.Get_Virtual_Size()) + "\n" +
337 tr("Image On Disk Size: ") + QString::number(HDA.Get_Disk_Size().Size) +
338 Get_TR_Size_Suffix(HDA.Get_Disk_Size()) );
339 }
340 else if( ui.Devices_List->currentItem()->data(512).toString() == "hdb" )
341 {
342 HDB_Info->Update_Disk_Info( HDB.Get_File_Name() );
343
344 ui.Label_Connected_To->setText( tr("Image Virtual Size: ") + QString::number(HDB.Get_Virtual_Size().Size) +
345 Get_TR_Size_Suffix(HDB.Get_Virtual_Size()) + "\n" +
346 tr("Image On Disk Size: ") + QString::number(HDB.Get_Disk_Size().Size) +
347 Get_TR_Size_Suffix(HDB.Get_Disk_Size()) );
348 }
349 else if( ui.Devices_List->currentItem()->data(512).toString() == "hdc" )
350 {
351 HDC_Info->Update_Disk_Info( HDC.Get_File_Name() );
352
353 ui.Label_Connected_To->setText( tr("Image Virtual Size: ") + QString::number(HDC.Get_Virtual_Size().Size) +
354 Get_TR_Size_Suffix(HDC.Get_Virtual_Size()) + "\n" +
355 tr("Image On Disk Size: ") + QString::number(HDC.Get_Disk_Size().Size) +
356 Get_TR_Size_Suffix(HDC.Get_Disk_Size()));
357 }
358 else if( ui.Devices_List->currentItem()->data(512).toString() == "hdd" )
359 {
360 HDD_Info->Update_Disk_Info( HDD.Get_File_Name() );
361
362 ui.Label_Connected_To->setText( tr("Image Virtual Size: ") + QString::number(HDD.Get_Virtual_Size().Size) +
363 Get_TR_Size_Suffix(HDD.Get_Virtual_Size()) + "\n" +
364 tr("Image On Disk Size: ") + QString::number(HDD.Get_Disk_Size().Size) +
365 Get_TR_Size_Suffix(HDD.Get_Disk_Size()));
366 }
367 }
368 else
369 {
370 bool found = false;
371
372 for( int fx = 0; fx < 32; ++fx )
373 {
374 if( ui.Devices_List->currentItem()->data(512).toString() == "device" + QString::number(fx) )
375 {
376 found = true;
377
378 ui.Label_Connected_To->setText( tr("Type: Storage Device") );
379
380 ui.TB_Edit_Device->setEnabled( true );
381 ui.actionProperties->setEnabled( true );
382
383 ui.TB_Delete_Device->setEnabled( true );
384 ui.actionDelete->setEnabled( true );
385
386 ui.TB_Format_HDD->setEnabled( false );
387 ui.actionFormat_HDD->setEnabled( false );
388
389 ui.TB_Quick_Format->setEnabled( false );
390 ui.actionQuick_Format->setEnabled( false );
391 }
392 }
393
394 if( ! found )
395 {
396 ui.TB_Edit_Device->setEnabled( false );
397 ui.actionProperties->setEnabled( false);
398
399 ui.TB_Delete_Device->setEnabled( false );
400 ui.actionDelete->setEnabled( false );
401
402 ui.TB_Format_HDD->setEnabled( false );
403 ui.actionFormat_HDD->setEnabled( false );
404
405 ui.TB_Quick_Format->setEnabled( false );
406 ui.actionQuick_Format->setEnabled( false );
407 }
408 }
409 }
410 else
411 {
412 ui.TB_Edit_Device->setEnabled( false );
413 ui.actionProperties->setEnabled( false);
414
415 ui.TB_Delete_Device->setEnabled( false );
416 ui.actionDelete->setEnabled( false );
417
418 ui.TB_Format_HDD->setEnabled( false );
419 ui.actionFormat_HDD->setEnabled( false );
420
421 ui.TB_Quick_Format->setEnabled( false );
422 ui.actionQuick_Format->setEnabled( false );
423 }
424
425 // Disable widgets
426 if( ! Enabled )
427 {
428 ui.actionAdd_Floppy->setEnabled( false );
429 ui.TB_Add_Floppy->setEnabled( false );
430
431 ui.actionAdd_CD_ROM->setEnabled( false );
432 ui.TB_Add_CDROM->setEnabled( false );
433
434 ui.actionAdd_HDD->setEnabled( false );
435 ui.TB_Add_HDD->setEnabled( false );
436
437 ui.TB_Delete_Device->setEnabled( false );
438 ui.actionDelete->setEnabled( false );
439
440 ui.TB_Format_HDD->setEnabled( false );
441 ui.actionFormat_HDD->setEnabled( false );
442
443 ui.TB_Quick_Format->setEnabled( false );
444 ui.actionQuick_Format->setEnabled( false );
445 }
446 }
447
Update_List_Mode()448 void Device_Manager_Widget::Update_List_Mode()
449 {
450 if( ui.Devices_List->viewMode() == QListView::IconMode )
451 {
452 ui.Devices_List->setSpacing( 10 );
453 ui.Devices_List->setFlow( QListView::LeftToRight );
454 ui.Devices_List->setViewMode( QListView::IconMode );
455 }
456 else
457 {
458 ui.Devices_List->setSpacing( 3 );
459 ui.Devices_List->setFlow( QListView::TopToBottom );
460 ui.Devices_List->setViewMode( QListView::ListMode );
461 }
462 }
463
on_Devices_List_customContextMenuRequested(const QPoint & pos)464 void Device_Manager_Widget::on_Devices_List_customContextMenuRequested( const QPoint &pos )
465 {
466 QListWidgetItem *it = ui.Devices_List->itemAt( pos );
467
468 if( it != NULL )
469 {
470 if( it->data(512).toString() == "fd1" ||
471 it->data(512).toString() == "fd2" )
472 {
473 Context_Menu = new QMenu( ui.Devices_List );
474
475 Context_Menu->addAction( ui.actionProperties );
476 Context_Menu->addAction( ui.actionDelete );
477
478 Context_Menu->exec( ui.Devices_List->mapToGlobal(pos) );
479 }
480 else if( it->data(512).toString() == "cd" )
481 {
482 Context_Menu = new QMenu( ui.Devices_List );
483
484 Context_Menu->addAction( ui.actionProperties );
485 Context_Menu->addAction( ui.actionDelete );
486
487 Context_Menu->exec( ui.Devices_List->mapToGlobal(pos) );
488 }
489 else if( it->data(512).toString() == "hda" ||
490 it->data(512).toString() == "hdb" ||
491 it->data(512).toString() == "hdc" ||
492 it->data(512).toString() == "hdd" )
493 {
494 Context_Menu = new QMenu( ui.Devices_List );
495
496 Context_Menu->addAction( ui.actionProperties );
497 Context_Menu->addAction( ui.actionDelete );
498 Context_Menu->addAction( ui.actionFormat_HDD );
499 Context_Menu->addAction( ui.actionQuick_Format );
500
501 Context_Menu->exec( ui.Devices_List->mapToGlobal(pos) );
502 }
503 else
504 {
505 bool found = false;
506
507 for( int fx = 0; fx < 32; ++fx )
508 {
509 if( ui.Devices_List->currentItem()->data(512).toString() == "device" + QString::number(fx) )
510 {
511 found = true;
512
513 Context_Menu = new QMenu( ui.Devices_List );
514
515 Context_Menu->addAction( ui.actionProperties );
516 Context_Menu->addAction( ui.actionDelete );
517
518 Context_Menu->exec( ui.Devices_List->mapToGlobal(pos) );
519 }
520 }
521
522 if( ! found )
523 {
524 AQError( "void Device_Manager_Widget::on_Devices_List_customContextMenuRequested( const QPoint &pos )",
525 "Incorrect Device!" );
526 }
527 }
528 }
529 else
530 {
531 Context_Menu = new QMenu( ui.Devices_List );
532
533 Context_Menu->addAction( ui.actionAdd_Floppy );
534 Context_Menu->addAction( ui.actionAdd_CD_ROM );
535 Context_Menu->addAction( ui.actionAdd_HDD );
536 Context_Menu->addSeparator();
537 Context_Menu->addAction( ui.actionIcon_Mode );
538 Context_Menu->addAction( ui.actionList_Mode );
539
540 Context_Menu->exec( ui.Devices_List->mapToGlobal(pos) );
541 }
542 }
543
on_Devices_List_currentItemChanged(QListWidgetItem * current,QListWidgetItem * previous)544 void Device_Manager_Widget::on_Devices_List_currentItemChanged(
545 QListWidgetItem *current, QListWidgetItem *previous )
546 {
547 Update_Enabled_Actions();
548 }
549
on_Devices_List_itemDoubleClicked(QListWidgetItem * item)550 void Device_Manager_Widget::on_Devices_List_itemDoubleClicked( QListWidgetItem *item )
551 {
552 on_actionProperties_triggered();
553 }
554
Add_Floppy(VM_Storage_Device & dev,int num)555 void Device_Manager_Widget::Add_Floppy(VM_Storage_Device& dev, int num)
556 {
557 dev = pw->Get_Floppy();
558
559 QString dev_name = dev.Get_File_Name();
560
561 if ( ! QFileInfo(dev_name).exists() )
562 return;
563
564 QListWidgetItem *fdit = new QListWidgetItem( QIcon(":/fdd.png"),
565 tr("Floppy") + " " + QString::number(num) + " (" + dev_name + ")" );
566 fdit->setData( 512, "fd" + QString::number(num) );
567 ui.Devices_List->addItem( fdit );
568
569 emit Device_Changed();
570 }
571
on_actionAdd_Floppy_triggered()572 void Device_Manager_Widget::on_actionAdd_Floppy_triggered()
573 {
574 if( ! Floppy1.Get_Enabled() )
575 {
576 pw = new Properties_Window(this);
577 pw->Set_Floppy( Floppy1, tr("Floppy 1") );
578
579 if( pw->exec() == QDialog::Accepted )
580 {
581 Add_Floppy(Floppy1,1);
582 }
583 }
584 else if( ! Floppy2.Get_Enabled() )
585 {
586 pw = new Properties_Window(this);
587 pw->Set_Floppy( Floppy2, tr("Floppy 2") );
588
589 if( pw->exec() == QDialog::Accepted )
590 {
591 Add_Floppy(Floppy2,2);
592 }
593 }
594 else
595 {
596 AQGraphic_Warning( tr("Warning!"),
597 tr("Maximum Floppy Disk Count is 2") );
598 }
599 }
600
on_actionAdd_CD_ROM_triggered()601 void Device_Manager_Widget::on_actionAdd_CD_ROM_triggered()
602 {
603 if( ! CD_ROM.Get_Enabled() )
604 {
605 pw = new Properties_Window(this);
606 pw->Set_Current_Machine_Devices( Current_Machine_Devices );
607 pw->Set_CD_ROM( CD_ROM, tr("CD/DVD-ROM") );
608
609 if( pw->exec() == QDialog::Accepted )
610 {
611 CD_ROM = pw->Get_CD_ROM();
612 CD_ROM.Set_Enabled( true );
613
614 QString dev_name = CD_ROM.Get_File_Name();
615
616 if ( ! QFileInfo(dev_name).exists() )
617 return;
618
619 QListWidgetItem *cdit = new QListWidgetItem( QIcon(":/cdrom.png"),
620 tr("CD-ROM") + " (" + dev_name + ")" , ui.Devices_List );
621 cdit->setData( 512, "cd" );
622
623 ui.Devices_List->addItem( cdit );
624
625 emit Device_Changed();
626 }
627 }
628 else
629 {
630 AQGraphic_Warning( tr("Warning!"),
631 tr("Maximum CD-ROM Disk Count is 1") );
632 }
633 }
634
635
Add_HDD(VM_HDD & dev,QString letter)636 void Device_Manager_Widget::Add_HDD(VM_HDD& dev,QString letter)
637 {
638 dev = pw->Get_HDD();
639
640 QString dev_name = dev.Get_File_Name();
641
642 if ( ! QFileInfo(dev_name).exists() )
643 return;
644
645 QListWidgetItem *hdit = new QListWidgetItem( QIcon(":/hdd.png"),
646 tr("HD") + letter.toUpper() + " (" + dev_name + ")", ui.Devices_List );
647 hdit->setData( 512, "hd"+letter.toLower() );
648 ui.Devices_List->addItem( hdit );
649
650 emit Device_Changed();
651 }
652
on_actionAdd_HDD_triggered()653 void Device_Manager_Widget::on_actionAdd_HDD_triggered()
654 {
655 if( ! HDA.Get_Enabled() )
656 {
657 pw = new Properties_Window(this);
658 pw->Set_Current_Machine_Devices( Current_Machine_Devices );
659 pw->Set_HDD( HDA, tr("HDA (First Master)") );
660
661 if( pw->exec() == QDialog::Accepted )
662 {
663 Add_HDD(HDA,"A");
664 }
665 }
666 else if( ! HDB.Get_Enabled() )
667 {
668 pw = new Properties_Window(this);
669 pw->Set_Current_Machine_Devices( Current_Machine_Devices );
670 pw->Set_HDD( HDB, tr("HDB (First Slave)") );
671
672 if( pw->exec() == QDialog::Accepted )
673 {
674 Add_HDD(HDB,"B");
675 }
676 }
677 else if( HDC.Get_Enabled() == false && CD_ROM.Get_Enabled() == false )
678 {
679 pw = new Properties_Window(this);
680 pw->Set_Current_Machine_Devices( Current_Machine_Devices );
681 pw->Set_HDD( HDC, tr("HDC (Second Master)") );
682
683 if( pw->exec() == QDialog::Accepted )
684 {
685 Add_HDD(HDC,"C");
686 }
687 }
688 else if( ! HDD.Get_Enabled() )
689 {
690 pw = new Properties_Window(this);
691 pw->Set_Current_Machine_Devices( Current_Machine_Devices );
692 pw->Set_HDD( HDD, tr("HDD (Second Slave)") );
693
694 if( pw->exec() == QDialog::Accepted )
695 {
696 Add_HDD(HDD,"D");
697 }
698 }
699 else
700 {
701 AQGraphic_Warning( tr("Warning!"),
702 tr("Maximum Hard Disk Count is 4 excluding CD-ROM") );
703 }
704 }
705
on_actionAdd_Device_triggered()706 void Device_Manager_Widget::on_actionAdd_Device_triggered()
707 {
708 Add_New_Device_Window Device_Window;
709 VM_Nativ_Storage_Device tmp_dev;
710 Device_Window.Set_Emulator_Devices( *Current_Machine_Devices );
711 Device_Window.Set_Device( tmp_dev );
712
713 if( Device_Window.exec() == QDialog::Accepted )
714 {
715 Storage_Devices << Device_Window.Get_Device();
716
717 QListWidgetItem *devit = new QListWidgetItem( QIcon(":blockdevice.png"),
718 Device_Window.Get_Device().Get_QEMU_Device_Name(), ui.Devices_List );
719 devit->setData( 512, "device" + QString::number(Storage_Devices.count() - 1) );
720
721 ui.Devices_List->addItem( devit );
722
723 emit Device_Changed();
724 }
725 }
726
on_actionProperties_triggered()727 void Device_Manager_Widget::on_actionProperties_triggered()
728 {
729 if( ui.Devices_List->currentItem()->data(512).toString() == "fd1" )
730 {
731 pw = new Properties_Window(this);
732 pw->Set_Enabled( Enabled );
733 pw->Set_Floppy( Floppy1, tr("Floppy 1") );
734
735 if( ! Current_Machine_Devices )
736 AQError( "void Device_Manager_Widget::on_actionProperties_triggered()",
737 "Current_Machine_Devices == NULL" );
738 pw->Set_Current_Machine_Devices( Current_Machine_Devices );
739
740 if( pw->exec() == QDialog::Accepted )
741 {
742 if( Floppy1 != pw->Get_Floppy() )
743 {
744 Floppy1 = pw->Get_Floppy();
745
746 ui.Devices_List->currentItem()->setText( tr("Floppy 1") + " (" + Floppy1.Get_File_Name() + ")" );
747
748 emit Device_Changed();
749 }
750 }
751 }
752 else if( ui.Devices_List->currentItem()->data(512).toString() == "fd2" )
753 {
754 pw = new Properties_Window(this);
755 pw->Set_Enabled( Enabled );
756 pw->Set_Floppy( Floppy2, tr("Floppy 2") );
757
758 if( ! Current_Machine_Devices )
759 AQError( "void Device_Manager_Widget::on_actionProperties_triggered()",
760 "Current_Machine_Devices == NULL" );
761 pw->Set_Current_Machine_Devices( Current_Machine_Devices );
762
763 if( pw->exec() == QDialog::Accepted )
764 {
765 if( Floppy2 != pw->Get_Floppy() )
766 {
767 Floppy2 = pw->Get_Floppy();
768
769 ui.Devices_List->currentItem()->setText( tr("Floppy 2") + " (" + Floppy2.Get_File_Name() + ")" );
770
771 emit Device_Changed();
772 }
773 }
774 }
775 else if( ui.Devices_List->currentItem()->data(512).toString() == "cd" )
776 {
777 pw = new Properties_Window(this);
778 pw->Set_Enabled( Enabled );
779 pw->Set_CD_ROM( CD_ROM, tr("CD/DVD-ROM") );
780
781 if( ! Current_Machine_Devices )
782 AQError( "void Device_Manager_Widget::on_actionProperties_triggered()",
783 "Current_Machine_Devices == NULL" );
784 pw->Set_Current_Machine_Devices( Current_Machine_Devices );
785
786 if( pw->exec() == QDialog::Accepted )
787 {
788 if( CD_ROM != pw->Get_CD_ROM() )
789 {
790 CD_ROM = pw->Get_CD_ROM();
791
792 ui.Devices_List->currentItem()->setText( tr("CD-ROM") + " (" + CD_ROM.Get_File_Name() + ")" );
793
794 emit Device_Changed();
795 }
796 }
797 }
798 else if( ui.Devices_List->currentItem()->data(512).toString() == "hda" )
799 {
800 pw = new Properties_Window(this);
801 pw->Set_Enabled( Enabled );
802 pw->Set_HDD( HDA, tr("HDA (First Master)") );
803
804 if( ! Current_Machine_Devices )
805 AQError( "void Device_Manager_Widget::on_actionProperties_triggered()",
806 "Current_Machine_Devices == NULL" );
807 pw->Set_Current_Machine_Devices( Current_Machine_Devices );
808
809 if( pw->exec() == QDialog::Accepted )
810 {
811 if( HDA != pw->Get_HDD() )
812 {
813 HDA = pw->Get_HDD();
814
815 ui.Devices_List->currentItem()->setText( tr("HDA") + " (" + HDA.Get_File_Name() + ")" );
816
817 emit Device_Changed();
818 }
819 }
820 }
821 else if( ui.Devices_List->currentItem()->data(512).toString() == "hdb" )
822 {
823 pw = new Properties_Window(this);
824 pw->Set_Enabled( Enabled );
825 pw->Set_HDD( HDB, tr("HDB (First Slave)") );
826
827 if( ! Current_Machine_Devices )
828 AQError( "void Device_Manager_Widget::on_actionProperties_triggered()",
829 "Current_Machine_Devices == NULL" );
830 pw->Set_Current_Machine_Devices( Current_Machine_Devices );
831
832 if( pw->exec() == QDialog::Accepted )
833 {
834 if( HDB != pw->Get_HDD() )
835 {
836 HDB = pw->Get_HDD();
837
838 ui.Devices_List->currentItem()->setText( tr("HDB") + " (" + HDB.Get_File_Name() + ")" );
839
840 emit Device_Changed();
841 }
842 }
843 }
844 else if( ui.Devices_List->currentItem()->data(512).toString() == "hdc" )
845 {
846 pw = new Properties_Window(this);
847 pw->Set_Enabled( Enabled );
848 pw->Set_HDD( HDC, tr("HDC (Second Master)") );
849
850 if( ! Current_Machine_Devices )
851 AQError( "void Device_Manager_Widget::on_actionProperties_triggered()",
852 "Current_Machine_Devices == NULL" );
853 pw->Set_Current_Machine_Devices( Current_Machine_Devices );
854
855 if( pw->exec() == QDialog::Accepted )
856 {
857 if( HDC != pw->Get_HDD() )
858 {
859 HDC = pw->Get_HDD();
860
861 ui.Devices_List->currentItem()->setText( tr("HDC") + " (" + HDC.Get_File_Name() + ")" );
862
863 emit Device_Changed();
864 }
865 }
866 }
867 else if( ui.Devices_List->currentItem()->data(512).toString() == "hdd" )
868 {
869 pw = new Properties_Window(this);
870 pw->Set_Enabled( Enabled );
871 pw->Set_HDD( HDD, tr("HDD (Second Slave)") );
872
873 if( ! Current_Machine_Devices )
874 AQError( "void Device_Manager_Widget::on_actionProperties_triggered()",
875 "Current_Machine_Devices == NULL" );
876 pw->Set_Current_Machine_Devices( Current_Machine_Devices );
877
878 if( pw->exec() == QDialog::Accepted )
879 {
880 if( HDD != pw->Get_HDD() )
881 {
882 HDD = pw->Get_HDD();
883
884 ui.Devices_List->currentItem()->setText( tr("HDD") + " (" + HDC.Get_File_Name() + ")" );
885
886 emit Device_Changed();
887 }
888 }
889 }
890 else
891 {
892 bool found = false;
893
894 for( int fx = 0; fx < 32; ++fx )
895 {
896 if( ui.Devices_List->currentItem()->data(512).toString() == "device" + QString::number(fx) )
897 {
898 found = true;
899
900 Add_New_Device_Window Device_Window ;
901 Device_Window.Set_Enabled( Enabled );
902 Device_Window.Set_Device( Storage_Devices[fx] );
903
904 if( ! Current_Machine_Devices )
905 AQError( "void Device_Manager_Widget::on_actionProperties_triggered()",
906 "Current_Machine_Devices == NULL" );
907 Device_Window.Set_Emulator_Devices( *Current_Machine_Devices );
908
909 if( Device_Window.exec() == QDialog::Accepted )
910 {
911 if( Storage_Devices[fx] != Device_Window.Get_Device() )
912 {
913 Storage_Devices[fx] = Device_Window.Get_Device();
914
915 emit Device_Changed();
916 }
917 }
918 }
919 }
920
921 if( ! found )
922 {
923 AQError( "void Device_Manager_Widget::on_actionProperties_triggered()",
924 "Incorrect Device!" );
925 return;
926 }
927 }
928
929 Update_Enabled_Actions();
930 }
931
on_actionDelete_triggered()932 void Device_Manager_Widget::on_actionDelete_triggered()
933 {
934 int mes_ret = QMessageBox::question( this, tr("Delete?"),
935 tr("Delete Device?"),
936 QMessageBox::Yes | QMessageBox::No, QMessageBox::No );
937
938 if( mes_ret == QMessageBox::No ) return;
939
940 if( ui.Devices_List->currentItem()->data(512).toString() == "fd1" )
941 {
942 Floppy1 = VM_Storage_Device();
943 }
944 else if( ui.Devices_List->currentItem()->data(512).toString() == "fd2" )
945 {
946 Floppy2 = VM_Storage_Device();
947 }
948 else if( ui.Devices_List->currentItem()->data(512).toString() == "cd" )
949 {
950 CD_ROM = VM_Storage_Device();
951 }
952 else if( ui.Devices_List->currentItem()->data(512).toString() == "hda" )
953 {
954 HDA = VM_HDD( false, "" );
955 }
956 else if( ui.Devices_List->currentItem()->data(512).toString() == "hdb" )
957 {
958 HDB = VM_HDD( false, "" );
959 }
960 else if( ui.Devices_List->currentItem()->data(512).toString() == "hdc" )
961 {
962 HDC = VM_HDD( false, "" );
963 }
964 else if( ui.Devices_List->currentItem()->data(512).toString() == "hdd" )
965 {
966 HDD = VM_HDD( false, "" );
967 }
968 else
969 {
970 bool found = false;
971
972 for( int fx = 0; fx < 32; ++fx )
973 {
974 if( ui.Devices_List->currentItem()->data(512).toString() == "device" + QString::number(fx) )
975 {
976 found = true;
977
978 Storage_Devices.removeAt( fx );
979 ui.Devices_List->takeItem( ui.Devices_List->currentRow() );
980 break;
981 }
982 }
983
984 if( ! found )
985 {
986 AQError( "void Device_Manager_Widget::on_actionDelete_triggered()",
987 "Incorrect Device!" );
988 return;
989 }
990 else
991 {
992 // Rename items
993 for( int ix = 0, count = 0; ix < ui.Devices_List->count(); ++ix )
994 {
995 if( ui.Devices_List->item(ix)->data(512).toString().contains("device") )
996 {
997 ui.Devices_List->item(ix)->setData( 512, QString("device%1").arg(count) );
998 ++count;
999 }
1000 }
1001
1002 emit Device_Changed();
1003 return;
1004 }
1005 }
1006
1007 ui.Devices_List->takeItem( ui.Devices_List->currentRow() );
1008
1009 emit Device_Changed();
1010 }
1011
on_actionFormat_HDD_triggered()1012 void Device_Manager_Widget::on_actionFormat_HDD_triggered()
1013 {
1014 Create_HDD_Image_Window *hdd_win = new Create_HDD_Image_Window( this );
1015
1016 if( ui.Devices_List->currentItem()->data(512).toString() == "hda" )
1017 {
1018 hdd_win->Set_Image_File_Name( HDA.Get_File_Name() );
1019 hdd_win->Set_Image_Info( HDA_Info->Get_Disk_Info() );
1020 hdd_win->exec();
1021 }
1022 else if( ui.Devices_List->currentItem()->data(512).toString() == "hdb" )
1023 {
1024 hdd_win->Set_Image_File_Name( HDB.Get_File_Name() );
1025 hdd_win->Set_Image_Info( HDB_Info->Get_Disk_Info() );
1026 hdd_win->exec();
1027 }
1028 else if( ui.Devices_List->currentItem()->data(512).toString() == "hdc" )
1029 {
1030 hdd_win->Set_Image_File_Name( HDC.Get_File_Name() );
1031 hdd_win->Set_Image_Info( HDC_Info->Get_Disk_Info() );
1032 hdd_win->exec();
1033 }
1034 else if( ui.Devices_List->currentItem()->data(512).toString() == "hdd" )
1035 {
1036 hdd_win->Set_Image_File_Name( HDD.Get_File_Name() );
1037 hdd_win->Set_Image_Info( HDD_Info->Get_Disk_Info() );
1038 hdd_win->exec();
1039 }
1040 else
1041 {
1042 AQGraphic_Error( "void Device_Manager_Widget::on_actionFormat_HDD_triggered()",
1043 tr("Error!"), tr("Incorrect Device!"), false );
1044 return;
1045 }
1046
1047 delete hdd_win;
1048
1049 Update_Enabled_Actions();
1050
1051 emit Device_Changed();
1052 }
1053
on_actionQuick_Format_triggered()1054 void Device_Manager_Widget::on_actionQuick_Format_triggered()
1055 {
1056 int mes_ret = QMessageBox::question( this, tr("Format?"),
1057 tr("Format Virtual Hard Disk?"),
1058 QMessageBox::Yes | QMessageBox::No, QMessageBox::No );
1059
1060 if( mes_ret == QMessageBox::No ) return;
1061
1062 if( ui.Devices_List->currentItem()->data(512).toString() == "hda" )
1063 {
1064 if( Format_HDD_Image(HDA.Get_File_Name(), HDA_Info->Get_Disk_Info()) )
1065 {
1066 QMessageBox::information( this, tr("Information"), tr("Complete!") );
1067 }
1068 else
1069 {
1070 QMessageBox::critical( this, tr("Error!"), tr("Cannot Format!") );
1071 }
1072 }
1073 else if( ui.Devices_List->currentItem()->data(512).toString() == "hdb" )
1074 {
1075 if( Format_HDD_Image(HDB.Get_File_Name(), HDB_Info->Get_Disk_Info()) )
1076 {
1077 QMessageBox::information( this, tr("Information"), tr("Complete!") );
1078 }
1079 else
1080 {
1081 QMessageBox::critical( this, tr("Error!"), tr("Cannot Format!") );
1082 }
1083 }
1084 else if( ui.Devices_List->currentItem()->data(512).toString() == "hdc" )
1085 {
1086 if( Format_HDD_Image(HDC.Get_File_Name(), HDC_Info->Get_Disk_Info()) )
1087 {
1088 QMessageBox::information( this, tr("Information"), tr("Complete!") );
1089 }
1090 else
1091 {
1092 QMessageBox::critical( this, tr("Error!"), tr("Cannot Format!") );
1093 }
1094 }
1095 else if( ui.Devices_List->currentItem()->data(512).toString() == "hdd" )
1096 {
1097 if( Format_HDD_Image(HDD.Get_File_Name(), HDD_Info->Get_Disk_Info()) )
1098 {
1099 QMessageBox::information( this, tr("Information"), tr("Complete!") );
1100 }
1101 else
1102 {
1103 QMessageBox::critical( this, tr("Error!"), tr("Cannot Format!") );
1104 }
1105 }
1106 else
1107 {
1108 AQGraphic_Error( "void Device_Manager_Widget::on_actionQuick_Format_triggered()",
1109 tr("Error!"), tr("Incorrect Device!"), false );
1110 return;
1111 }
1112
1113 Update_Enabled_Actions();
1114
1115 emit Device_Changed();
1116 }
1117
on_actionIcon_Mode_triggered()1118 void Device_Manager_Widget::on_actionIcon_Mode_triggered()
1119 {
1120 ui.Devices_List->setSpacing( 10 );
1121 ui.Devices_List->setFlow( QListView::LeftToRight );
1122 ui.Devices_List->setViewMode( QListView::IconMode );
1123 }
1124
on_actionList_Mode_triggered()1125 void Device_Manager_Widget::on_actionList_Mode_triggered()
1126 {
1127 ui.Devices_List->setSpacing( 3 );
1128 ui.Devices_List->setFlow( QListView::TopToBottom );
1129 ui.Devices_List->setViewMode( QListView::ListMode );
1130 }
1131
Update_Icons()1132 void Device_Manager_Widget::Update_Icons()
1133 {
1134 ui.Devices_List->clear();
1135
1136 if( Floppy1.Get_Enabled() )
1137 {
1138 QListWidgetItem *fdit = new QListWidgetItem( QIcon(":/fdd.png"),
1139 tr("Floppy 1") + " (" + Floppy1.Get_File_Name() + ")" );
1140 fdit->setData( 512, "fd1" );
1141
1142 ui.Devices_List->addItem( fdit );
1143 }
1144
1145 if( Floppy2.Get_Enabled() )
1146 {
1147 QListWidgetItem *fdit = new QListWidgetItem( QIcon(":/fdd.png"),
1148 tr("Floppy 2") + " (" + Floppy2.Get_File_Name() + ")" );
1149 fdit->setData( 512, "fd2" );
1150
1151 ui.Devices_List->addItem( fdit );
1152 }
1153
1154 if( CD_ROM.Get_Enabled() )
1155 {
1156 QListWidgetItem *cdit = new QListWidgetItem( QIcon(":/cdrom.png"),
1157 tr("CD-ROM") + " (" + CD_ROM.Get_File_Name() + ")" , ui.Devices_List );
1158 cdit->setData( 512, "cd" );
1159
1160 ui.Devices_List->addItem( cdit );
1161 }
1162
1163 if( HDA.Get_Enabled() )
1164 {
1165 QListWidgetItem *hdit = new QListWidgetItem( QIcon(":/hdd.png"),
1166 tr("HDA") + " (" + HDA.Get_File_Name() + ")", ui.Devices_List );
1167 hdit->setData( 512, "hda" );
1168
1169 ui.Devices_List->addItem( hdit );
1170 }
1171
1172 if( HDB.Get_Enabled() )
1173 {
1174 QListWidgetItem *hdit = new QListWidgetItem( QIcon(":/hdd.png"),
1175 tr("HDB") + " (" + HDB.Get_File_Name() + ")", ui.Devices_List );
1176 hdit->setData( 512, "hdb" );
1177
1178 ui.Devices_List->addItem( hdit );
1179 }
1180
1181 if( HDC.Get_Enabled() )
1182 {
1183 QListWidgetItem *hdit = new QListWidgetItem( QIcon(":/hdd.png"),
1184 tr("HDC") + " (" + HDC.Get_File_Name() + ")", ui.Devices_List );
1185 hdit->setData( 512, "hdc" );
1186
1187 ui.Devices_List->addItem( hdit );
1188 }
1189
1190 if( HDD.Get_Enabled() )
1191 {
1192 QListWidgetItem *hdit = new QListWidgetItem( QIcon(":/hdd.png"),
1193 tr("HDD") + " (" + HDD.Get_File_Name() + ")", ui.Devices_List );
1194 hdit->setData( 512, "hdd" );
1195
1196 ui.Devices_List->addItem( hdit );
1197 }
1198
1199 // Storage Devices
1200 if( Storage_Devices.count() )
1201 {
1202 for( int ix = 0; ix < Storage_Devices.count(); ++ix )
1203 {
1204 QListWidgetItem *hdit = new QListWidgetItem( QIcon(":/blockdevice.png"),
1205 Storage_Devices[ix].Get_QEMU_Device_Name(), ui.Devices_List );
1206 hdit->setData( 512, "device" + QString::number(ix) );
1207
1208 ui.Devices_List->addItem( hdit );
1209 }
1210 }
1211 }
1212
Update_HDA(bool ok)1213 void Device_Manager_Widget::Update_HDA( bool ok )
1214 {
1215 HDA.Set_Disk_Info( HDA_Info->Get_Disk_Info() );
1216
1217 ui.Label_Connected_To->setText( tr("Image Virtual Size: ") + QString::number(HDA.Get_Virtual_Size().Size) +
1218 Get_TR_Size_Suffix(HDA.Get_Virtual_Size()) + "\n" +
1219 tr("Image On Disk Size: ") + QString::number(HDA.Get_Disk_Size().Size) +
1220 Get_TR_Size_Suffix(HDA.Get_Disk_Size()) );
1221 }
1222
Update_HDB(bool ok)1223 void Device_Manager_Widget::Update_HDB( bool ok )
1224 {
1225 HDB.Set_Disk_Info( HDB_Info->Get_Disk_Info() );
1226
1227 ui.Label_Connected_To->setText( tr("Image Virtual Size: ") + QString::number(HDB.Get_Virtual_Size().Size) +
1228 Get_TR_Size_Suffix(HDB.Get_Virtual_Size()) + "\n" +
1229 tr("Image On Disk Size: ") + QString::number(HDB.Get_Disk_Size().Size) +
1230 Get_TR_Size_Suffix(HDB.Get_Disk_Size()) );
1231 }
1232
Update_HDC(bool ok)1233 void Device_Manager_Widget::Update_HDC( bool ok )
1234 {
1235 HDC.Set_Disk_Info( HDC_Info->Get_Disk_Info() );
1236
1237 ui.Label_Connected_To->setText( tr("Image Virtual Size: ") + QString::number(HDC.Get_Virtual_Size().Size) +
1238 Get_TR_Size_Suffix(HDC.Get_Virtual_Size()) + "\n" +
1239 tr("Image On Disk Size: ") + QString::number(HDC.Get_Disk_Size().Size) +
1240 Get_TR_Size_Suffix(HDC.Get_Disk_Size()));
1241 }
1242
Update_HDD(bool ok)1243 void Device_Manager_Widget::Update_HDD( bool ok )
1244 {
1245 HDD.Set_Disk_Info( HDD_Info->Get_Disk_Info() );
1246
1247 ui.Label_Connected_To->setText( tr("Image Virtual Size: ") + QString::number(HDD.Get_Virtual_Size().Size) +
1248 Get_TR_Size_Suffix(HDD.Get_Virtual_Size()) + "\n" +
1249 tr("Image On Disk Size: ") + QString::number(HDD.Get_Disk_Size().Size) +
1250 Get_TR_Size_Suffix(HDD.Get_Disk_Size()));
1251 }
1252