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