VirtualBox

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

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

1703: Redesign the Virtual Disk Manager dialog:

Ensure VDI nodes containing inaccessible children are fully expanded.

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

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