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