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