VirtualBox

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

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

FE/Qt: Fixed VDM: After releasing a VDI, the Select button's enabled state wasn't refreshed until you change the selection and go back again.

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