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 |
|
---|
33 | class DiskImageItem : public QListViewItem
|
---|
34 | {
|
---|
35 | public:
|
---|
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 |
|
---|
125 | protected:
|
---|
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 |
|
---|
145 | VBoxDiskImageManagerDlg *VBoxDiskImageManagerDlg::mModelessDialog = 0;
|
---|
146 |
|
---|
147 |
|
---|
148 | void 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 |
|
---|
178 | void 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 |
|
---|
396 | QIRichLabel *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> %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 |
|
---|
435 | void 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 |
|
---|
454 | void 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 |
|
---|
470 | void VBoxDiskImageManagerDlg::resizeEvent (QResizeEvent*)
|
---|
471 | {
|
---|
472 | sizeGrip->move (centralWidget()->rect().bottomRight() -
|
---|
473 | QPoint(sizeGrip->rect().width() - 1, sizeGrip->rect().height() - 1));
|
---|
474 | }
|
---|
475 |
|
---|
476 |
|
---|
477 | void VBoxDiskImageManagerDlg::closeEvent (QCloseEvent *aEvent)
|
---|
478 | {
|
---|
479 | mModelessDialog = 0;
|
---|
480 | aEvent->accept();
|
---|
481 | }
|
---|
482 |
|
---|
483 |
|
---|
484 | void 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 |
|
---|
511 | QPushButton* 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 |
|
---|
524 | int VBoxDiskImageManagerDlg::result() { return mRescode; }
|
---|
525 | void VBoxDiskImageManagerDlg::setResult (int aRescode) { mRescode = aRescode; }
|
---|
526 | void VBoxDiskImageManagerDlg::accept() { done( Accepted ); }
|
---|
527 | void VBoxDiskImageManagerDlg::reject() { done( Rejected ); }
|
---|
528 |
|
---|
529 | int 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 |
|
---|
542 | void 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 |
|
---|
558 | QListView* VBoxDiskImageManagerDlg::getCurrentListView()
|
---|
559 | {
|
---|
560 | QListView *clv = static_cast<QListView*>(twImages->currentPage()->
|
---|
561 | queryList("QListView")->getFirst());
|
---|
562 | Assert(clv);
|
---|
563 | return clv;
|
---|
564 | }
|
---|
565 |
|
---|
566 | QListView* 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 |
|
---|
582 | bool 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 |
|
---|
653 | void 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 |
|
---|
681 | void 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 |
|
---|
751 | DiskImageItem* 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 |
|
---|
767 | void VBoxDiskImageManagerDlg::invokePopup (QListViewItem *aItem, const QPoint & aPos, int)
|
---|
768 | {
|
---|
769 | if (aItem)
|
---|
770 | itemMenu->popup(aPos);
|
---|
771 | }
|
---|
772 |
|
---|
773 |
|
---|
774 | QString 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 |
|
---|
812 | QString 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 |
|
---|
851 | QString 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: %2</nobr><br>"
|
---|
893 | "<nobr>Storage type: %3</nobr>")
|
---|
894 | .arg (location)
|
---|
895 | .arg (hardDiskType)
|
---|
896 | .arg (storageType);
|
---|
897 |
|
---|
898 | if (!usage.isNull())
|
---|
899 | tip += tr ("<br><nobr>Attached to: %1</nobr>", "HDD")
|
---|
900 | .arg (usage);
|
---|
901 | if (!snapshotName.isNull())
|
---|
902 | tip += tr ("<br><nobr>Snapshot: %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 |
|
---|
929 | QString 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: %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 |
|
---|
985 | QString 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: %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 |
|
---|
1043 | void 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 |
|
---|
1093 | void 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 |
|
---|
1121 | void 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 |
|
---|
1150 | DiskImageItem* 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 |
|
---|
1160 | DiskImageItem* 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 |
|
---|
1169 | DiskImageItem* 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 |
|
---|
1178 | void 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 |
|
---|
1195 | DiskImageItem* 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 |
|
---|
1211 | void 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 |
|
---|
1282 | void 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 |
|
---|
1303 | void 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 |
|
---|
1312 | void 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 |
|
---|
1338 | void 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 | if (item == getCurrentListView()->currentItem())
|
---|
1381 | processCurrentChanged (item);
|
---|
1382 | }
|
---|
1383 |
|
---|
1384 | void VBoxDiskImageManagerDlg::mediaUpdated (const VBoxMedia &aMedia)
|
---|
1385 | {
|
---|
1386 | /* ignore non-interesting aMedia */
|
---|
1387 | if (!(type & aMedia.type))
|
---|
1388 | return;
|
---|
1389 |
|
---|
1390 | DiskImageItem *item = 0;
|
---|
1391 | switch (aMedia.type)
|
---|
1392 | {
|
---|
1393 | case VBoxDefs::HD:
|
---|
1394 | {
|
---|
1395 | CHardDisk hd = aMedia.disk;
|
---|
1396 | item = searchItem (hdsView, hd.GetId());
|
---|
1397 | if (item)
|
---|
1398 | updateHdItem (item, aMedia);
|
---|
1399 | break;
|
---|
1400 | }
|
---|
1401 | case VBoxDefs::CD:
|
---|
1402 | {
|
---|
1403 | CDVDImage cd = aMedia.disk;
|
---|
1404 | item = searchItem (cdsView, cd.GetId());
|
---|
1405 | if (item)
|
---|
1406 | updateCdItem (item, aMedia);
|
---|
1407 | break;
|
---|
1408 | }
|
---|
1409 | case VBoxDefs::FD:
|
---|
1410 | {
|
---|
1411 | CFloppyImage fd = aMedia.disk;
|
---|
1412 | item = searchItem (fdsView, fd.GetId());
|
---|
1413 | if (item)
|
---|
1414 | updateFdItem (item, aMedia);
|
---|
1415 | break;
|
---|
1416 | }
|
---|
1417 | default:
|
---|
1418 | AssertMsgFailed (("Invalid aMedia type\n"));
|
---|
1419 | }
|
---|
1420 |
|
---|
1421 | if (!item)
|
---|
1422 | return;
|
---|
1423 |
|
---|
1424 | /* note: current items on invisible tabs are not updated because
|
---|
1425 | * it is always done in processCurrentChanged() when the user switches
|
---|
1426 | * to an invisible tab */
|
---|
1427 | if (item == getCurrentListView()->currentItem())
|
---|
1428 | processCurrentChanged (item);
|
---|
1429 | }
|
---|
1430 |
|
---|
1431 | void VBoxDiskImageManagerDlg::mediaRemoved (VBoxDefs::DiskType aType,
|
---|
1432 | const QUuid &aId)
|
---|
1433 | {
|
---|
1434 | QListView *listView = getListView (aType);
|
---|
1435 | DiskImageItem *item = searchItem (listView, aId);
|
---|
1436 | delete item;
|
---|
1437 | setCurrentItem (listView, listView->currentItem());
|
---|
1438 | }
|
---|
1439 |
|
---|
1440 |
|
---|
1441 | void VBoxDiskImageManagerDlg::machineStateChanged (const VBoxMachineStateChangeEvent &e)
|
---|
1442 | {
|
---|
1443 | /// @todo (r=dmik) IVirtualBoxCallback::OnMachineStateChange
|
---|
1444 | // must also expose the old state! In this case we won't need to cache
|
---|
1445 | // the state value in every class in GUI that uses this signal.
|
---|
1446 |
|
---|
1447 | switch (e.state)
|
---|
1448 | {
|
---|
1449 | case CEnums::PoweredOff:
|
---|
1450 | case CEnums::Aborted:
|
---|
1451 | case CEnums::Saved:
|
---|
1452 | case CEnums::Starting:
|
---|
1453 | case CEnums::Restoring:
|
---|
1454 | {
|
---|
1455 | refreshAll();
|
---|
1456 | break;
|
---|
1457 | }
|
---|
1458 | default:
|
---|
1459 | break;
|
---|
1460 | }
|
---|
1461 | }
|
---|
1462 |
|
---|
1463 |
|
---|
1464 | void VBoxDiskImageManagerDlg::clearInfoPanes()
|
---|
1465 | {
|
---|
1466 | hdsPane1->clear();
|
---|
1467 | hdsPane2->clear(), hdsPane3->clear();
|
---|
1468 | hdsPane4->clear(), hdsPane5->clear();
|
---|
1469 | cdsPane1->clear(), cdsPane2->clear();
|
---|
1470 | fdsPane1->clear(), fdsPane2->clear();
|
---|
1471 | }
|
---|
1472 |
|
---|
1473 |
|
---|
1474 | void VBoxDiskImageManagerDlg::prepareToRefresh (int aTotal)
|
---|
1475 | {
|
---|
1476 | /* info panel clearing */
|
---|
1477 | clearInfoPanes();
|
---|
1478 |
|
---|
1479 | /* prepare progressbar */
|
---|
1480 | if (mProgressBar)
|
---|
1481 | {
|
---|
1482 | mProgressBar->setProgress (0, aTotal);
|
---|
1483 | mProgressBar->setHidden (false);
|
---|
1484 | mProgressText->setHidden (false);
|
---|
1485 | }
|
---|
1486 |
|
---|
1487 | imRefreshAction->setEnabled (false);
|
---|
1488 | setCursor (QCursor (BusyCursor));
|
---|
1489 |
|
---|
1490 | /* store the current list selections */
|
---|
1491 |
|
---|
1492 | QListViewItem *item;
|
---|
1493 | DiskImageItem *di;
|
---|
1494 |
|
---|
1495 | item = hdsView->currentItem();
|
---|
1496 | di = (item && item->rtti() == 1001) ? static_cast <DiskImageItem *> (item) : 0;
|
---|
1497 | hdSelectedId = di ? di->getUuid() : QString::null;
|
---|
1498 |
|
---|
1499 | item = cdsView->currentItem();
|
---|
1500 | di = (item && item->rtti() == 1001) ? static_cast <DiskImageItem *> (item) : 0;
|
---|
1501 | cdSelectedId = di ? di->getUuid() : QString::null;
|
---|
1502 |
|
---|
1503 | item = fdsView->currentItem();
|
---|
1504 | di = (item && item->rtti() == 1001) ? static_cast <DiskImageItem *> (item) : 0;
|
---|
1505 | fdSelectedId = di ? di->getUuid() : QString::null;
|
---|
1506 |
|
---|
1507 | /* finally, clear all lists */
|
---|
1508 | hdsView->clear();
|
---|
1509 | cdsView->clear();
|
---|
1510 | fdsView->clear();
|
---|
1511 | }
|
---|
1512 |
|
---|
1513 |
|
---|
1514 | void VBoxDiskImageManagerDlg::refreshAll()
|
---|
1515 | {
|
---|
1516 | /* start enumerating media */
|
---|
1517 | vboxGlobal().startEnumeratingMedia();
|
---|
1518 | }
|
---|
1519 |
|
---|
1520 |
|
---|
1521 | bool VBoxDiskImageManagerDlg::checkImage (DiskImageItem* aItem)
|
---|
1522 | {
|
---|
1523 | QUuid itemId = aItem ? QUuid (aItem->getUuid()) : QUuid();
|
---|
1524 | if (itemId.isNull()) return false;
|
---|
1525 |
|
---|
1526 | QListView* parentList = aItem->listView();
|
---|
1527 | if (parentList == hdsView)
|
---|
1528 | {
|
---|
1529 | QUuid machineId = vbox.GetHardDisk (itemId).GetMachineId();
|
---|
1530 | if (machineId.isNull() ||
|
---|
1531 | vbox.GetMachine (machineId).GetState() != CEnums::PoweredOff &&
|
---|
1532 | vbox.GetMachine (machineId).GetState() != CEnums::Aborted)
|
---|
1533 | return false;
|
---|
1534 | }
|
---|
1535 | else if (parentList == cdsView)
|
---|
1536 | {
|
---|
1537 | QString usage = getDVDImageUsage (itemId);
|
---|
1538 | /* check if there is temporary usage: */
|
---|
1539 | QStringList tempMachines =
|
---|
1540 | QStringList::split (' ', vbox.GetDVDImageUsage (itemId,
|
---|
1541 | CEnums::TemporaryUsage));
|
---|
1542 | if (!tempMachines.isEmpty())
|
---|
1543 | return false;
|
---|
1544 | /* only permamently mounted .iso could be released */
|
---|
1545 | QStringList permMachines =
|
---|
1546 | QStringList::split (' ', vbox.GetDVDImageUsage (itemId,
|
---|
1547 | CEnums::PermanentUsage));
|
---|
1548 | for (QStringList::Iterator it = permMachines.begin();
|
---|
1549 | it != permMachines.end(); ++it)
|
---|
1550 | if (vbox.GetMachine(QUuid (*it)).GetState() != CEnums::PoweredOff &&
|
---|
1551 | vbox.GetMachine(QUuid (*it)).GetState() != CEnums::Aborted)
|
---|
1552 | return false;
|
---|
1553 | }
|
---|
1554 | else if (parentList == fdsView)
|
---|
1555 | {
|
---|
1556 | QString usage = getFloppyImageUsage(itemId);
|
---|
1557 | /* check if there is temporary usage: */
|
---|
1558 | QStringList tempMachines =
|
---|
1559 | QStringList::split (' ', vbox.GetFloppyImageUsage (itemId,
|
---|
1560 | CEnums::TemporaryUsage));
|
---|
1561 | if (!tempMachines.isEmpty())
|
---|
1562 | return false;
|
---|
1563 | /* only permamently mounted .iso could be released */
|
---|
1564 | QStringList permMachines =
|
---|
1565 | QStringList::split (' ', vbox.GetFloppyImageUsage (itemId,
|
---|
1566 | CEnums::PermanentUsage));
|
---|
1567 | for (QStringList::Iterator it = permMachines.begin();
|
---|
1568 | it != permMachines.end(); ++it)
|
---|
1569 | if (vbox.GetMachine(QUuid (*it)).GetState() != CEnums::PoweredOff &&
|
---|
1570 | vbox.GetMachine(QUuid (*it)).GetState() != CEnums::Aborted)
|
---|
1571 | return false;
|
---|
1572 | }
|
---|
1573 | else
|
---|
1574 | {
|
---|
1575 | return false;
|
---|
1576 | }
|
---|
1577 | return true;
|
---|
1578 | }
|
---|
1579 |
|
---|
1580 |
|
---|
1581 | void VBoxDiskImageManagerDlg::setCurrentItem (QListView *aListView,
|
---|
1582 | QListViewItem *aItem)
|
---|
1583 | {
|
---|
1584 | if (!aItem)
|
---|
1585 | return;
|
---|
1586 |
|
---|
1587 | aListView->setCurrentItem (aItem);
|
---|
1588 | aListView->setSelected (aListView->currentItem(), true);
|
---|
1589 | }
|
---|
1590 |
|
---|
1591 |
|
---|
1592 | void VBoxDiskImageManagerDlg::processCurrentChanged()
|
---|
1593 | {
|
---|
1594 | QListView *currentList = getCurrentListView();
|
---|
1595 | currentList->setFocus();
|
---|
1596 |
|
---|
1597 | /* tab stop setup */
|
---|
1598 | setTabOrder (hdsView, hdsPane1);
|
---|
1599 | setTabOrder (hdsPane1, hdsPane2);
|
---|
1600 | setTabOrder (hdsPane2, hdsPane3);
|
---|
1601 | setTabOrder (hdsPane3, hdsPane4);
|
---|
1602 | setTabOrder (hdsPane4, hdsPane5);
|
---|
1603 | setTabOrder (hdsPane5, buttonHelp);
|
---|
1604 |
|
---|
1605 | setTabOrder (cdsView, cdsPane1);
|
---|
1606 | setTabOrder (cdsPane1, cdsPane2);
|
---|
1607 | setTabOrder (cdsPane2, buttonHelp);
|
---|
1608 |
|
---|
1609 | setTabOrder (fdsView, fdsPane1);
|
---|
1610 | setTabOrder (fdsPane1, fdsPane2);
|
---|
1611 | setTabOrder (fdsPane2, buttonHelp);
|
---|
1612 |
|
---|
1613 | setTabOrder (buttonHelp, buttonOk);
|
---|
1614 | setTabOrder (buttonOk, twImages);
|
---|
1615 |
|
---|
1616 | processCurrentChanged (currentList->currentItem());
|
---|
1617 | }
|
---|
1618 |
|
---|
1619 | void VBoxDiskImageManagerDlg::processCurrentChanged (QListViewItem *aItem)
|
---|
1620 | {
|
---|
1621 | DiskImageItem *item = aItem && aItem->rtti() == 1001 ?
|
---|
1622 | static_cast<DiskImageItem*> (aItem) : 0;
|
---|
1623 |
|
---|
1624 | bool notInEnum = !vboxGlobal().isMediaEnumerationStarted();
|
---|
1625 | bool modifyEnabled = notInEnum &&
|
---|
1626 | item && item->getUsage().isNull() &&
|
---|
1627 | !item->firstChild() && !item->getPath().isNull();
|
---|
1628 | bool releaseEnabled = item && !item->getUsage().isNull() &&
|
---|
1629 | checkImage (item) &&
|
---|
1630 | !item->parent() && !item->firstChild() &&
|
---|
1631 | item->getSnapshotName().isNull();
|
---|
1632 | bool newEnabled = notInEnum &&
|
---|
1633 | getCurrentListView() == hdsView ? true : false;
|
---|
1634 | bool addEnabled = notInEnum;
|
---|
1635 |
|
---|
1636 | // imEditAction->setEnabled (modifyEnabled);
|
---|
1637 | imRemoveAction->setEnabled (modifyEnabled);
|
---|
1638 | imReleaseAction->setEnabled (releaseEnabled);
|
---|
1639 | imNewAction->setEnabled (newEnabled);
|
---|
1640 | imAddAction->setEnabled (addEnabled);
|
---|
1641 |
|
---|
1642 | // itemMenu->setItemVisible (itemMenu->idAt(0), modifyEnabled);
|
---|
1643 | itemMenu->setItemEnabled (itemMenu->idAt(0), modifyEnabled);
|
---|
1644 | itemMenu->setItemEnabled (itemMenu->idAt(1), releaseEnabled);
|
---|
1645 |
|
---|
1646 | if (doSelect)
|
---|
1647 | {
|
---|
1648 | bool selectEnabled = item && !item->parent() &&
|
---|
1649 | (!newEnabled ||
|
---|
1650 | (item->getUsage().isNull() ||
|
---|
1651 | item->getMachineId() == targetVMId));
|
---|
1652 |
|
---|
1653 | buttonOk->setEnabled (selectEnabled);
|
---|
1654 | }
|
---|
1655 |
|
---|
1656 | if (item)
|
---|
1657 | {
|
---|
1658 | if (item->listView() == hdsView)
|
---|
1659 | {
|
---|
1660 | hdsPane1->setText (item->getInformation (item->getPath(), true, "end"));
|
---|
1661 | hdsPane2->setText (item->getInformation (item->getDiskType(), false));
|
---|
1662 | hdsPane3->setText (item->getInformation (item->getStorageType(), false));
|
---|
1663 | hdsPane4->setText (item->getInformation (item->getUsage()));
|
---|
1664 | hdsPane5->setText (item->getInformation (item->getSnapshotName()));
|
---|
1665 | }
|
---|
1666 | else if (item->listView() == cdsView)
|
---|
1667 | {
|
---|
1668 | cdsPane1->setText (item->getInformation (item->getPath(), true, "end"));
|
---|
1669 | cdsPane2->setText (item->getInformation (item->getUsage()));
|
---|
1670 | }
|
---|
1671 | else if (item->listView() == fdsView)
|
---|
1672 | {
|
---|
1673 | fdsPane1->setText (item->getInformation (item->getPath(), true, "end"));
|
---|
1674 | fdsPane2->setText (item->getInformation (item->getUsage()));
|
---|
1675 | }
|
---|
1676 | }
|
---|
1677 | else
|
---|
1678 | clearInfoPanes();
|
---|
1679 | }
|
---|
1680 |
|
---|
1681 |
|
---|
1682 | void VBoxDiskImageManagerDlg::processPressed (QListViewItem * aItem)
|
---|
1683 | {
|
---|
1684 | if (!aItem)
|
---|
1685 | {
|
---|
1686 | QListView *currentList = getCurrentListView();
|
---|
1687 | currentList->setSelected (currentList->currentItem(), true);
|
---|
1688 | }
|
---|
1689 | }
|
---|
1690 |
|
---|
1691 |
|
---|
1692 | void VBoxDiskImageManagerDlg::newImage()
|
---|
1693 | {
|
---|
1694 | AssertReturnVoid (getCurrentListView() == hdsView);
|
---|
1695 |
|
---|
1696 | VBoxNewHDWzd dlg (this, "VBoxNewHDWzd");
|
---|
1697 |
|
---|
1698 | if (dlg.exec() == QDialog::Accepted)
|
---|
1699 | {
|
---|
1700 | CHardDisk hd = dlg.hardDisk();
|
---|
1701 | VBoxMedia::Status status =
|
---|
1702 | hd.GetAccessible() ? VBoxMedia::Ok :
|
---|
1703 | hd.isOk() ? VBoxMedia::Inaccessible :
|
---|
1704 | VBoxMedia::Error;
|
---|
1705 | vboxGlobal().addMedia (VBoxMedia (CUnknown (hd), VBoxDefs::HD, status));
|
---|
1706 | }
|
---|
1707 | }
|
---|
1708 |
|
---|
1709 |
|
---|
1710 | void VBoxDiskImageManagerDlg::addImage()
|
---|
1711 | {
|
---|
1712 | QListView *currentList = getCurrentListView();
|
---|
1713 | DiskImageItem *item =
|
---|
1714 | currentList->currentItem() && currentList->currentItem()->rtti() == 1001 ?
|
---|
1715 | static_cast<DiskImageItem*> (currentList->currentItem()) : 0;
|
---|
1716 |
|
---|
1717 | QString dir;
|
---|
1718 | if (item && item->getStatus() == VBoxMedia::Ok)
|
---|
1719 | dir = item->getPath().stripWhiteSpace();
|
---|
1720 |
|
---|
1721 | if (!dir)
|
---|
1722 | if (currentList == hdsView)
|
---|
1723 | dir = vbox.GetSystemProperties().GetDefaultVDIFolder();
|
---|
1724 | if (!dir || !QFileInfo (dir).exists())
|
---|
1725 | dir = vbox.GetHomeFolder();
|
---|
1726 |
|
---|
1727 | QString title;
|
---|
1728 | QString filter;
|
---|
1729 | VBoxDefs::DiskType type = VBoxDefs::InvalidType;
|
---|
1730 |
|
---|
1731 | if (currentList == hdsView) {
|
---|
1732 | filter = tr( "Hard disk images (*.vdi)" );
|
---|
1733 | title = tr( "Select a hard disk image file" );
|
---|
1734 | type = VBoxDefs::HD;
|
---|
1735 | } else if (currentList == cdsView) {
|
---|
1736 | filter = tr( "CDROM images (*.iso)" );
|
---|
1737 | title = tr( "Select a DVD/CD-ROM disk image file" );
|
---|
1738 | type = VBoxDefs::CD;
|
---|
1739 | } else if (currentList == fdsView) {
|
---|
1740 | filter = tr( "Floppy images (*.img)" );
|
---|
1741 | title = tr( "Select a floppy disk image file" );
|
---|
1742 | type = VBoxDefs::FD;
|
---|
1743 | } else {
|
---|
1744 | AssertMsgFailed (("Root list should be equal to hdsView, cdsView or fdsView"));
|
---|
1745 | }
|
---|
1746 |
|
---|
1747 | QString src = QFileDialog::getOpenFileName (dir, filter,
|
---|
1748 | this, "AddDiskImageDialog",
|
---|
1749 | title);
|
---|
1750 |
|
---|
1751 | addImageToList (src, type);
|
---|
1752 | if (!vbox.isOk())
|
---|
1753 | vboxProblem().cannotRegisterMedia (this, vbox, type, src);
|
---|
1754 | }
|
---|
1755 |
|
---|
1756 |
|
---|
1757 | void VBoxDiskImageManagerDlg::removeImage()
|
---|
1758 | {
|
---|
1759 | QListView *currentList = getCurrentListView();
|
---|
1760 | DiskImageItem *item =
|
---|
1761 | currentList->currentItem() && currentList->currentItem()->rtti() == 1001 ?
|
---|
1762 | static_cast<DiskImageItem*> (currentList->currentItem()) : 0;
|
---|
1763 | AssertMsg (item, ("Current item must not be null"));
|
---|
1764 |
|
---|
1765 | QString src = item->getPath().stripWhiteSpace();
|
---|
1766 | QUuid uuid = QUuid (item->getUuid());
|
---|
1767 | VBoxDefs::DiskType type = VBoxDefs::InvalidType;
|
---|
1768 |
|
---|
1769 | if (currentList == hdsView)
|
---|
1770 | {
|
---|
1771 | type = VBoxDefs::HD;
|
---|
1772 | int deleteImage;
|
---|
1773 | if (vbox.GetHardDisk (uuid).GetStorageType() == CEnums::VirtualDiskImage &&
|
---|
1774 | item->getStatus() == VBoxMedia::Ok)
|
---|
1775 | {
|
---|
1776 | deleteImage = vboxProblem().confirmHardDiskImageDeletion (this, src);
|
---|
1777 | }
|
---|
1778 | else
|
---|
1779 | {
|
---|
1780 | deleteImage = vboxProblem().confirmHardDiskUnregister (this, src);
|
---|
1781 | }
|
---|
1782 | if (deleteImage == QIMessageBox::Cancel)
|
---|
1783 | return;
|
---|
1784 | CHardDisk hd = vbox.UnregisterHardDisk (uuid);
|
---|
1785 | if (vbox.isOk() && deleteImage == QIMessageBox::Yes)
|
---|
1786 | {
|
---|
1787 | /// @todo (dmik) later, change wrappers so that converting
|
---|
1788 | // to CUnknown is not necessary for cross-assignments
|
---|
1789 | CVirtualDiskImage vdi = CUnknown (hd);
|
---|
1790 | if (vdi.isOk())
|
---|
1791 | vdi.DeleteImage();
|
---|
1792 | if (!vdi.isOk())
|
---|
1793 | vboxProblem().cannotDeleteHardDiskImage (this, vdi);
|
---|
1794 | }
|
---|
1795 | }
|
---|
1796 | else if (currentList == cdsView)
|
---|
1797 | {
|
---|
1798 | type = VBoxDefs::CD;
|
---|
1799 | vbox.UnregisterDVDImage (uuid);
|
---|
1800 | }
|
---|
1801 | else if (currentList == fdsView)
|
---|
1802 | {
|
---|
1803 | type = VBoxDefs::FD;
|
---|
1804 | vbox.UnregisterFloppyImage (uuid);
|
---|
1805 | }
|
---|
1806 |
|
---|
1807 | if (vbox.isOk())
|
---|
1808 | vboxGlobal().removeMedia (type, uuid);
|
---|
1809 | else
|
---|
1810 | vboxProblem().cannotUnregisterMedia (this, vbox, type, src);
|
---|
1811 | }
|
---|
1812 |
|
---|
1813 |
|
---|
1814 | void VBoxDiskImageManagerDlg::releaseImage()
|
---|
1815 | {
|
---|
1816 | QListView *currentList = getCurrentListView();
|
---|
1817 | DiskImageItem *item =
|
---|
1818 | currentList->currentItem() && currentList->currentItem()->rtti() == 1001 ?
|
---|
1819 | static_cast<DiskImageItem*> (currentList->currentItem()) : 0;
|
---|
1820 | AssertMsg (item, ("Current item must not be null"));
|
---|
1821 |
|
---|
1822 | QUuid itemId = QUuid (item->getUuid());
|
---|
1823 | AssertMsg (!itemId.isNull(), ("Current item must have uuid"));
|
---|
1824 |
|
---|
1825 | VBoxMedia media;
|
---|
1826 | QUuid machineId;
|
---|
1827 | /* if it is a hard disk sub-item: */
|
---|
1828 | if (currentList == hdsView)
|
---|
1829 | {
|
---|
1830 | machineId = vbox.GetHardDisk (itemId).GetMachineId();
|
---|
1831 | if (vboxProblem().confirmReleaseImage (this,
|
---|
1832 | vbox.GetMachine(machineId).GetName()))
|
---|
1833 | {
|
---|
1834 | releaseDisk (machineId, itemId, VBoxDefs::HD);
|
---|
1835 | CHardDisk hd = vboxGlobal().virtualBox().GetHardDisk (itemId);
|
---|
1836 | media = VBoxMedia (CUnknown (hd), VBoxDefs::HD, item->getStatus());
|
---|
1837 | }
|
---|
1838 | }
|
---|
1839 | /* if it is a cd/dvd sub-item: */
|
---|
1840 | else if (currentList == cdsView)
|
---|
1841 | {
|
---|
1842 | QString usage = getDVDImageUsage (itemId);
|
---|
1843 | /* only permamently mounted .iso could be released */
|
---|
1844 | if (vboxProblem().confirmReleaseImage (this, usage))
|
---|
1845 | {
|
---|
1846 | QStringList permMachines =
|
---|
1847 | QStringList::split (' ', vbox.GetDVDImageUsage (itemId,
|
---|
1848 | CEnums::PermanentUsage));
|
---|
1849 | for (QStringList::Iterator it = permMachines.begin();
|
---|
1850 | it != permMachines.end(); ++it)
|
---|
1851 | releaseDisk (QUuid (*it), itemId, VBoxDefs::CD);
|
---|
1852 |
|
---|
1853 | CDVDImage cd = vboxGlobal().virtualBox().GetDVDImage (itemId);
|
---|
1854 | media = VBoxMedia (CUnknown (cd), VBoxDefs::CD, item->getStatus());
|
---|
1855 | }
|
---|
1856 | }
|
---|
1857 | /* if it is a floppy sub-item: */
|
---|
1858 | else if (currentList == fdsView)
|
---|
1859 | {
|
---|
1860 | QString usage = getFloppyImageUsage (itemId);
|
---|
1861 | /* only permamently mounted .img could be released */
|
---|
1862 | if (vboxProblem().confirmReleaseImage (this, usage))
|
---|
1863 | {
|
---|
1864 | QStringList permMachines =
|
---|
1865 | QStringList::split (' ', vbox.GetFloppyImageUsage (itemId,
|
---|
1866 | CEnums::PermanentUsage));
|
---|
1867 | for (QStringList::Iterator it = permMachines.begin();
|
---|
1868 | it != permMachines.end(); ++it)
|
---|
1869 | releaseDisk (QUuid (*it), itemId, VBoxDefs::FD);
|
---|
1870 |
|
---|
1871 | CFloppyImage fd = vboxGlobal().virtualBox().GetFloppyImage (itemId);
|
---|
1872 | media = VBoxMedia (CUnknown (fd), VBoxDefs::FD, item->getStatus());
|
---|
1873 | }
|
---|
1874 | }
|
---|
1875 | if (media.type != VBoxDefs::InvalidType)
|
---|
1876 | vboxGlobal().updateMedia (media);
|
---|
1877 | }
|
---|
1878 |
|
---|
1879 |
|
---|
1880 | void VBoxDiskImageManagerDlg::releaseDisk (QUuid aMachineId,
|
---|
1881 | QUuid aItemId,
|
---|
1882 | VBoxDefs::DiskType aDiskType)
|
---|
1883 | {
|
---|
1884 | CSession session;
|
---|
1885 | CMachine machine;
|
---|
1886 | /* is this media image mapped to this VM: */
|
---|
1887 | if (!cmachine.isNull() && cmachine.GetId() == aMachineId)
|
---|
1888 | {
|
---|
1889 | machine = cmachine;
|
---|
1890 | }
|
---|
1891 | /* or some other: */
|
---|
1892 | else
|
---|
1893 | {
|
---|
1894 | session = vboxGlobal().openSession (aMachineId);
|
---|
1895 | if (session.isNull()) return;
|
---|
1896 | machine = session.GetMachine();
|
---|
1897 | }
|
---|
1898 | /* perform disk releasing: */
|
---|
1899 | switch (aDiskType)
|
---|
1900 | {
|
---|
1901 | case VBoxDefs::HD:
|
---|
1902 | {
|
---|
1903 | /* releasing hd: */
|
---|
1904 | CHardDiskAttachmentEnumerator en =
|
---|
1905 | machine.GetHardDiskAttachments().Enumerate();
|
---|
1906 | while (en.HasMore())
|
---|
1907 | {
|
---|
1908 | CHardDiskAttachment hda = en.GetNext();
|
---|
1909 | if (hda.GetHardDisk().GetId() == aItemId)
|
---|
1910 | {
|
---|
1911 | machine.DetachHardDisk (hda.GetController(),
|
---|
1912 | hda.GetDeviceNumber());
|
---|
1913 | if (!machine.isOk())
|
---|
1914 | vboxProblem().cannotDetachHardDisk (this,
|
---|
1915 | machine, hda.GetController(), hda.GetDeviceNumber());
|
---|
1916 | break;
|
---|
1917 | }
|
---|
1918 | }
|
---|
1919 | break;
|
---|
1920 | }
|
---|
1921 | case VBoxDefs::CD:
|
---|
1922 | {
|
---|
1923 | /* releasing cd: */
|
---|
1924 | machine.GetDVDDrive().Unmount();
|
---|
1925 | break;
|
---|
1926 | }
|
---|
1927 | case VBoxDefs::FD:
|
---|
1928 | {
|
---|
1929 | /* releasing fd: */
|
---|
1930 | machine.GetFloppyDrive().Unmount();
|
---|
1931 | break;
|
---|
1932 | }
|
---|
1933 | default:
|
---|
1934 | AssertFailed();
|
---|
1935 | }
|
---|
1936 | /* save all setting changes: */
|
---|
1937 | machine.SaveSettings();
|
---|
1938 | if (!machine.isOk())
|
---|
1939 | vboxProblem().cannotSaveMachineSettings (machine);
|
---|
1940 | /* if local session was opened - close this session: */
|
---|
1941 | if (!session.isNull())
|
---|
1942 | session.Close();
|
---|
1943 | }
|
---|
1944 |
|
---|
1945 |
|
---|
1946 | QUuid VBoxDiskImageManagerDlg::getSelectedUuid()
|
---|
1947 | {
|
---|
1948 | QListView *currentList = getCurrentListView();
|
---|
1949 | QUuid uuid;
|
---|
1950 |
|
---|
1951 | if ( currentList->selectedItem() &&
|
---|
1952 | currentList->selectedItem()->rtti() == 1001 )
|
---|
1953 | uuid = QUuid (static_cast<DiskImageItem *>(currentList->selectedItem())
|
---|
1954 | ->getUuid());
|
---|
1955 |
|
---|
1956 | return uuid;
|
---|
1957 | }
|
---|
1958 |
|
---|
1959 |
|
---|
1960 | QString VBoxDiskImageManagerDlg::getSelectedPath()
|
---|
1961 | {
|
---|
1962 | QListView *currentList = getCurrentListView();
|
---|
1963 | QString path;
|
---|
1964 |
|
---|
1965 | if ( currentList->selectedItem() && currentList->selectedItem()->rtti() == 1001 )
|
---|
1966 | path = static_cast<DiskImageItem*> (currentList->selectedItem())
|
---|
1967 | ->getPath().stripWhiteSpace();
|
---|
1968 |
|
---|
1969 | return path;
|
---|
1970 | }
|
---|
1971 |
|
---|
1972 |
|
---|
1973 | void VBoxDiskImageManagerDlg::processDoubleClick (QListViewItem*)
|
---|
1974 | {
|
---|
1975 | QListView *currentList = getCurrentListView();
|
---|
1976 |
|
---|
1977 | if (doSelect && currentList->selectedItem() && buttonOk->isEnabled())
|
---|
1978 | accept();
|
---|
1979 | }
|
---|