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