VirtualBox

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

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

Enumeration mechanism updated with vdi-children enumeration.

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