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