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