VirtualBox

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

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

1758: Implement Shared Folders UI

Fixed buttons disappearing during scaling whats-this label in VMSharedFolders Settings.

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