VirtualBox

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

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

FE/Qt: Attempted to fix a bunch of bugs in VBoxGlobal::getOpenFileName().

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