VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/ui/VBoxDiskImageManagerDlg.ui.h@ 1688

Last change on this file since 1688 was 1413, checked in by vboxsync, 18 years ago

VBoxMedia data member integrated into DiskImageItem class allowing access to related disk image through particular list-view item. Used for releasing&removing media.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 66.9 KB
Line 
1/**
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * "Virtual Disk Manager" dialog UI include (Qt Designer)
5 */
6
7/*
8 * Copyright (C) 2006 InnoTek Systemberatung GmbH
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License as published by the Free Software Foundation,
14 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
15 * distribution. VirtualBox OSE is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * If you received this file as part of a commercial VirtualBox
19 * distribution, then only the terms of your commercial VirtualBox
20 * license agreement apply instead of the previous paragraph.
21 */
22
23/****************************************************************************
24** ui.h extension file, included from the uic-generated form implementation.
25**
26** If you wish to add, delete or rename functions or slots use
27** Qt Designer which will update this file, preserving your code. Create an
28** init() function in place of a constructor, and a destroy() function in
29** place of a destructor.
30*****************************************************************************/
31
32
33class DiskImageItem : public QListViewItem
34{
35public:
36
37 enum { TypeId = 1001 };
38
39 DiskImageItem (DiskImageItem *parent) :
40 QListViewItem (parent), mStatus (VBoxMedia::Unknown) {}
41
42 DiskImageItem (QListView *parent) :
43 QListViewItem (parent), mStatus (VBoxMedia::Unknown) {}
44
45 void setMedia (const VBoxMedia &aMedia) { mMedia = aMedia; }
46 VBoxMedia &getMedia() { return mMedia; }
47
48 QString getName() { return mName; }
49
50 void setPath (QString aPath) { mPath = aPath; }
51 const QString &getPath() { return mPath; }
52
53 void setUsage (QString aUsage) { mUsage = aUsage; }
54 const QString &getUsage() { return mUsage; }
55
56 void setSnapshotName (QString aSnapshotName) { mSnapshotName = aSnapshotName; }
57 const QString &getSnapshotName() { return mSnapshotName; }
58
59 void setDiskType (QString aDiskType) { mDiskType = aDiskType; }
60 const QString &getDiskType() { return mDiskType; }
61
62 void setStorageType (QString aStorageType) { mStorageType = aStorageType; }
63 const QString &getStorageType() { return mStorageType; }
64
65 void setVirtualSize (QString aVirtualSize) { mVirtualSize = aVirtualSize; }
66 const QString &getVirtualSize() { return mVirtualSize; }
67
68 void setActualSize (QString aActualSize) { mActualSize = aActualSize; }
69 const QString &getActualSize() { return mActualSize; }
70
71
72 void setUuid (QUuid aUuid) { mUuid = aUuid; }
73 const QString &getUuid() { return mUuid; }
74
75 void setMachineId (QString aMachineId) { mMachineId = aMachineId; }
76 const QString &getMachineId() { return mMachineId; }
77
78
79 void setStatus (VBoxMedia::Status aStatus) { mStatus = aStatus; }
80 VBoxMedia::Status getStatus() { return mStatus; }
81
82
83 void setToolTip (QString aToolTip) { mToolTip = aToolTip; }
84 const QString &getToolTip() { return mToolTip; }
85
86 QString getInformation (const QString &aInfo, bool aCompact = true,
87 const QString &aElipsis = "middle")
88 {
89 QString compactString = QString ("<compact elipsis=\"%1\">").arg (aElipsis);
90 QString info = QString ("<nobr>%1%2%3</nobr>")
91 .arg (aCompact ? compactString : "")
92 .arg (aInfo.isEmpty() ? QObject::tr ("--") : aInfo)
93 .arg (aCompact ? "</compact>" : "");
94 return info;
95 }
96
97 int rtti() const { return TypeId; }
98
99 int compare (QListViewItem *aItem, int aColumn, bool aAscending) const
100 {
101 ULONG64 thisValue = vboxGlobal().parseSize ( text (aColumn));
102 ULONG64 thatValue = vboxGlobal().parseSize (aItem->text (aColumn));
103 if (thisValue && thatValue)
104 {
105 if (thisValue == thatValue)
106 return 0;
107 else
108 return thisValue > thatValue ? 1 : -1;
109 }
110 else
111 return QListViewItem::compare (aItem, aColumn, aAscending);
112 }
113
114 DiskImageItem* nextSibling() const
115 {
116 return (QListViewItem::nextSibling() &&
117 QListViewItem::nextSibling()->rtti() == DiskImageItem::TypeId) ?
118 static_cast<DiskImageItem*> (QListViewItem::nextSibling()) : 0;
119 }
120
121 void paintCell (QPainter *aPainter, const QColorGroup &aColorGroup,
122 int aColumn, int aWidth, int aSlign)
123 {
124 QColorGroup cGroup (aColorGroup);
125 if (mStatus == VBoxMedia::Unknown)
126 cGroup.setColor (QColorGroup::Text, cGroup.mid());
127 QListViewItem::paintCell (aPainter, cGroup, aColumn, aWidth, aSlign);
128 }
129
130protected:
131
132 VBoxMedia mMedia;
133
134 QString mName;
135 QString mPath;
136 QString mUsage;
137 QString mSnapshotName;
138 QString mDiskType;
139 QString mStorageType;
140 QString mVirtualSize;
141 QString mActualSize;
142
143 QString mUuid;
144 QString mMachineId;
145
146 QString mToolTip;
147
148 VBoxMedia::Status mStatus;
149};
150
151
152class DiskImageItemIterator : public QListViewItemIterator
153{
154public:
155
156 DiskImageItemIterator (QListView* aList)
157 : QListViewItemIterator (aList) {}
158
159 DiskImageItem* operator*()
160 {
161 QListViewItem *item = QListViewItemIterator::operator*();
162 return item && item->rtti() == DiskImageItem::TypeId ?
163 static_cast<DiskImageItem*> (item) : 0;
164 }
165
166 DiskImageItemIterator& operator++()
167 {
168 return (DiskImageItemIterator&) QListViewItemIterator::operator++();
169 }
170};
171
172
173VBoxDiskImageManagerDlg *VBoxDiskImageManagerDlg::mModelessDialog = 0;
174
175
176void VBoxDiskImageManagerDlg::showModeless (bool aRefresh /* = true */)
177{
178 if (!mModelessDialog)
179 {
180 mModelessDialog =
181 new VBoxDiskImageManagerDlg (NULL,
182 "VBoxDiskImageManagerDlg",
183 WType_TopLevel | WDestructiveClose);
184 mModelessDialog->setup (VBoxDefs::HD | VBoxDefs::CD | VBoxDefs::FD,
185 false, NULL, aRefresh);
186
187 /* listen to events that may change the media status and refresh
188 * the contents of the modeless dialog */
189 /// @todo refreshAll() may be slow, so it may be better to analyze
190 // event details and update only what is changed */
191 connect (&vboxGlobal(), SIGNAL (machineDataChanged (const VBoxMachineDataChangeEvent &)),
192 mModelessDialog, SLOT (refreshAll()));
193 connect (&vboxGlobal(), SIGNAL (machineRegistered (const VBoxMachineRegisteredEvent &)),
194 mModelessDialog, SLOT (refreshAll()));
195 connect (&vboxGlobal(), SIGNAL (snapshotChanged (const VBoxSnapshotEvent &)),
196 mModelessDialog, SLOT (refreshAll()));
197 }
198
199 mModelessDialog->show();
200 mModelessDialog->setWindowState (mModelessDialog->windowState() &
201 ~WindowMinimized);
202 mModelessDialog->setActiveWindow();
203}
204
205
206void VBoxDiskImageManagerDlg::init()
207{
208 polished = false;
209
210 mInLoop = false;
211
212 defaultButton = searchDefaultButton();
213
214 vbox = vboxGlobal().virtualBox();
215 Assert (!vbox.isNull());
216
217 setIcon (QPixmap::fromMimeSource ("diskim_16px.png"));
218
219 type = VBoxDefs::InvalidType;
220
221 QImage img =
222 QMessageBox::standardIcon (QMessageBox::Warning).convertToImage();
223 img = img.smoothScale (16, 16);
224 pxInaccessible.convertFromImage (img);
225 Assert (!pxInaccessible.isNull());
226
227 img =
228 QMessageBox::standardIcon (QMessageBox::Critical).convertToImage();
229 img = img.smoothScale (16, 16);
230 pxErroneous.convertFromImage (img);
231 Assert (!pxErroneous.isNull());
232
233 pxHD = QPixmap::fromMimeSource ("diskim_16px.png");
234 pxCD = QPixmap::fromMimeSource ("cd_16px.png");
235 pxFD = QPixmap::fromMimeSource ("fd_16px.png");
236
237 /* setup tab widget icons */
238 twImages->setTabIconSet (twImages->page (0),
239 VBoxGlobal::iconSet ("hd_16px.png",
240 "hd_disabled_16px.png"));
241 twImages->setTabIconSet (twImages->page (1),
242 VBoxGlobal::iconSet ("cd_16px.png",
243 "cd_disabled_16px.png"));
244 twImages->setTabIconSet (twImages->page (2),
245 VBoxGlobal::iconSet ("fd_16px.png",
246 "fd_disabled_16px.png"));
247
248
249 /* setup image list views */
250 hdsView->setColumnAlignment (1, Qt::AlignRight);
251 hdsView->setColumnAlignment (2, Qt::AlignRight);
252 hdsView->header()->setStretchEnabled (false);
253 hdsView->header()->setStretchEnabled (true, 0);
254
255 fdsView->setColumnAlignment (1, Qt::AlignRight);
256 fdsView->header()->setStretchEnabled (false);
257 fdsView->header()->setStretchEnabled (true, 0);
258
259 cdsView->setColumnAlignment (1, Qt::AlignRight);
260 cdsView->header()->setStretchEnabled (false);
261 cdsView->header()->setStretchEnabled (true, 0);
262
263
264 /* setup list-view's item tooltip */
265 hdsView->setShowToolTips (false);
266 cdsView->setShowToolTips (false);
267 fdsView->setShowToolTips (false);
268 connect (hdsView, SIGNAL (onItem (QListViewItem*)),
269 this, SLOT (mouseOnItem(QListViewItem*)));
270 connect (cdsView, SIGNAL (onItem (QListViewItem*)),
271 this, SLOT (mouseOnItem(QListViewItem*)));
272 connect (fdsView, SIGNAL (onItem (QListViewItem*)),
273 this, SLOT (mouseOnItem(QListViewItem*)));
274
275
276 /* status-bar currently disabled */
277 statusBar()->setHidden (true);
278
279
280 /* context menu composing */
281 itemMenu = new QPopupMenu (this, "itemMenu");
282
283 imNewAction = new QAction (this, "imNewAction");
284 imAddAction = new QAction (this, "imAddAction");
285 // imEditAction = new QAction (this, "imEditAction");
286 imRemoveAction = new QAction (this, "imRemoveAction");
287 imReleaseAction = new QAction (this, "imReleaseAction");
288 imRefreshAction = new QAction (this, "imRefreshAction");
289
290 connect (imNewAction, SIGNAL (activated()),
291 this, SLOT (newImage()));
292 connect (imAddAction, SIGNAL (activated()),
293 this, SLOT (addImage()));
294 // connect (imEditAction, SIGNAL (activated()),
295 // this, SLOT (editImage()));
296 connect (imRemoveAction, SIGNAL (activated()),
297 this, SLOT (removeImage()));
298 connect (imReleaseAction, SIGNAL (activated()),
299 this, SLOT (releaseImage()));
300 connect (imRefreshAction, SIGNAL (activated()),
301 this, SLOT (refreshAll()));
302
303 imNewAction->setMenuText (tr ("&New..."));
304 imAddAction->setMenuText (tr ("&Add..."));
305 // imEditAction->setMenuText (tr ("&Edit..."));
306 imRemoveAction->setMenuText (tr ("R&emove"));
307 imReleaseAction->setMenuText (tr ("Re&lease"));
308 imRefreshAction->setMenuText (tr ("Re&fresh"));
309
310 imNewAction->setText (tr ("New"));
311 imAddAction->setText (tr ("Add"));
312 // imEditAction->setText (tr ("Edit"));
313 imRemoveAction->setText (tr ("Remove"));
314 imReleaseAction->setText (tr ("Release"));
315 imRefreshAction->setText (tr ("Refresh"));
316
317 imNewAction->setAccel (tr ("Ctrl+N"));
318 imAddAction->setAccel (tr ("Ctrl+A"));
319 // imEditAction->setAccel (tr ("Ctrl+E"));
320 imRemoveAction->setAccel (tr ("Ctrl+D"));
321 imReleaseAction->setAccel (tr ("Ctrl+L"));
322 imRefreshAction->setAccel (tr ("Ctrl+R"));
323
324 imNewAction->setStatusTip (tr ("Create new VDI file and attach it to media list"));
325 imAddAction->setStatusTip (tr ("Add existing media image file to media list"));
326 // imEditAction->setStatusTip (tr ("Edit properties of selected media image file"));
327 imRemoveAction->setStatusTip (tr ("Remove selected media image file from media list"));
328 imReleaseAction->setStatusTip (tr ("Release selected media image file from being using in some VM"));
329 imRefreshAction->setStatusTip (tr ("Refresh media image list"));
330
331 imNewAction->setIconSet (VBoxGlobal::iconSetEx (
332 "vdm_new_22px.png", "vdm_new_16px.png",
333 "vdm_new_disabled_22px.png", "vdm_new_disabled_16px.png"));
334 imAddAction->setIconSet (VBoxGlobal::iconSetEx (
335 "vdm_add_22px.png", "vdm_add_16px.png",
336 "vdm_add_disabled_22px.png", "vdm_add_disabled_16px.png"));
337 // imEditAction->setIconSet (VBoxGlobal::iconSet ("guesttools_16px.png", "guesttools_disabled_16px.png"));
338 imRemoveAction->setIconSet (VBoxGlobal::iconSetEx (
339 "vdm_remove_22px.png", "vdm_remove_16px.png",
340 "vdm_remove_disabled_22px.png", "vdm_remove_disabled_16px.png"));
341 imReleaseAction->setIconSet (VBoxGlobal::iconSetEx (
342 "vdm_release_22px.png", "vdm_release_16px.png",
343 "vdm_release_disabled_22px.png", "vdm_release_disabled_16px.png"));
344 imRefreshAction->setIconSet (VBoxGlobal::iconSetEx (
345 "refresh_22px.png", "refresh_16px.png",
346 "refresh_disabled_22px.png", "refresh_disabled_16px.png"));
347
348 // imEditAction->addTo (itemMenu);
349 imRemoveAction->addTo (itemMenu);
350 imReleaseAction->addTo (itemMenu);
351
352
353 /* toolbar composing */
354 toolBar = new VBoxToolBar (this, centralWidget(), "toolBar");
355 toolBar->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Minimum);
356 ((QVBoxLayout*)centralWidget()->layout())->insertWidget(0, toolBar);
357
358 toolBar->setUsesTextLabel (true);
359 toolBar->setUsesBigPixmaps (true);
360
361 imNewAction->addTo (toolBar);
362 imAddAction->addTo (toolBar);
363 toolBar->addSeparator();
364 // imEditAction->addTo (toolBar);
365 imRemoveAction->addTo (toolBar);
366 imReleaseAction->addTo (toolBar);
367 toolBar->addSeparator();
368 imRefreshAction->addTo (toolBar);
369
370
371 /* menu bar */
372 QPopupMenu *actionMenu = new QPopupMenu (this, "actionMenu");
373 imNewAction->addTo (actionMenu);
374 imAddAction->addTo (actionMenu);
375 actionMenu->insertSeparator();
376 // imEditAction->addTo (toolBar);
377 imRemoveAction->addTo (actionMenu);
378 imReleaseAction->addTo (actionMenu);
379 actionMenu->insertSeparator();
380 imRefreshAction->addTo (actionMenu);
381 menuBar()->insertItem (QString (tr ("&Actions")), actionMenu, 1);
382
383
384 /* setup size grip */
385 sizeGrip = new QSizeGrip (centralWidget(), "sizeGrip");
386 sizeGrip->resize (sizeGrip->sizeHint());
387 sizeGrip->stackUnder(buttonOk);
388
389 /* setup information pane */
390 QApplication::setGlobalMouseTracking (true);
391 qApp->installEventFilter (this);
392 /* setup information pane layouts */
393 QGridLayout *hdsContainerLayout = new QGridLayout (hdsContainer, 4, 4);
394 hdsContainerLayout->setMargin (10);
395 QGridLayout *cdsContainerLayout = new QGridLayout (cdsContainer, 2, 4);
396 cdsContainerLayout->setMargin (10);
397 QGridLayout *fdsContainerLayout = new QGridLayout (fdsContainer, 2, 4);
398 fdsContainerLayout->setMargin (10);
399 /* create info-pane for hd list-view */
400 hdsPane1 = createInfoString (tr ("Location"), hdsContainer, 0, -1);
401 hdsPane2 = createInfoString (tr ("Disk Type"), hdsContainer, 1, 0);
402 hdsPane3 = createInfoString (tr ("Storage Type"), hdsContainer, 1, 1);
403 hdsPane4 = createInfoString (tr ("Attached to"), hdsContainer, 2, 0);
404 hdsPane5 = createInfoString (tr ("Snapshot"), hdsContainer, 2, 1);
405 /* create info-pane for cd list-view */
406 cdsPane1 = createInfoString (tr ("Location"), cdsContainer, 0, -1);
407 cdsPane2 = createInfoString (tr ("Attached to"), cdsContainer, 1, -1);
408 /* create info-pane for fd list-view */
409 fdsPane1 = createInfoString (tr ("Location"), fdsContainer, 0, -1);
410 fdsPane2 = createInfoString (tr ("Attached to"), fdsContainer, 1, -1);
411
412
413 /* enumeration progressbar creation */
414 mProgressText = new QLabel (tr ("Checking accessibility"), centralWidget());
415 mProgressText->setHidden (true);
416 buttonLayout->insertWidget (2, mProgressText);
417 mProgressBar = new QProgressBar (centralWidget());
418 mProgressBar->setHidden (true);
419 mProgressBar->setFrameShadow (QFrame::Sunken);
420 mProgressBar->setFrameShape (QFrame::Panel);
421 mProgressBar->setPercentageVisible (false);
422 mProgressBar->setMaximumWidth (100);
423 buttonLayout->insertWidget (3, mProgressBar);
424}
425
426
427QIRichLabel *VBoxDiskImageManagerDlg::createInfoString (const QString &name, QWidget *root, int row, int column)
428{
429 QLabel *nameLabel = new QLabel (name, root, "nameLabel");
430 QIRichLabel *infoLabel = new QIRichLabel (root, "infoPane");
431
432 /* Setup focus policy <strong> default for info pane */
433 infoLabel->setFocusPolicy (QWidget::StrongFocus);
434
435 /* prevent the name columns from being expanded */
436 nameLabel->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
437
438 if (column == -1)
439 {
440 /* add qt-html tags to prevent wrapping and to have the same initial
441 * height of nameLabel and infoLabel (plain text gets a height smaller
442 * than rich text */
443 nameLabel->setText (QString ("<nobr>%1:</nobr>").arg (name));
444
445 ((QGridLayout *) root->layout())->addWidget (nameLabel, row, 0);
446 ((QGridLayout *) root->layout())->
447 addMultiCellWidget (infoLabel, row, row,
448 1, ((QGridLayout *) root->layout())->numCols() - 1);
449 }
450 else
451 {
452 /* add some spacing to the left of the name field for all columns but
453 * the first one, to separate it from the value field (note that adding
454 * spacing to the right is not necessary since Qt does it anyway for
455 * rich text for whatever stupid reason). */
456 if (column == 0)
457 nameLabel->setText (QString ("<nobr>%1:</nobr>").arg (name));
458 else
459 nameLabel->setText (QString ("<nobr>&nbsp;&nbsp;%1:</nobr>").arg (name));
460
461 ((QGridLayout *) root->layout())->addWidget (nameLabel, row, column * 2);
462 ((QGridLayout *) root->layout())->addWidget (infoLabel, row, column * 2 + 1);
463 }
464
465 return infoLabel;
466}
467
468
469void VBoxDiskImageManagerDlg::showEvent (QShowEvent *e)
470{
471 QMainWindow::showEvent (e);
472
473 /* one may think that QWidget::polish() is the right place to do things
474 * below, but apparently, by the time when QWidget::polish() is called,
475 * the widget style & layout are not fully done, at least the minimum
476 * size hint is not properly calculated. Since this is sometimes necessary,
477 * we provide our own "polish" implementation. */
478
479 if (polished)
480 return;
481
482 polished = true;
483
484 VBoxGlobal::centerWidget (this, parentWidget());
485}
486
487
488void VBoxDiskImageManagerDlg::mouseOnItem (QListViewItem *aItem)
489{
490 QListView *currentList = getCurrentListView();
491 QString tip;
492 switch (aItem->rtti())
493 {
494 case DiskImageItem::TypeId:
495 tip = static_cast<DiskImageItem*> (aItem)->getToolTip();
496 break;
497 default:
498 Assert (0);
499 }
500 QToolTip::add (currentList->viewport(), currentList->itemRect (aItem), tip);
501}
502
503
504void VBoxDiskImageManagerDlg::resizeEvent (QResizeEvent*)
505{
506 sizeGrip->move (centralWidget()->rect().bottomRight() -
507 QPoint(sizeGrip->rect().width() - 1, sizeGrip->rect().height() - 1));
508}
509
510
511void VBoxDiskImageManagerDlg::closeEvent (QCloseEvent *aEvent)
512{
513 mModelessDialog = 0;
514 aEvent->accept();
515}
516
517
518void VBoxDiskImageManagerDlg::keyPressEvent (QKeyEvent *aEvent)
519{
520 if ( aEvent->state() == 0 ||
521 (aEvent->state() & Keypad && aEvent->key() == Key_Enter) )
522 {
523 switch ( aEvent->key() )
524 {
525 case Key_Enter:
526 case Key_Return:
527 {
528 QPushButton *currentDefault = searchDefaultButton();
529 if (currentDefault)
530 currentDefault->animateClick();
531 break;
532 }
533 case Key_Escape:
534 {
535 reject();
536 break;
537 }
538 }
539 }
540 else
541 aEvent->ignore();
542}
543
544
545QPushButton* VBoxDiskImageManagerDlg::searchDefaultButton()
546{
547 QPushButton *defButton = 0;
548 QObjectList *list = queryList ("QPushButton");
549 QObjectListIt it (*list);
550 while ( (defButton = (QPushButton*)it.current()) && !defButton->isDefault() )
551 {
552 ++it;
553 }
554 return defButton;
555}
556
557
558int VBoxDiskImageManagerDlg::result() { return mRescode; }
559void VBoxDiskImageManagerDlg::setResult (int aRescode) { mRescode = aRescode; }
560void VBoxDiskImageManagerDlg::accept() { done( Accepted ); }
561void VBoxDiskImageManagerDlg::reject() { done( Rejected ); }
562
563int VBoxDiskImageManagerDlg::exec()
564{
565 setResult (0);
566
567 if (mInLoop) return result();
568 show();
569 mInLoop = true;
570 qApp->eventLoop()->enterLoop();
571 mInLoop = false;
572
573 return result();
574}
575
576void VBoxDiskImageManagerDlg::done (int aResult)
577{
578 setResult (aResult);
579
580 if (mInLoop)
581 {
582 hide();
583 qApp->eventLoop()->exitLoop();
584 }
585 else
586 {
587 close();
588 }
589}
590
591
592QListView* VBoxDiskImageManagerDlg::getCurrentListView()
593{
594 QListView *clv = static_cast<QListView*>(twImages->currentPage()->
595 queryList("QListView")->getFirst());
596 Assert(clv);
597 return clv;
598}
599
600QListView* VBoxDiskImageManagerDlg::getListView (VBoxDefs::DiskType aType)
601{
602 switch (aType)
603 {
604 case VBoxDefs::HD:
605 return hdsView;
606 case VBoxDefs::CD:
607 return cdsView;
608 case VBoxDefs::FD:
609 return fdsView;
610 default:
611 return 0;
612 }
613}
614
615
616bool VBoxDiskImageManagerDlg::eventFilter (QObject *aObject, QEvent *aEvent)
617{
618 QListView *currentList = getCurrentListView();
619
620 switch (aEvent->type())
621 {
622 case QEvent::DragEnter:
623 {
624 if (aObject == currentList)
625 {
626 QDragEnterEvent *dragEnterEvent =
627 static_cast<QDragEnterEvent*>(aEvent);
628 dragEnterEvent->acceptAction();
629 return true;
630 }
631 break;
632 }
633 case QEvent::Drop:
634 {
635 if (aObject == currentList)
636 {
637 QDropEvent *dropEvent =
638 static_cast<QDropEvent*>(aEvent);
639 QStringList *droppedList = new QStringList();
640 QUriDrag::decodeLocalFiles (dropEvent, *droppedList);
641 QCustomEvent *updateEvent = new QCustomEvent (1001);
642 updateEvent->setData (droppedList);
643 QApplication::postEvent (currentList, updateEvent);
644 dropEvent->acceptAction();
645 return true;
646 }
647 break;
648 }
649 case 1001: /* QCustomEvent 1001 - DnD Update Event */
650 {
651 if (aObject == currentList)
652 {
653 QCustomEvent *updateEvent =
654 static_cast<QCustomEvent*>(aEvent);
655 addDroppedImages ((QStringList*) updateEvent->data());
656 return true;
657 }
658 break;
659 }
660 case QEvent::FocusIn:
661 {
662 if (aObject->inherits ("QPushButton") && aObject->parent() == centralWidget())
663 {
664 ((QPushButton*)aObject)->setDefault (aObject != defaultButton);
665 if (defaultButton)
666 defaultButton->setDefault (aObject == defaultButton);
667 }
668 break;
669 }
670 case QEvent::FocusOut:
671 {
672 if (aObject->inherits ("QPushButton") && aObject->parent() == centralWidget())
673 {
674 if (defaultButton)
675 defaultButton->setDefault (aObject != defaultButton);
676 ((QPushButton*)aObject)->setDefault (aObject == defaultButton);
677 }
678 break;
679 }
680 default:
681 break;
682 }
683 return QMainWindow::eventFilter (aObject, aEvent);
684}
685
686
687void VBoxDiskImageManagerDlg::addDroppedImages (QStringList *aDroppedList)
688{
689 QListView *currentList = getCurrentListView();
690
691 for (QStringList::Iterator it = (*aDroppedList).begin();
692 it != (*aDroppedList).end(); ++it)
693 {
694 QString src = *it;
695 /* Check dropped media type */
696 /// @todo On OS/2 and windows (and mac?) extension checks should be case
697 /// insensitive, as OPPOSED to linux and the rest where case matters.
698 VBoxDefs::DiskType type = VBoxDefs::InvalidType;
699 if (src.endsWith (".iso", false))
700 {
701 if (currentList == cdsView) type = VBoxDefs::CD;
702 }
703 else if (src.endsWith (".img", false))
704 {
705 if (currentList == fdsView) type = VBoxDefs::FD;
706 }
707 else if (src.endsWith (".vdi", false) ||
708 src.endsWith (".vmdk", false))
709 {
710 if (currentList == hdsView) type = VBoxDefs::HD;
711 }
712 /* If media type has been determined - attach this device */
713 if (type)
714 {
715 addImageToList (*it, type);
716 if (!vbox.isOk())
717 vboxProblem().cannotRegisterMedia (this, vbox, type, src);
718 }
719 }
720 delete aDroppedList;
721}
722
723
724void VBoxDiskImageManagerDlg::addImageToList (const QString &aSource,
725 VBoxDefs::DiskType aDiskType)
726{
727 if (aSource.isEmpty())
728 return;
729
730 QUuid uuid;
731 VBoxMedia media;
732 switch (aDiskType)
733 {
734 case VBoxDefs::HD:
735 {
736 CHardDisk hd = vbox.OpenHardDisk (aSource);
737 if (vbox.isOk())
738 {
739 vbox.RegisterHardDisk (hd);
740 if (vbox.isOk())
741 {
742 VBoxMedia::Status status =
743 hd.GetAccessible() ? VBoxMedia::Ok :
744 hd.isOk() ? VBoxMedia::Inaccessible :
745 VBoxMedia::Error;
746 media = VBoxMedia (CUnknown (hd), VBoxDefs::HD, status);
747 }
748 }
749 break;
750 }
751 case VBoxDefs::CD:
752 {
753 CDVDImage cd = vbox.OpenDVDImage (aSource, uuid);
754 if (vbox.isOk())
755 {
756 vbox.RegisterDVDImage (cd);
757 if (vbox.isOk())
758 {
759 VBoxMedia::Status status =
760 cd.GetAccessible() ? VBoxMedia::Ok :
761 cd.isOk() ? VBoxMedia::Inaccessible :
762 VBoxMedia::Error;
763 media = VBoxMedia (CUnknown (cd), VBoxDefs::CD, status);
764 }
765 }
766 break;
767 }
768 case VBoxDefs::FD:
769 {
770 CFloppyImage fd = vbox.OpenFloppyImage (aSource, uuid);
771 if (vbox.isOk())
772 {
773 vbox.RegisterFloppyImage (fd);
774 if (vbox.isOk())
775 {
776 VBoxMedia::Status status =
777 fd.GetAccessible() ? VBoxMedia::Ok :
778 fd.isOk() ? VBoxMedia::Inaccessible :
779 VBoxMedia::Error;
780 media = VBoxMedia (CUnknown (fd), VBoxDefs::FD, status);
781 }
782 }
783 break;
784 }
785 default:
786 AssertMsgFailed (("Invalid aDiskType type\n"));
787 }
788 if (media.type != VBoxDefs::InvalidType)
789 vboxGlobal().addMedia (media);
790}
791
792
793DiskImageItem* VBoxDiskImageManagerDlg::createImageNode (QListView *aList,
794 DiskImageItem *aRoot,
795 const VBoxMedia &aMedia)
796{
797 DiskImageItem *item = 0;
798
799 if (aRoot)
800 item = new DiskImageItem (aRoot);
801 else if (aList)
802 item = new DiskImageItem (aList);
803 else
804 Assert (0);
805
806 item->setMedia (aMedia);
807
808 return item;
809}
810
811
812void VBoxDiskImageManagerDlg::invokePopup (QListViewItem *aItem, const QPoint & aPos, int)
813{
814 if (aItem)
815 itemMenu->popup(aPos);
816}
817
818
819QString VBoxDiskImageManagerDlg::getDVDImageUsage (const QUuid &aId)
820{
821 CVirtualBox vbox = vboxGlobal().virtualBox();
822
823 QStringList permMachines =
824 QStringList::split (' ', vbox.GetDVDImageUsage (aId, CEnums::PermanentUsage));
825 QStringList tempMachines =
826 QStringList::split (' ', vbox.GetDVDImageUsage (aId, CEnums::TemporaryUsage));
827
828 QString usage;
829
830 for (QStringList::Iterator it = permMachines.begin();
831 it != permMachines.end();
832 ++it)
833 {
834 if (usage)
835 usage += ", ";
836 usage += vbox.GetMachine (QUuid (*it)).GetName();
837 }
838
839 for (QStringList::Iterator it = tempMachines.begin();
840 it != tempMachines.end();
841 ++it)
842 {
843 /* skip IDs that are in the permanent list */
844 if (!permMachines.contains (*it))
845 {
846 if (usage)
847 usage += ", [";
848 else
849 usage += "[";
850 usage += vbox.GetMachine (QUuid (*it)).GetName() + "]";
851 }
852 }
853
854 return usage;
855}
856
857QString VBoxDiskImageManagerDlg::getFloppyImageUsage (const QUuid &aId)
858{
859 CVirtualBox vbox = vboxGlobal().virtualBox();
860
861 QStringList permMachines =
862 QStringList::split (' ', vbox.GetFloppyImageUsage (aId, CEnums::PermanentUsage));
863 QStringList tempMachines =
864 QStringList::split (' ', vbox.GetFloppyImageUsage (aId, CEnums::TemporaryUsage));
865
866 QString usage;
867
868 for (QStringList::Iterator it = permMachines.begin();
869 it != permMachines.end();
870 ++it)
871 {
872 if (usage)
873 usage += ", ";
874 usage += vbox.GetMachine (QUuid (*it)).GetName();
875 }
876
877 for (QStringList::Iterator it = tempMachines.begin();
878 it != tempMachines.end();
879 ++it)
880 {
881 /* skip IDs that are in the permanent list */
882 if (!permMachines.contains (*it))
883 {
884 if (usage)
885 usage += ", [";
886 else
887 usage += "[";
888 usage += vbox.GetMachine (QUuid (*it)).GetName() + "]";
889 }
890 }
891
892 return usage;
893}
894
895
896QString VBoxDiskImageManagerDlg::composeHdToolTip (CHardDisk &aHd,
897 VBoxMedia::Status aStatus)
898{
899 CVirtualBox vbox = vboxGlobal().virtualBox();
900 QUuid machineId = aHd.GetMachineId();
901
902 QString src = aHd.GetLocation();
903 QFileInfo fi (src);
904 QString location = aHd.GetStorageType() == CEnums::ISCSIHardDisk ? src :
905 QDir::convertSeparators (fi.absFilePath());
906
907 QString storageType = vboxGlobal().toString (aHd.GetStorageType());
908 QString hardDiskType = vboxGlobal().hardDiskTypeString (aHd);
909
910 QString usage;
911 if (!machineId.isNull())
912 usage = vbox.GetMachine (machineId).GetName();
913
914 QString snapshotName;
915 if (!machineId.isNull() && !aHd.GetSnapshotId().isNull())
916 {
917 CSnapshot snapshot = vbox.GetMachine (machineId).
918 GetSnapshot (aHd.GetSnapshotId());
919 if (!snapshot.isNull())
920 snapshotName = snapshot.GetName();
921 }
922
923 /* compose tool-tip information */
924 QString tip;
925 switch (aStatus)
926 {
927 case VBoxMedia::Unknown:
928 {
929 tip = tr ("<nobr><b>%1</b></nobr><br>"
930 "Checking accessibility...", "HDD")
931 .arg (location);
932 break;
933 }
934 case VBoxMedia::Ok:
935 {
936 tip = tr ("<nobr><b>%1</b></nobr><br>"
937 "<nobr>Disk type:&nbsp;&nbsp;%2</nobr><br>"
938 "<nobr>Storage type:&nbsp;&nbsp;%3</nobr>")
939 .arg (location)
940 .arg (hardDiskType)
941 .arg (storageType);
942
943 if (!usage.isNull())
944 tip += tr ("<br><nobr>Attached to:&nbsp;&nbsp;%1</nobr>", "HDD")
945 .arg (usage);
946 if (!snapshotName.isNull())
947 tip += tr ("<br><nobr>Snapshot:&nbsp;&nbsp;%5</nobr>", "HDD")
948 .arg (snapshotName);
949 break;
950 }
951 case VBoxMedia::Error:
952 {
953 /// @todo (r=dmik) paass a complete VBoxMedia instance here
954 // to get the result of blabla.GetAccessible() call form CUnknown
955 tip = tr ("<nobr><b>%1</b></nobr><br>"
956 "Error checking media accessibility", "HDD")
957 .arg (location);
958 break;
959 }
960 case VBoxMedia::Inaccessible:
961 {
962 tip = tr ("<nobr><b>%1</b></nobr><br>%2", "HDD")
963 .arg (location)
964 .arg (VBoxGlobal::highlight (aHd.GetLastAccessError(),
965 true /* aToolTip */));
966 break;
967 }
968 default:
969 AssertFailed();
970 }
971 return tip;
972}
973
974QString VBoxDiskImageManagerDlg::composeCdToolTip (CDVDImage &aCd,
975 VBoxMedia::Status aStatus)
976{
977 QString src = aCd.GetFilePath();
978 QFileInfo fi (src);
979 QString location = QDir::convertSeparators (fi.absFilePath ());
980 QUuid uuid = aCd.GetId();
981 QString usage = getDVDImageUsage (uuid);
982
983 /* compose tool-tip information */
984 QString tip;
985 switch (aStatus)
986 {
987 case VBoxMedia::Unknown:
988 {
989 tip = tr ("<nobr><b>%1</b></nobr><br>"
990 "Checking accessibility...", "CD/DVD/Floppy")
991 .arg (location);
992 break;
993 }
994 case VBoxMedia::Ok:
995 {
996 tip = tr ("<nobr><b>%1</b></nobr>", "CD/DVD/Floppy")
997 .arg (location);
998
999 if (!usage.isNull())
1000 tip += tr ("<br><nobr>Attached to:&nbsp;&nbsp;%1</nobr>",
1001 "CD/DVD/Floppy")
1002 .arg (usage);
1003 break;
1004 }
1005 case VBoxMedia::Error:
1006 {
1007 /// @todo (r=dmik) paass a complete VBoxMedia instance here
1008 // to get the result of blabla.GetAccessible() call form CUnknown
1009 tip = tr ("<nobr><b>%1</b></nobr><br>"
1010 "Error checking media accessibility", "CD/DVD/Floppy")
1011 .arg (location);
1012 break;
1013 }
1014 case VBoxMedia::Inaccessible:
1015 {
1016 /// @todo (r=dmik) correct this when GetLastAccessError() is
1017 // implemented for IDVDImage
1018 tip = tr ("<nobr><b>%1</b></nobr><br>%2")
1019 .arg (location)
1020 .arg (tr ("The image file is not accessible",
1021 "CD/DVD/Floppy"));
1022 break;
1023 }
1024 default:
1025 AssertFailed();
1026 }
1027 return tip;
1028}
1029
1030QString VBoxDiskImageManagerDlg::composeFdToolTip (CFloppyImage &aFd,
1031 VBoxMedia::Status aStatus)
1032{
1033 QString src = aFd.GetFilePath();
1034 QFileInfo fi (src);
1035 QString location = QDir::convertSeparators (fi.absFilePath ());
1036 QUuid uuid = aFd.GetId();
1037 QString usage = getFloppyImageUsage (uuid);
1038
1039 /* compose tool-tip information */
1040 /* compose tool-tip information */
1041 QString tip;
1042 switch (aStatus)
1043 {
1044 case VBoxMedia::Unknown:
1045 {
1046 tip = tr ("<nobr><b>%1</b></nobr><br>"
1047 "Checking accessibility...", "CD/DVD/Floppy")
1048 .arg (location);
1049 break;
1050 }
1051 case VBoxMedia::Ok:
1052 {
1053 tip = tr ("<nobr><b>%1</b></nobr>", "CD/DVD/Floppy")
1054 .arg (location);
1055
1056 if (!usage.isNull())
1057 tip += tr ("<br><nobr>Attached to:&nbsp;&nbsp;%1</nobr>",
1058 "CD/DVD/Floppy")
1059 .arg (usage);
1060 break;
1061 }
1062 case VBoxMedia::Error:
1063 {
1064 /// @todo (r=dmik) paass a complete VBoxMedia instance here
1065 // to get the result of blabla.GetAccessible() call form CUnknown
1066 tip = tr ("<nobr><b>%1</b></nobr><br>"
1067 "Error checking media accessibility", "CD/DVD/Floppy")
1068 .arg (location);
1069 break;
1070 }
1071 case VBoxMedia::Inaccessible:
1072 {
1073 /// @todo (r=dmik) correct this when GetLastAccessError() is
1074 // implemented for IDVDImage
1075 tip = tr ("<nobr><b>%1</b></nobr><br>%2")
1076 .arg (location)
1077 .arg (tr ("The image file is not accessible",
1078 "CD/DVD/Floppy"));
1079 break;
1080 }
1081 default:
1082 AssertFailed();
1083 }
1084 return tip;
1085}
1086
1087
1088void VBoxDiskImageManagerDlg::updateHdItem (DiskImageItem *aItem,
1089 const VBoxMedia &aMedia)
1090{
1091 if (!aItem) return;
1092 CHardDisk hd = aMedia.disk;
1093 VBoxMedia::Status status = aMedia.status;
1094
1095 QUuid uuid = hd.GetId();
1096 QString src = hd.GetLocation();
1097 QUuid machineId = hd.GetMachineId();
1098 QString usage;
1099 if (!machineId.isNull())
1100 usage = vbox.GetMachine (machineId).GetName();
1101 QString storageType = vboxGlobal().toString (hd.GetStorageType());
1102 QString hardDiskType = vboxGlobal().hardDiskTypeString (hd);
1103 QString virtualSize = status == VBoxMedia::Ok ?
1104 vboxGlobal().formatSize ((ULONG64)hd.GetSize() * _1M) : QString ("--");
1105 QString actualSize = status == VBoxMedia::Ok ?
1106 vboxGlobal().formatSize (hd.GetActualSize()) : QString ("--");
1107 QString snapshotName;
1108 if (!machineId.isNull() && !hd.GetSnapshotId().isNull())
1109 {
1110 CSnapshot snapshot = vbox.GetMachine (machineId).
1111 GetSnapshot (hd.GetSnapshotId());
1112 if (!snapshot.isNull())
1113 snapshotName = QString ("%1").arg (snapshot.GetName());
1114 }
1115 QFileInfo fi (src);
1116
1117 aItem->setText (0, fi.fileName());
1118 aItem->setText (1, virtualSize);
1119 aItem->setText (2, actualSize);
1120 aItem->setPath (hd.GetStorageType() == CEnums::ISCSIHardDisk ? src :
1121 QDir::convertSeparators (fi.absFilePath()));
1122 aItem->setUsage (usage);
1123 aItem->setSnapshotName (snapshotName);
1124 aItem->setDiskType (hardDiskType);
1125 aItem->setStorageType (storageType);
1126 aItem->setVirtualSize (virtualSize);
1127 aItem->setActualSize (actualSize);
1128 aItem->setUuid (uuid);
1129 aItem->setMachineId (machineId);
1130 aItem->setToolTip (composeHdToolTip (hd, status));
1131 aItem->setStatus (status);
1132
1133 makeWarningMark (aItem, aMedia.status, VBoxDefs::HD);
1134}
1135
1136void VBoxDiskImageManagerDlg::updateCdItem (DiskImageItem *aItem,
1137 const VBoxMedia &aMedia)
1138{
1139 if (!aItem) return;
1140 CDVDImage cd = aMedia.disk;
1141 VBoxMedia::Status status = aMedia.status;
1142
1143 QUuid uuid = cd.GetId();
1144 QString src = cd.GetFilePath();
1145 QString usage = getDVDImageUsage (uuid);
1146 QString size = status == VBoxMedia::Ok ?
1147 vboxGlobal().formatSize (cd.GetSize()) : QString ("--");
1148 QFileInfo fi (src);
1149
1150 aItem->setText (0, fi.fileName());
1151 aItem->setText (1, size);
1152 aItem->setPath (QDir::convertSeparators (fi.absFilePath ()));
1153 aItem->setUsage (usage);
1154 aItem->setActualSize (size);
1155 aItem->setUuid (uuid);
1156 aItem->setToolTip (composeCdToolTip (cd, status));
1157 aItem->setStatus (status);
1158
1159 makeWarningMark (aItem, aMedia.status, VBoxDefs::CD);
1160}
1161
1162void VBoxDiskImageManagerDlg::updateFdItem (DiskImageItem *aItem,
1163 const VBoxMedia &aMedia)
1164{
1165 if (!aItem) return;
1166 CFloppyImage fd = aMedia.disk;
1167 VBoxMedia::Status status = aMedia.status;
1168
1169 QUuid uuid = fd.GetId();
1170 QString src = fd.GetFilePath();
1171 QString usage = getFloppyImageUsage (uuid);
1172 QString size = status == VBoxMedia::Ok ?
1173 vboxGlobal().formatSize (fd.GetSize()) : QString ("--");
1174 QFileInfo fi (src);
1175
1176 aItem->setText (0, fi.fileName());
1177 aItem->setText (1, size);
1178 aItem->setPath (QDir::convertSeparators (fi.absFilePath ()));
1179 aItem->setUsage (usage);
1180 aItem->setActualSize (size);
1181 aItem->setUuid (uuid);
1182 aItem->setToolTip (composeFdToolTip (fd, status));
1183 aItem->setStatus (status);
1184
1185 makeWarningMark (aItem, aMedia.status, VBoxDefs::FD);
1186}
1187
1188
1189DiskImageItem* VBoxDiskImageManagerDlg::createHdItem (QListView *aList,
1190 const VBoxMedia &aMedia)
1191{
1192 CHardDisk hd = aMedia.disk;
1193 QUuid rootId = hd.GetParent().isNull() ? QUuid() : hd.GetParent().GetId();
1194 DiskImageItem *root = searchItem (aList, rootId);
1195 DiskImageItem *item = createImageNode (aList, root, aMedia);
1196 updateHdItem (item, aMedia);
1197 return item;
1198}
1199
1200DiskImageItem* VBoxDiskImageManagerDlg::createCdItem (QListView *aList,
1201 const VBoxMedia &aMedia)
1202{
1203 DiskImageItem *item = createImageNode (aList, 0, aMedia);
1204 updateCdItem (item, aMedia);
1205 return item;
1206}
1207
1208DiskImageItem* VBoxDiskImageManagerDlg::createFdItem (QListView *aList,
1209 const VBoxMedia &aMedia)
1210{
1211 DiskImageItem *item = createImageNode (aList, 0, aMedia);
1212 updateFdItem (item, aMedia);
1213 return item;
1214}
1215
1216
1217void VBoxDiskImageManagerDlg::makeWarningMark (DiskImageItem *aItem,
1218 VBoxMedia::Status aStatus,
1219 VBoxDefs::DiskType aType)
1220{
1221 const QPixmap &pm = aStatus == VBoxMedia::Inaccessible ? pxInaccessible :
1222 aStatus == VBoxMedia::Error ? pxErroneous : QPixmap();
1223
1224 if (!pm.isNull())
1225 {
1226 aItem->setPixmap (0, pm);
1227 QIconSet iconSet (pm);
1228 QWidget *wt = aType == VBoxDefs::HD ? twImages->page (0) :
1229 aType == VBoxDefs::CD ? twImages->page (1) :
1230 aType == VBoxDefs::FD ? twImages->page (2) : 0;
1231 Assert (wt); /* aType should be correct */
1232 twImages->changeTab (wt, iconSet, twImages->tabLabel (wt));
1233 aItem->listView()->ensureItemVisible (aItem);
1234 }
1235}
1236
1237
1238DiskImageItem* VBoxDiskImageManagerDlg::searchItem (QListView *aList,
1239 const QUuid &aId)
1240{
1241 if (aId.isNull()) return 0;
1242 DiskImageItemIterator iterator (aList);
1243 while (*iterator)
1244 {
1245 if ((*iterator)->getUuid() == aId)
1246 return *iterator;
1247 ++iterator;
1248 }
1249 return 0;
1250}
1251
1252
1253void VBoxDiskImageManagerDlg::setup (int aType, bool aDoSelect,
1254 const QUuid *aTargetVMId /* = NULL */,
1255 bool aRefresh /* = true */,
1256 CMachine machine /* = NULL */)
1257{
1258 cmachine = machine;
1259
1260 type = aType;
1261 twImages->setTabEnabled (twImages->page(0), type & VBoxDefs::HD);
1262 twImages->setTabEnabled (twImages->page(1), type & VBoxDefs::CD);
1263 twImages->setTabEnabled (twImages->page(2), type & VBoxDefs::FD);
1264
1265 doSelect = aDoSelect;
1266 if (aTargetVMId)
1267 targetVMId = aTargetVMId->toString();
1268
1269 if (doSelect)
1270 buttonOk->setText (tr ("&Select"));
1271 else
1272 buttonCancel->setShown (false);
1273
1274 /* listen to "media enumeration started" signals */
1275 connect (&vboxGlobal(), SIGNAL (mediaEnumStarted()),
1276 this, SLOT (mediaEnumStarted()));
1277 /* listen to "media enumeration" signals */
1278 connect (&vboxGlobal(), SIGNAL (mediaEnumerated (const VBoxMedia &, int)),
1279 this, SLOT (mediaEnumerated (const VBoxMedia &, int)));
1280 /* listen to "media enumeration finished" signals */
1281 connect (&vboxGlobal(), SIGNAL (mediaEnumFinished (const VBoxMediaList &)),
1282 this, SLOT (mediaEnumFinished (const VBoxMediaList &)));
1283
1284 /* listen to "media add" signals */
1285 connect (&vboxGlobal(), SIGNAL (mediaAdded (const VBoxMedia &)),
1286 this, SLOT (mediaAdded (const VBoxMedia &)));
1287 /* listen to "media update" signals */
1288 connect (&vboxGlobal(), SIGNAL (mediaUpdated (const VBoxMedia &)),
1289 this, SLOT (mediaUpdated (const VBoxMedia &)));
1290 /* listen to "media remove" signals */
1291 connect (&vboxGlobal(), SIGNAL (mediaRemoved (VBoxDefs::DiskType, const QUuid &)),
1292 this, SLOT (mediaRemoved (VBoxDefs::DiskType, const QUuid &)));
1293
1294 if (aRefresh && !vboxGlobal().isMediaEnumerationStarted())
1295 {
1296 vboxGlobal().startEnumeratingMedia();
1297 }
1298 else
1299 {
1300 /* insert already enumerated media */
1301 const VBoxMediaList &list = vboxGlobal().currentMediaList();
1302 prepareToRefresh (list.size());
1303 VBoxMediaList::const_iterator it;
1304 int index = 0;
1305 for (it = list.begin(); it != list.end(); ++ it)
1306 {
1307 mediaAdded (*it);
1308 if ((*it).status != VBoxMedia::Unknown)
1309 mProgressBar->setProgress (++ index);
1310 }
1311
1312 /* emulate the finished signal to reuse the code */
1313 if (!vboxGlobal().isMediaEnumerationStarted())
1314 mediaEnumFinished (list);
1315 }
1316
1317 /* for a newly opened dialog, select the first item */
1318 setCurrentItem (hdsView, hdsView->firstChild());
1319 setCurrentItem (cdsView, cdsView->firstChild());
1320 setCurrentItem (fdsView, fdsView->firstChild());
1321}
1322
1323
1324void VBoxDiskImageManagerDlg::mediaEnumStarted()
1325{
1326 /* load default tab icons */
1327 twImages->changeTab (twImages->page (0),
1328 QIconSet (pxHD),
1329 twImages->tabLabel (twImages->page (0)));
1330 twImages->changeTab (twImages->page (1),
1331 QIconSet (pxCD),
1332 twImages->tabLabel (twImages->page (1)));
1333 twImages->changeTab (twImages->page (2),
1334 QIconSet (pxFD),
1335 twImages->tabLabel (twImages->page (2)));
1336
1337 /* load current media list */
1338 const VBoxMediaList &list = vboxGlobal().currentMediaList();
1339 prepareToRefresh (list.size());
1340 VBoxMediaList::const_iterator it;
1341 for (it = list.begin(); it != list.end(); ++ it)
1342 mediaAdded (*it);
1343
1344 /* select the first item if the previous saved item is not found
1345 * or no current item at all */
1346 if (!hdsView->currentItem() || !hdSelectedId.isNull())
1347 setCurrentItem (hdsView, hdsView->firstChild());
1348 if (!cdsView->currentItem() || !cdSelectedId.isNull())
1349 setCurrentItem (cdsView, cdsView->firstChild());
1350 if (!fdsView->currentItem() || !fdSelectedId.isNull())
1351 setCurrentItem (fdsView, fdsView->firstChild());
1352
1353 processCurrentChanged();
1354}
1355
1356void VBoxDiskImageManagerDlg::mediaEnumerated (const VBoxMedia &aMedia,
1357 int aIndex)
1358{
1359 mediaUpdated (aMedia);
1360 Assert (aMedia.status != VBoxMedia::Unknown);
1361 if (aMedia.status != VBoxMedia::Unknown)
1362 mProgressBar->setProgress (aIndex + 1);
1363}
1364
1365void VBoxDiskImageManagerDlg::mediaEnumFinished (const VBoxMediaList &/* aList */)
1366{
1367 mProgressBar->setHidden (true);
1368 mProgressText->setHidden (true);
1369
1370 imRefreshAction->setEnabled (true);
1371 unsetCursor();
1372
1373 /* adjust columns (it is strange to repeat but it works) */
1374
1375 hdsView->adjustColumn (1);
1376 hdsView->adjustColumn (2);
1377 hdsView->adjustColumn (1);
1378
1379 cdsView->adjustColumn (1);
1380 cdsView->adjustColumn (2);
1381 cdsView->adjustColumn (1);
1382
1383 fdsView->adjustColumn (1);
1384 fdsView->adjustColumn (2);
1385 fdsView->adjustColumn (1);
1386
1387 processCurrentChanged();
1388}
1389
1390
1391void VBoxDiskImageManagerDlg::mediaAdded (const VBoxMedia &aMedia)
1392{
1393 /* ignore non-interesting aMedia */
1394 if (!(type & aMedia.type))
1395 return;
1396
1397 DiskImageItem *item = 0;
1398 switch (aMedia.type)
1399 {
1400 case VBoxDefs::HD:
1401 item = createHdItem (hdsView, aMedia);
1402 if (item->getUuid() == hdSelectedId)
1403 {
1404 setCurrentItem (hdsView, item);
1405 hdSelectedId = QUuid();
1406 }
1407 break;
1408 case VBoxDefs::CD:
1409 item = createCdItem (cdsView, aMedia);
1410 if (item->getUuid() == cdSelectedId)
1411 {
1412 setCurrentItem (cdsView, item);
1413 cdSelectedId = QUuid();
1414 }
1415 break;
1416 case VBoxDefs::FD:
1417 item = createFdItem (fdsView, aMedia);
1418 if (item->getUuid() == fdSelectedId)
1419 {
1420 setCurrentItem (fdsView, item);
1421 fdSelectedId = QUuid();
1422 }
1423 break;
1424 default:
1425 AssertMsgFailed (("Invalid aMedia type\n"));
1426 }
1427
1428 if (!item)
1429 return;
1430
1431 if (!vboxGlobal().isMediaEnumerationStarted())
1432 setCurrentItem (getListView (aMedia.type), item);
1433 if (item == getCurrentListView()->currentItem())
1434 processCurrentChanged (item);
1435}
1436
1437void VBoxDiskImageManagerDlg::mediaUpdated (const VBoxMedia &aMedia)
1438{
1439 /* ignore non-interesting aMedia */
1440 if (!(type & aMedia.type))
1441 return;
1442
1443 DiskImageItem *item = 0;
1444 switch (aMedia.type)
1445 {
1446 case VBoxDefs::HD:
1447 {
1448 CHardDisk hd = aMedia.disk;
1449 item = searchItem (hdsView, hd.GetId());
1450 updateHdItem (item, aMedia);
1451 break;
1452 }
1453 case VBoxDefs::CD:
1454 {
1455 CDVDImage cd = aMedia.disk;
1456 item = searchItem (cdsView, cd.GetId());
1457 updateCdItem (item, aMedia);
1458 break;
1459 }
1460 case VBoxDefs::FD:
1461 {
1462 CFloppyImage fd = aMedia.disk;
1463 item = searchItem (fdsView, fd.GetId());
1464 updateFdItem (item, aMedia);
1465 break;
1466 }
1467 default:
1468 AssertMsgFailed (("Invalid aMedia type\n"));
1469 }
1470
1471 if (!item)
1472 return;
1473
1474 /* note: current items on invisible tabs are not updated because
1475 * it is always done in processCurrentChanged() when the user switches
1476 * to an invisible tab */
1477 if (item == getCurrentListView()->currentItem())
1478 processCurrentChanged (item);
1479}
1480
1481void VBoxDiskImageManagerDlg::mediaRemoved (VBoxDefs::DiskType aType,
1482 const QUuid &aId)
1483{
1484 QListView *listView = getListView (aType);
1485 DiskImageItem *item = searchItem (listView, aId);
1486 delete item;
1487 setCurrentItem (listView, listView->currentItem());
1488}
1489
1490
1491void VBoxDiskImageManagerDlg::machineStateChanged (const VBoxMachineStateChangeEvent &e)
1492{
1493 /// @todo (r=dmik) IVirtualBoxCallback::OnMachineStateChange
1494 // must also expose the old state! In this case we won't need to cache
1495 // the state value in every class in GUI that uses this signal.
1496
1497 switch (e.state)
1498 {
1499 case CEnums::PoweredOff:
1500 case CEnums::Aborted:
1501 case CEnums::Saved:
1502 case CEnums::Starting:
1503 case CEnums::Restoring:
1504 {
1505 refreshAll();
1506 break;
1507 }
1508 default:
1509 break;
1510 }
1511}
1512
1513
1514void VBoxDiskImageManagerDlg::clearInfoPanes()
1515{
1516 hdsPane1->clear();
1517 hdsPane2->clear(), hdsPane3->clear();
1518 hdsPane4->clear(), hdsPane5->clear();
1519 cdsPane1->clear(), cdsPane2->clear();
1520 fdsPane1->clear(), fdsPane2->clear();
1521}
1522
1523
1524void VBoxDiskImageManagerDlg::prepareToRefresh (int aTotal)
1525{
1526 /* info panel clearing */
1527 clearInfoPanes();
1528
1529 /* prepare progressbar */
1530 if (mProgressBar)
1531 {
1532 mProgressBar->setProgress (0, aTotal);
1533 mProgressBar->setHidden (false);
1534 mProgressText->setHidden (false);
1535 }
1536
1537 imRefreshAction->setEnabled (false);
1538 setCursor (QCursor (BusyCursor));
1539
1540 /* store the current list selections */
1541
1542 QListViewItem *item;
1543 DiskImageItem *di;
1544
1545 item = hdsView->currentItem();
1546 di = (item && item->rtti() == DiskImageItem::TypeId) ?
1547 static_cast <DiskImageItem *> (item) : 0;
1548 hdSelectedId = di ? di->getUuid() : QString::null;
1549
1550 item = cdsView->currentItem();
1551 di = (item && item->rtti() == DiskImageItem::TypeId) ?
1552 static_cast <DiskImageItem *> (item) : 0;
1553 cdSelectedId = di ? di->getUuid() : QString::null;
1554
1555 item = fdsView->currentItem();
1556 di = (item && item->rtti() == DiskImageItem::TypeId) ?
1557 static_cast <DiskImageItem *> (item) : 0;
1558 fdSelectedId = di ? di->getUuid() : QString::null;
1559
1560 /* finally, clear all lists */
1561 hdsView->clear();
1562 cdsView->clear();
1563 fdsView->clear();
1564}
1565
1566
1567void VBoxDiskImageManagerDlg::refreshAll()
1568{
1569 /* start enumerating media */
1570 vboxGlobal().startEnumeratingMedia();
1571}
1572
1573
1574bool VBoxDiskImageManagerDlg::checkImage (DiskImageItem* aItem)
1575{
1576 QUuid itemId = aItem ? QUuid (aItem->getUuid()) : QUuid();
1577 if (itemId.isNull()) return false;
1578
1579 QListView* parentList = aItem->listView();
1580 if (parentList == hdsView)
1581 {
1582 CHardDisk hd = aItem->getMedia().disk;
1583 QUuid machineId = hd.GetMachineId();
1584 if (machineId.isNull() ||
1585 vbox.GetMachine (machineId).GetState() != CEnums::PoweredOff &&
1586 vbox.GetMachine (machineId).GetState() != CEnums::Aborted)
1587 return false;
1588 }
1589 else if (parentList == cdsView)
1590 {
1591 QString usage = getDVDImageUsage (itemId);
1592 /* check if there is temporary usage: */
1593 QStringList tempMachines =
1594 QStringList::split (' ', vbox.GetDVDImageUsage (itemId,
1595 CEnums::TemporaryUsage));
1596 if (!tempMachines.isEmpty())
1597 return false;
1598 /* only permamently mounted .iso could be released */
1599 QStringList permMachines =
1600 QStringList::split (' ', vbox.GetDVDImageUsage (itemId,
1601 CEnums::PermanentUsage));
1602 for (QStringList::Iterator it = permMachines.begin();
1603 it != permMachines.end(); ++it)
1604 if (vbox.GetMachine(QUuid (*it)).GetState() != CEnums::PoweredOff &&
1605 vbox.GetMachine(QUuid (*it)).GetState() != CEnums::Aborted)
1606 return false;
1607 }
1608 else if (parentList == fdsView)
1609 {
1610 QString usage = getFloppyImageUsage(itemId);
1611 /* check if there is temporary usage: */
1612 QStringList tempMachines =
1613 QStringList::split (' ', vbox.GetFloppyImageUsage (itemId,
1614 CEnums::TemporaryUsage));
1615 if (!tempMachines.isEmpty())
1616 return false;
1617 /* only permamently mounted .iso could be released */
1618 QStringList permMachines =
1619 QStringList::split (' ', vbox.GetFloppyImageUsage (itemId,
1620 CEnums::PermanentUsage));
1621 for (QStringList::Iterator it = permMachines.begin();
1622 it != permMachines.end(); ++it)
1623 if (vbox.GetMachine(QUuid (*it)).GetState() != CEnums::PoweredOff &&
1624 vbox.GetMachine(QUuid (*it)).GetState() != CEnums::Aborted)
1625 return false;
1626 }
1627 else
1628 {
1629 return false;
1630 }
1631 return true;
1632}
1633
1634
1635void VBoxDiskImageManagerDlg::setCurrentItem (QListView *aListView,
1636 QListViewItem *aItem)
1637{
1638 if (!aItem)
1639 return;
1640
1641 aListView->setCurrentItem (aItem);
1642 aListView->setSelected (aListView->currentItem(), true);
1643}
1644
1645
1646void VBoxDiskImageManagerDlg::processCurrentChanged()
1647{
1648 QListView *currentList = getCurrentListView();
1649 currentList->setFocus();
1650
1651 /* tab stop setup */
1652 setTabOrder (hdsView, hdsPane1);
1653 setTabOrder (hdsPane1, hdsPane2);
1654 setTabOrder (hdsPane2, hdsPane3);
1655 setTabOrder (hdsPane3, hdsPane4);
1656 setTabOrder (hdsPane4, hdsPane5);
1657 setTabOrder (hdsPane5, buttonHelp);
1658
1659 setTabOrder (cdsView, cdsPane1);
1660 setTabOrder (cdsPane1, cdsPane2);
1661 setTabOrder (cdsPane2, buttonHelp);
1662
1663 setTabOrder (fdsView, fdsPane1);
1664 setTabOrder (fdsPane1, fdsPane2);
1665 setTabOrder (fdsPane2, buttonHelp);
1666
1667 setTabOrder (buttonHelp, buttonOk);
1668 setTabOrder (buttonOk, twImages);
1669
1670 processCurrentChanged (currentList->currentItem());
1671}
1672
1673void VBoxDiskImageManagerDlg::processCurrentChanged (QListViewItem *aItem)
1674{
1675 DiskImageItem *item = aItem && aItem->rtti() == DiskImageItem::TypeId ?
1676 static_cast<DiskImageItem*> (aItem) : 0;
1677
1678 bool notInEnum = !vboxGlobal().isMediaEnumerationStarted();
1679 bool modifyEnabled = notInEnum &&
1680 item && item->getUsage().isNull() &&
1681 !item->firstChild() && !item->getPath().isNull();
1682 bool releaseEnabled = item && !item->getUsage().isNull() &&
1683 checkImage (item) &&
1684 !item->parent() && !item->firstChild() &&
1685 item->getSnapshotName().isNull();
1686 bool newEnabled = notInEnum &&
1687 getCurrentListView() == hdsView ? true : false;
1688 bool addEnabled = notInEnum;
1689
1690 // imEditAction->setEnabled (modifyEnabled);
1691 imRemoveAction->setEnabled (modifyEnabled);
1692 imReleaseAction->setEnabled (releaseEnabled);
1693 imNewAction->setEnabled (newEnabled);
1694 imAddAction->setEnabled (addEnabled);
1695
1696 // itemMenu->setItemVisible (itemMenu->idAt(0), modifyEnabled);
1697 itemMenu->setItemEnabled (itemMenu->idAt(0), modifyEnabled);
1698 itemMenu->setItemEnabled (itemMenu->idAt(1), releaseEnabled);
1699
1700 if (doSelect)
1701 {
1702 bool selectEnabled = item && !item->parent() &&
1703 (!newEnabled ||
1704 (item->getUsage().isNull() ||
1705 item->getMachineId() == targetVMId));
1706
1707 buttonOk->setEnabled (selectEnabled);
1708 }
1709
1710 if (item)
1711 {
1712 if (item->listView() == hdsView)
1713 {
1714 hdsPane1->setText (item->getInformation (item->getPath(), true, "end"));
1715 hdsPane2->setText (item->getInformation (item->getDiskType(), false));
1716 hdsPane3->setText (item->getInformation (item->getStorageType(), false));
1717 hdsPane4->setText (item->getInformation (item->getUsage()));
1718 hdsPane5->setText (item->getInformation (item->getSnapshotName()));
1719 }
1720 else if (item->listView() == cdsView)
1721 {
1722 cdsPane1->setText (item->getInformation (item->getPath(), true, "end"));
1723 cdsPane2->setText (item->getInformation (item->getUsage()));
1724 }
1725 else if (item->listView() == fdsView)
1726 {
1727 fdsPane1->setText (item->getInformation (item->getPath(), true, "end"));
1728 fdsPane2->setText (item->getInformation (item->getUsage()));
1729 }
1730 }
1731 else
1732 clearInfoPanes();
1733}
1734
1735
1736void VBoxDiskImageManagerDlg::processPressed (QListViewItem * aItem)
1737{
1738 if (!aItem)
1739 {
1740 QListView *currentList = getCurrentListView();
1741 currentList->setSelected (currentList->currentItem(), true);
1742 }
1743}
1744
1745
1746void VBoxDiskImageManagerDlg::newImage()
1747{
1748 AssertReturnVoid (getCurrentListView() == hdsView);
1749
1750 VBoxNewHDWzd dlg (this, "VBoxNewHDWzd");
1751
1752 if (dlg.exec() == QDialog::Accepted)
1753 {
1754 CHardDisk hd = dlg.hardDisk();
1755 VBoxMedia::Status status =
1756 hd.GetAccessible() ? VBoxMedia::Ok :
1757 hd.isOk() ? VBoxMedia::Inaccessible :
1758 VBoxMedia::Error;
1759 vboxGlobal().addMedia (VBoxMedia (CUnknown (hd), VBoxDefs::HD, status));
1760 }
1761}
1762
1763
1764void VBoxDiskImageManagerDlg::addImage()
1765{
1766 QListView *currentList = getCurrentListView();
1767 DiskImageItem *item =
1768 currentList->currentItem() &&
1769 currentList->currentItem()->rtti() == DiskImageItem::TypeId ?
1770 static_cast <DiskImageItem*> (currentList->currentItem()) : 0;
1771
1772 QString dir;
1773 if (item && item->getStatus() == VBoxMedia::Ok)
1774 dir = item->getPath().stripWhiteSpace();
1775
1776 if (!dir)
1777 if (currentList == hdsView)
1778 dir = vbox.GetSystemProperties().GetDefaultVDIFolder();
1779 if (!dir || !QFileInfo (dir).exists())
1780 dir = vbox.GetHomeFolder();
1781
1782 QString title;
1783 QString filter;
1784 VBoxDefs::DiskType type = VBoxDefs::InvalidType;
1785
1786 if (currentList == hdsView)
1787 {
1788 filter = tr ("All hard disk images (*.vdi; *.vmdk);;"
1789 "Virtual Disk images (*.vdi);;"
1790 "VMDK images (*.vmdk);;"
1791 "All files (*)");
1792 title = tr ("Select a hard disk image file");
1793 type = VBoxDefs::HD;
1794 }
1795 else if (currentList == cdsView)
1796 {
1797 filter = tr( "CD/DVD-ROM images (*.iso)");
1798 title = tr( "Select a CD/DVD-ROM disk image file" );
1799 type = VBoxDefs::CD;
1800 }
1801 else if (currentList == fdsView)
1802 {
1803 filter = tr( "Floppy images (*.img)" );
1804 title = tr( "Select a floppy disk image file" );
1805 type = VBoxDefs::FD;
1806 }
1807 else
1808 {
1809 AssertMsgFailed (("Root list should be equal to hdsView, cdsView or fdsView"));
1810 }
1811
1812 QString src = QFileDialog::getOpenFileName (dir, filter,
1813 this, "AddDiskImageDialog",
1814 title);
1815 src = QDir::convertSeparators (src);
1816
1817 addImageToList (src, type);
1818 if (!vbox.isOk())
1819 vboxProblem().cannotRegisterMedia (this, vbox, type, src);
1820}
1821
1822
1823void VBoxDiskImageManagerDlg::removeImage()
1824{
1825 QListView *currentList = getCurrentListView();
1826 DiskImageItem *item =
1827 currentList->currentItem() &&
1828 currentList->currentItem()->rtti() == DiskImageItem::TypeId ?
1829 static_cast<DiskImageItem*> (currentList->currentItem()) : 0;
1830 AssertMsg (item, ("Current item must not be null"));
1831
1832 QUuid uuid = QUuid (item->getUuid());
1833 AssertMsg (!uuid.isNull(), ("Current item must have uuid"));
1834
1835 QString src = item->getPath().stripWhiteSpace();
1836 VBoxDefs::DiskType type = VBoxDefs::InvalidType;
1837
1838 if (currentList == hdsView)
1839 {
1840 type = VBoxDefs::HD;
1841 int deleteImage;
1842 /// @todo When creation of VMDK is implemented, we should
1843 /// enable image deletion for them as well (use
1844 /// GetStorageType() to define the correct cast).
1845 CHardDisk disk = item->getMedia().disk;
1846 if (disk.GetStorageType() == CEnums::VirtualDiskImage &&
1847 item->getStatus() == VBoxMedia::Ok)
1848 deleteImage = vboxProblem().confirmHardDiskImageDeletion (this, src);
1849 else
1850 deleteImage = vboxProblem().confirmHardDiskUnregister (this, src);
1851 if (deleteImage == QIMessageBox::Cancel)
1852 return;
1853 CHardDisk hd = vbox.UnregisterHardDisk (uuid);
1854 if (vbox.isOk() && deleteImage == QIMessageBox::Yes)
1855 {
1856 /// @todo When creation of VMDK is implemented, we should
1857 /// enable image deletion for them as well (use
1858 /// GetStorageType() to define the correct cast).
1859 CVirtualDiskImage vdi = CUnknown (hd);
1860 if (vdi.isOk())
1861 vdi.DeleteImage();
1862 if (!vdi.isOk())
1863 vboxProblem().cannotDeleteHardDiskImage (this, vdi);
1864 }
1865 }
1866 else if (currentList == cdsView)
1867 {
1868 type = VBoxDefs::CD;
1869 vbox.UnregisterDVDImage (uuid);
1870 }
1871 else if (currentList == fdsView)
1872 {
1873 type = VBoxDefs::FD;
1874 vbox.UnregisterFloppyImage (uuid);
1875 }
1876
1877 if (vbox.isOk())
1878 vboxGlobal().removeMedia (type, uuid);
1879 else
1880 vboxProblem().cannotUnregisterMedia (this, vbox, type, src);
1881}
1882
1883
1884void VBoxDiskImageManagerDlg::releaseImage()
1885{
1886 QListView *currentList = getCurrentListView();
1887 DiskImageItem *item =
1888 currentList->currentItem() &&
1889 currentList->currentItem()->rtti() == DiskImageItem::TypeId ?
1890 static_cast<DiskImageItem*> (currentList->currentItem()) : 0;
1891 AssertMsg (item, ("Current item must not be null"));
1892
1893 QUuid itemId = QUuid (item->getUuid());
1894 AssertMsg (!itemId.isNull(), ("Current item must have uuid"));
1895
1896 /* if it is a hard disk sub-item: */
1897 if (currentList == hdsView)
1898 {
1899 CHardDisk hd = item->getMedia().disk;
1900 QUuid machineId = hd.GetMachineId();
1901 if (vboxProblem().confirmReleaseImage (this,
1902 vbox.GetMachine (machineId).GetName()))
1903 {
1904 releaseDisk (machineId, itemId, VBoxDefs::HD);
1905 vboxGlobal().updateMedia (item->getMedia());
1906 }
1907 }
1908 /* if it is a cd/dvd sub-item: */
1909 else if (currentList == cdsView)
1910 {
1911 QString usage = getDVDImageUsage (itemId);
1912 /* only permamently mounted .iso could be released */
1913 if (vboxProblem().confirmReleaseImage (this, usage))
1914 {
1915 QStringList permMachines =
1916 QStringList::split (' ', vbox.GetDVDImageUsage (itemId,
1917 CEnums::PermanentUsage));
1918 for (QStringList::Iterator it = permMachines.begin();
1919 it != permMachines.end(); ++it)
1920 releaseDisk (QUuid (*it), itemId, VBoxDefs::CD);
1921
1922 CDVDImage cd = vbox.GetDVDImage (itemId);
1923 vboxGlobal().updateMedia (item->getMedia());
1924 }
1925 }
1926 /* if it is a floppy sub-item: */
1927 else if (currentList == fdsView)
1928 {
1929 QString usage = getFloppyImageUsage (itemId);
1930 /* only permamently mounted .img could be released */
1931 if (vboxProblem().confirmReleaseImage (this, usage))
1932 {
1933 QStringList permMachines =
1934 QStringList::split (' ', vbox.GetFloppyImageUsage (itemId,
1935 CEnums::PermanentUsage));
1936 for (QStringList::Iterator it = permMachines.begin();
1937 it != permMachines.end(); ++it)
1938 releaseDisk (QUuid (*it), itemId, VBoxDefs::FD);
1939
1940 CFloppyImage fd = vbox.GetFloppyImage (itemId);
1941 vboxGlobal().updateMedia (item->getMedia());
1942 }
1943 }
1944}
1945
1946
1947void VBoxDiskImageManagerDlg::releaseDisk (QUuid aMachineId,
1948 QUuid aItemId,
1949 VBoxDefs::DiskType aDiskType)
1950{
1951 CSession session;
1952 CMachine machine;
1953 /* is this media image mapped to this VM: */
1954 if (!cmachine.isNull() && cmachine.GetId() == aMachineId)
1955 {
1956 machine = cmachine;
1957 }
1958 /* or some other: */
1959 else
1960 {
1961 session = vboxGlobal().openSession (aMachineId);
1962 if (session.isNull()) return;
1963 machine = session.GetMachine();
1964 }
1965 /* perform disk releasing: */
1966 switch (aDiskType)
1967 {
1968 case VBoxDefs::HD:
1969 {
1970 /* releasing hd: */
1971 CHardDiskAttachmentEnumerator en =
1972 machine.GetHardDiskAttachments().Enumerate();
1973 while (en.HasMore())
1974 {
1975 CHardDiskAttachment hda = en.GetNext();
1976 if (hda.GetHardDisk().GetId() == aItemId)
1977 {
1978 machine.DetachHardDisk (hda.GetController(),
1979 hda.GetDeviceNumber());
1980 if (!machine.isOk())
1981 vboxProblem().cannotDetachHardDisk (this,
1982 machine, hda.GetController(), hda.GetDeviceNumber());
1983 break;
1984 }
1985 }
1986 break;
1987 }
1988 case VBoxDefs::CD:
1989 {
1990 /* releasing cd: */
1991 machine.GetDVDDrive().Unmount();
1992 break;
1993 }
1994 case VBoxDefs::FD:
1995 {
1996 /* releasing fd: */
1997 machine.GetFloppyDrive().Unmount();
1998 break;
1999 }
2000 default:
2001 AssertMsgFailed (("Incorrect disk type."));
2002 }
2003 /* save all setting changes: */
2004 machine.SaveSettings();
2005 if (!machine.isOk())
2006 vboxProblem().cannotSaveMachineSettings (machine);
2007 /* if local session was opened - close this session: */
2008 if (!session.isNull())
2009 session.Close();
2010}
2011
2012
2013QUuid VBoxDiskImageManagerDlg::getSelectedUuid()
2014{
2015 QListView *currentList = getCurrentListView();
2016 QUuid uuid;
2017
2018 if (currentList->selectedItem() &&
2019 currentList->selectedItem()->rtti() == DiskImageItem::TypeId)
2020 uuid = QUuid (static_cast<DiskImageItem *>(currentList->selectedItem())
2021 ->getUuid());
2022
2023 return uuid;
2024}
2025
2026
2027QString VBoxDiskImageManagerDlg::getSelectedPath()
2028{
2029 QListView *currentList = getCurrentListView();
2030 QString path;
2031
2032 if (currentList->selectedItem() &&
2033 currentList->selectedItem()->rtti() == DiskImageItem::TypeId )
2034 path = static_cast<DiskImageItem*> (currentList->selectedItem())
2035 ->getPath().stripWhiteSpace();
2036
2037 return path;
2038}
2039
2040
2041void VBoxDiskImageManagerDlg::processDoubleClick (QListViewItem*)
2042{
2043 QListView *currentList = getCurrentListView();
2044
2045 if (doSelect && currentList->selectedItem() && buttonOk->isEnabled())
2046 accept();
2047}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette