1 | /* $Id: UIMediumSelector.cpp 72431 2018-06-04 13:18:42Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIMediumSelector class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2017 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifdef VBOX_WITH_PRECOMPILED_HEADERS
|
---|
19 | # include <precomp.h>
|
---|
20 | #else /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
21 |
|
---|
22 | /* Qt includes: */
|
---|
23 | # include <QAction>
|
---|
24 | # include <QHeaderView>
|
---|
25 | # include <QVBoxLayout>
|
---|
26 | # include <QPushButton>
|
---|
27 |
|
---|
28 | /* GUI includes: */
|
---|
29 | # include "QIDialogButtonBox.h"
|
---|
30 | # include "QIMessageBox.h"
|
---|
31 | # include "QITabWidget.h"
|
---|
32 | # include "VBoxGlobal.h"
|
---|
33 | # include "UIDesktopWidgetWatchdog.h"
|
---|
34 | # include "UIExtraDataManager.h"
|
---|
35 | # include "UIMediumSelector.h"
|
---|
36 | # include "UIIconPool.h"
|
---|
37 | # include "UIMedium.h"
|
---|
38 | # include "UIMediumItem.h"
|
---|
39 | # include "UIToolBar.h"
|
---|
40 |
|
---|
41 | /* COM includes: */
|
---|
42 | # include "COMEnums.h"
|
---|
43 | # include "CMachine.h"
|
---|
44 | # include "CMediumAttachment.h"
|
---|
45 | # include "CMediumFormat.h"
|
---|
46 | # include "CStorageController.h"
|
---|
47 | # include "CSystemProperties.h"
|
---|
48 |
|
---|
49 | # ifdef VBOX_WS_MAC
|
---|
50 | # include "UIWindowMenuManager.h"
|
---|
51 | # endif /* VBOX_WS_MAC */
|
---|
52 |
|
---|
53 | #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
54 |
|
---|
55 |
|
---|
56 | UIMediumSelector::UIMediumSelector(UIMediumType enmMediumType, QWidget *pParent /* = 0 */)
|
---|
57 | :QIWithRetranslateUI<QIDialog>(pParent)
|
---|
58 | , m_pMainLayout(0)
|
---|
59 | , m_pTreeWidget(0)
|
---|
60 | , m_enmMediumType(enmMediumType)
|
---|
61 | , m_pButtonBox(0)
|
---|
62 | , m_pToolBar(0)
|
---|
63 | , m_pActionAdd(0)
|
---|
64 | , m_pActionRefresh(0)
|
---|
65 | , m_pAttachedSubTreeRoot(0)
|
---|
66 | , m_pNotAttachedSubTreeRoot(0)
|
---|
67 | , m_pParent(pParent)
|
---|
68 | {
|
---|
69 | configure();
|
---|
70 | finalize();
|
---|
71 | //setAttribute(Qt::WA_DeleteOnClose);
|
---|
72 | }
|
---|
73 |
|
---|
74 | QStringList UIMediumSelector::selectedMediumIds() const
|
---|
75 | {
|
---|
76 | QStringList selectedIds;
|
---|
77 | if (!m_pTreeWidget)
|
---|
78 | return selectedIds;
|
---|
79 | QList<QTreeWidgetItem*> selectedItems = m_pTreeWidget->selectedItems();
|
---|
80 | for (int i = 0; i < selectedItems.size(); ++i)
|
---|
81 | {
|
---|
82 | UIMediumItem *item = dynamic_cast<UIMediumItem*>(selectedItems.at(i));
|
---|
83 | if (item)
|
---|
84 | selectedIds.push_back(item->medium().id());
|
---|
85 | }
|
---|
86 | return selectedIds;
|
---|
87 | }
|
---|
88 |
|
---|
89 |
|
---|
90 | void UIMediumSelector::retranslateUi()
|
---|
91 | {
|
---|
92 | if (m_pActionAdd)
|
---|
93 | {
|
---|
94 | m_pActionAdd->setText(QApplication::translate("UIMediumManager", "&Add"));
|
---|
95 | m_pActionAdd->setToolTip(QApplication::translate("UIMediumManager", "Add Disk Image File"));
|
---|
96 | m_pActionAdd->setStatusTip(QApplication::translate("UIMediumManager", "Add disk image file"));
|
---|
97 | }
|
---|
98 | if (m_pActionRefresh)
|
---|
99 | {
|
---|
100 | m_pActionRefresh->setText(QApplication::translate("UIMediumManager","Re&fresh"));
|
---|
101 | m_pActionRefresh->setToolTip(QApplication::translate("UIMediumManager","Refresh Disk Image Files (%1)").arg(m_pActionRefresh->shortcut().toString()));
|
---|
102 | m_pActionRefresh->setStatusTip(QApplication::translate("UIMediumManager","Refresh the list of disk image files"));
|
---|
103 | }
|
---|
104 |
|
---|
105 | if (m_pButtonBox)
|
---|
106 | m_pButtonBox->button(QDialogButtonBox::Ok)->setText("Choose");
|
---|
107 |
|
---|
108 | if (m_pTreeWidget)
|
---|
109 | {
|
---|
110 | m_pTreeWidget->headerItem()->setText(0, QApplication::translate("UIMediumManager","Name"));
|
---|
111 | m_pTreeWidget->headerItem()->setText(1, QApplication::translate("UIMediumManager","Virtual Size"));
|
---|
112 | m_pTreeWidget->headerItem()->setText(2, QApplication::translate("UIMediumManager","Actual Size"));
|
---|
113 | }
|
---|
114 | }
|
---|
115 |
|
---|
116 | void UIMediumSelector::configure()
|
---|
117 | {
|
---|
118 | /* Apply window icons: */
|
---|
119 | setWindowIcon(UIIconPool::iconSetFull(":/diskimage_32px.png", ":/diskimage_16px.png"));
|
---|
120 | prepareActions();
|
---|
121 | prepareWidgets();
|
---|
122 | prepareConnections();
|
---|
123 |
|
---|
124 | }
|
---|
125 |
|
---|
126 | void UIMediumSelector::prepareActions()
|
---|
127 | {
|
---|
128 | m_pActionAdd = new QAction(this);
|
---|
129 | if (m_pActionAdd)
|
---|
130 | {
|
---|
131 | /* Configure add-action: */
|
---|
132 | m_pActionAdd->setShortcut(QKeySequence("Ctrl+A"));
|
---|
133 | QString strPrefix("hd");
|
---|
134 | switch (m_enmMediumType)
|
---|
135 | {
|
---|
136 | case UIMediumType_DVD:
|
---|
137 | strPrefix = "cd";
|
---|
138 | break;
|
---|
139 | case UIMediumType_Floppy:
|
---|
140 | strPrefix = "fd";
|
---|
141 | break;
|
---|
142 | case UIMediumType_HardDisk:
|
---|
143 | case UIMediumType_All:
|
---|
144 | case UIMediumType_Invalid:
|
---|
145 | default:
|
---|
146 | strPrefix = "hd";
|
---|
147 | break;
|
---|
148 | }
|
---|
149 |
|
---|
150 | m_pActionAdd->setIcon(UIIconPool::iconSetFull(QString(":/%1_add_22px.png").arg(strPrefix),
|
---|
151 | QString(":/%1_add_16px.png").arg(strPrefix),
|
---|
152 | QString(":/%1_add_disabled_22px.png").arg(strPrefix),
|
---|
153 | QString(":/%1_add_disabled_16px.png").arg(strPrefix)));
|
---|
154 | }
|
---|
155 |
|
---|
156 | m_pActionRefresh = new QAction(this);
|
---|
157 | if (m_pActionRefresh)
|
---|
158 | {
|
---|
159 | m_pActionRefresh->setShortcut(QKeySequence(QKeySequence::Refresh));
|
---|
160 | if (m_pActionRefresh && m_pActionRefresh->icon().isNull())
|
---|
161 | m_pActionRefresh->setIcon(UIIconPool::iconSetFull(":/refresh_22px.png", ":/refresh_16px.png",
|
---|
162 | ":/refresh_disabled_22px.png", ":/refresh_disabled_16px.png"));
|
---|
163 | }
|
---|
164 | }
|
---|
165 |
|
---|
166 | void UIMediumSelector::prepareConnections()
|
---|
167 | {
|
---|
168 | /* Configure medium-enumeration connections: */
|
---|
169 | connect(&vboxGlobal(), &VBoxGlobal::sigMediumEnumerationStarted,
|
---|
170 | this, &UIMediumSelector::sltHandleMediumEnumerationStart);
|
---|
171 | connect(&vboxGlobal(), &VBoxGlobal::sigMediumEnumerated,
|
---|
172 | this, &UIMediumSelector::sltHandleMediumEnumerated);
|
---|
173 | connect(&vboxGlobal(), &VBoxGlobal::sigMediumEnumerationFinished,
|
---|
174 | this, &UIMediumSelector::sltHandleMediumEnumerationFinish);
|
---|
175 | if (m_pActionAdd)
|
---|
176 | connect(m_pActionAdd, &QAction::triggered, this, &UIMediumSelector::sltAddMedium);
|
---|
177 | if (m_pActionRefresh)
|
---|
178 | connect(m_pActionRefresh, &QAction::triggered, this, &UIMediumSelector::sltHandleRefresh);
|
---|
179 |
|
---|
180 | if (m_pTreeWidget)
|
---|
181 | connect(m_pTreeWidget, &QITreeWidget::itemSelectionChanged, this, &UIMediumSelector::sltHandleItemSelectionChanged);
|
---|
182 |
|
---|
183 | if (m_pButtonBox)
|
---|
184 | {
|
---|
185 | connect(m_pButtonBox, &QIDialogButtonBox::rejected, this, &UIMediumSelector::close);
|
---|
186 | connect(m_pButtonBox, &QIDialogButtonBox::accepted, this, &UIMediumSelector::accept);
|
---|
187 | }
|
---|
188 | }
|
---|
189 |
|
---|
190 | UIMediumItem* UIMediumSelector::addTreeItem(const UIMedium &medium, QITreeWidgetItem *pParent)
|
---|
191 | {
|
---|
192 | if (!pParent)
|
---|
193 | return 0;
|
---|
194 | switch (m_enmMediumType)
|
---|
195 | {
|
---|
196 | case UIMediumType_DVD:
|
---|
197 | return new UIMediumItemCD(medium, pParent);
|
---|
198 | break;
|
---|
199 | case UIMediumType_Floppy:
|
---|
200 | return new UIMediumItemFD(medium, pParent);
|
---|
201 | break;
|
---|
202 | case UIMediumType_HardDisk:
|
---|
203 | case UIMediumType_All:
|
---|
204 | case UIMediumType_Invalid:
|
---|
205 | default:
|
---|
206 | return createHardDiskItem(medium, pParent);
|
---|
207 | break;
|
---|
208 | }
|
---|
209 | }
|
---|
210 |
|
---|
211 | UIMediumItem* UIMediumSelector::createHardDiskItem(const UIMedium &medium, QITreeWidgetItem *pParent)
|
---|
212 | {
|
---|
213 | if (medium.medium().isNull())
|
---|
214 | return 0;
|
---|
215 | if (!m_pTreeWidget)
|
---|
216 | return 0;
|
---|
217 | /* Search the tree to see if we already have the item: */
|
---|
218 | UIMediumItem *pMediumItem = searchItem(0, medium.id());
|
---|
219 | if (pMediumItem)
|
---|
220 | return pMediumItem;
|
---|
221 | /* Check if the corresponding medium has a parent */
|
---|
222 | if (medium.parentID() != UIMedium::nullID())
|
---|
223 | {
|
---|
224 | UIMediumItem *pParentMediumItem = searchItem(0, medium.parentID());
|
---|
225 | /* If parent medium-item was not found we create it: */
|
---|
226 | if (!pParentMediumItem)
|
---|
227 | {
|
---|
228 | /* Make sure corresponding parent medium is already cached! */
|
---|
229 | UIMedium parentMedium = vboxGlobal().medium(medium.parentID());
|
---|
230 | if (parentMedium.isNull())
|
---|
231 | AssertMsgFailed(("Parent medium with ID={%s} was not found!\n", medium.parentID().toUtf8().constData()));
|
---|
232 | /* Try to create parent medium-item: */
|
---|
233 | else
|
---|
234 | pParentMediumItem = createHardDiskItem(parentMedium, pParent);
|
---|
235 | /* If parent medium-item was found: */
|
---|
236 | if (pParentMediumItem)
|
---|
237 | {
|
---|
238 | pMediumItem = new UIMediumItemHD(medium, pParentMediumItem);
|
---|
239 | LogRel2(("UIMediumManager: Child hard-disk medium-item with ID={%s} created.\n", medium.id().toUtf8().constData()));
|
---|
240 | }
|
---|
241 | else
|
---|
242 | AssertMsgFailed(("Parent medium with ID={%s} could not be created!\n", medium.parentID().toUtf8().constData()));
|
---|
243 |
|
---|
244 | }
|
---|
245 | }
|
---|
246 | /* Else just create item as top-level one: */
|
---|
247 | else
|
---|
248 | {
|
---|
249 | pMediumItem = new UIMediumItemHD(medium, pParent);
|
---|
250 | LogRel2(("UIMediumManager: Root hard-disk medium-item with ID={%s} created.\n", medium.id().toUtf8().constData()));
|
---|
251 | }
|
---|
252 | return pMediumItem;
|
---|
253 | }
|
---|
254 |
|
---|
255 | void UIMediumSelector::restoreSelection(const QStringList &selectedMediums, QVector<UIMediumItem*> &mediumList)
|
---|
256 | {
|
---|
257 | if (!m_pTreeWidget)
|
---|
258 | return;
|
---|
259 | if (selectedMediums.isEmpty())
|
---|
260 | {
|
---|
261 | m_pTreeWidget->setCurrentItem(0);
|
---|
262 | return;
|
---|
263 | }
|
---|
264 | bool selected = false;
|
---|
265 | for (int i = 0; i < mediumList.size(); ++i)
|
---|
266 | {
|
---|
267 | if (!mediumList[i])
|
---|
268 | continue;
|
---|
269 | if (selectedMediums.contains(mediumList[i]->medium().id()))
|
---|
270 | {
|
---|
271 | mediumList[i]->setSelected(true);
|
---|
272 | selected = true;
|
---|
273 | }
|
---|
274 | }
|
---|
275 |
|
---|
276 | if (!selected)
|
---|
277 | m_pTreeWidget->setCurrentItem(0);
|
---|
278 | return;
|
---|
279 | }
|
---|
280 |
|
---|
281 | void UIMediumSelector::prepareWidgets()
|
---|
282 | {
|
---|
283 | m_pMainLayout = new QVBoxLayout;
|
---|
284 | if (!m_pMainLayout)
|
---|
285 | return;
|
---|
286 |
|
---|
287 | setLayout(m_pMainLayout);
|
---|
288 |
|
---|
289 | m_pToolBar = new UIToolBar(parentWidget());
|
---|
290 | if (m_pToolBar)
|
---|
291 | {
|
---|
292 | /* Configure toolbar: */
|
---|
293 | const int iIconMetric = (int)(QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) * 1.375);
|
---|
294 | m_pToolBar->setIconSize(QSize(iIconMetric, iIconMetric));
|
---|
295 | m_pToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
---|
296 | /* Add toolbar actions: */
|
---|
297 | if (m_pActionAdd)
|
---|
298 | m_pToolBar->addAction(m_pActionAdd);
|
---|
299 | if (m_pActionRefresh)
|
---|
300 | m_pToolBar->addAction(m_pActionRefresh);
|
---|
301 |
|
---|
302 | m_pMainLayout->addWidget(m_pToolBar);
|
---|
303 | }
|
---|
304 |
|
---|
305 | m_pTreeWidget = new QITreeWidget;
|
---|
306 | if (m_pTreeWidget)
|
---|
307 | {
|
---|
308 | m_pTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
|
---|
309 | m_pMainLayout->addWidget(m_pTreeWidget);
|
---|
310 |
|
---|
311 | m_pTreeWidget->setAlternatingRowColors(true);
|
---|
312 |
|
---|
313 | }
|
---|
314 |
|
---|
315 | m_pButtonBox = new QIDialogButtonBox;
|
---|
316 | if (m_pButtonBox)
|
---|
317 | {
|
---|
318 | /* Configure button-box: */
|
---|
319 | m_pButtonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
|
---|
320 | m_pButtonBox->button(QDialogButtonBox::Cancel)->setShortcut(Qt::Key_Escape);
|
---|
321 |
|
---|
322 | /* Add button-box into main layout: */
|
---|
323 | m_pMainLayout->addWidget(m_pButtonBox);
|
---|
324 | }
|
---|
325 |
|
---|
326 | repopulateTreeWidget();
|
---|
327 | //m_pMainLayout->addWidget(
|
---|
328 | }
|
---|
329 |
|
---|
330 | void UIMediumSelector::sltAddMedium()
|
---|
331 | {
|
---|
332 | QString strDefaultMachineFolder = vboxGlobal().virtualBox().GetSystemProperties().GetDefaultMachineFolder();
|
---|
333 | vboxGlobal().openMediumWithFileOpenDialog(m_enmMediumType, this, strDefaultMachineFolder);
|
---|
334 | }
|
---|
335 |
|
---|
336 | // void UIMediumSelector::sltHandleCurrentItemChanged()
|
---|
337 | // {
|
---|
338 | // printf("%d\n", m_pTreeWidget->selectedItems().size());
|
---|
339 | // updateOkButton();
|
---|
340 |
|
---|
341 | // }
|
---|
342 |
|
---|
343 | void UIMediumSelector::sltHandleItemSelectionChanged()
|
---|
344 | {
|
---|
345 | updateOkButton();
|
---|
346 | }
|
---|
347 |
|
---|
348 | void UIMediumSelector::sltHandleMediumEnumerationStart()
|
---|
349 | {
|
---|
350 | /* Disable controls. Left Alone button box 'Ok' button. it is handle by tree population: */
|
---|
351 | if (m_pActionRefresh)
|
---|
352 | m_pActionRefresh->setEnabled(false);
|
---|
353 | }
|
---|
354 |
|
---|
355 | void UIMediumSelector::sltHandleMediumEnumerated()
|
---|
356 | {
|
---|
357 | }
|
---|
358 |
|
---|
359 | void UIMediumSelector::sltHandleMediumEnumerationFinish()
|
---|
360 | {
|
---|
361 | repopulateTreeWidget();
|
---|
362 | if (m_pActionRefresh)
|
---|
363 | m_pActionRefresh->setEnabled(true);
|
---|
364 | }
|
---|
365 |
|
---|
366 | void UIMediumSelector::sltHandleRefresh()
|
---|
367 | {
|
---|
368 | /* Initialize media enumation: */
|
---|
369 | vboxGlobal().startMediumEnumeration();
|
---|
370 | }
|
---|
371 |
|
---|
372 | void UIMediumSelector::updateOkButton()
|
---|
373 | {
|
---|
374 |
|
---|
375 | if (!m_pTreeWidget || !m_pButtonBox || !m_pButtonBox->button(QDialogButtonBox::Ok))
|
---|
376 | return;
|
---|
377 | QList<QTreeWidgetItem*> selectedItems = m_pTreeWidget->selectedItems();
|
---|
378 | if (selectedItems.isEmpty())
|
---|
379 | {
|
---|
380 | m_pButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
---|
381 | return;
|
---|
382 | }
|
---|
383 |
|
---|
384 | /* check if at least one of the selected items is a UIMediumItem */
|
---|
385 | bool mediumItemSelected = false;
|
---|
386 | for (int i = 0; i < selectedItems.size() && !mediumItemSelected; ++i)
|
---|
387 | {
|
---|
388 | if (dynamic_cast<UIMediumItem*>(selectedItems.at(i)))
|
---|
389 | mediumItemSelected = true;
|
---|
390 | }
|
---|
391 | if (mediumItemSelected)
|
---|
392 | m_pButtonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
|
---|
393 | else
|
---|
394 | m_pButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
---|
395 | }
|
---|
396 |
|
---|
397 | void UIMediumSelector::finalize()
|
---|
398 | {
|
---|
399 | /* Apply language settings: */
|
---|
400 | retranslateUi();
|
---|
401 | }
|
---|
402 |
|
---|
403 | void UIMediumSelector::showEvent(QShowEvent *pEvent)
|
---|
404 | {
|
---|
405 | Q_UNUSED(pEvent);
|
---|
406 |
|
---|
407 | /* Try to determine the initial size: */
|
---|
408 | QSize proposedSize;
|
---|
409 | int iHostScreen = 0;
|
---|
410 | if (m_pParent)
|
---|
411 | iHostScreen = gpDesktop->screenNumber(m_pParent);
|
---|
412 | else
|
---|
413 | iHostScreen = gpDesktop->screenNumber(this);
|
---|
414 | if (iHostScreen >= 0 && iHostScreen < gpDesktop->screenCount())
|
---|
415 | {
|
---|
416 | /* On the basis of current host-screen geometry if possible: */
|
---|
417 | const QRect screenGeometry = gpDesktop->screenGeometry(iHostScreen);
|
---|
418 | if (screenGeometry.isValid())
|
---|
419 | proposedSize = screenGeometry.size() * 5 / 15;
|
---|
420 | }
|
---|
421 | /* Fallback to default size if we failed: */
|
---|
422 | if (proposedSize.isNull())
|
---|
423 | proposedSize = QSize(800, 600);
|
---|
424 | /* Resize to initial size: */
|
---|
425 | resize(proposedSize);
|
---|
426 |
|
---|
427 | if (m_pParent)
|
---|
428 | VBoxGlobal::centerWidget(this, m_pParent, false);
|
---|
429 |
|
---|
430 | }
|
---|
431 |
|
---|
432 | void UIMediumSelector::repopulateTreeWidget()
|
---|
433 | {
|
---|
434 | if (!m_pTreeWidget)
|
---|
435 | return;
|
---|
436 |
|
---|
437 | /* Cache the currently selected items: */
|
---|
438 | QList<QTreeWidgetItem*> selectedItems = m_pTreeWidget->selectedItems();
|
---|
439 | QStringList selectedMediums = selectedMediumIds();
|
---|
440 | /* uuid list of selected items: */
|
---|
441 | /* Reset the related data structure: */
|
---|
442 | m_pTreeWidget->clear();
|
---|
443 | m_pAttachedSubTreeRoot = 0;
|
---|
444 | m_pNotAttachedSubTreeRoot = 0;
|
---|
445 | QVector<UIMediumItem*> menuItemVector;
|
---|
446 |
|
---|
447 | foreach (const QString &strMediumID, vboxGlobal().mediumIDs())
|
---|
448 | {
|
---|
449 | UIMedium medium = vboxGlobal().medium(strMediumID);
|
---|
450 |
|
---|
451 | if (medium.type() == m_enmMediumType)
|
---|
452 | {
|
---|
453 | bool isMediumAttached = !(medium.medium().GetMachineIds().isEmpty());
|
---|
454 | QITreeWidgetItem *pParent = 0;
|
---|
455 | if (isMediumAttached)
|
---|
456 | {
|
---|
457 | if (!m_pAttachedSubTreeRoot)
|
---|
458 | {
|
---|
459 | QStringList strList;
|
---|
460 | strList << "Attached";
|
---|
461 | m_pAttachedSubTreeRoot = new QITreeWidgetItem(m_pTreeWidget, strList);
|
---|
462 | }
|
---|
463 | pParent = m_pAttachedSubTreeRoot;
|
---|
464 |
|
---|
465 | }
|
---|
466 | else
|
---|
467 | {
|
---|
468 | if (!m_pNotAttachedSubTreeRoot)
|
---|
469 | {
|
---|
470 | QStringList strList;
|
---|
471 | strList << "Not Attached";
|
---|
472 | m_pNotAttachedSubTreeRoot = new QITreeWidgetItem(m_pTreeWidget, strList);
|
---|
473 | }
|
---|
474 | pParent = m_pNotAttachedSubTreeRoot;
|
---|
475 | }
|
---|
476 | menuItemVector.push_back(addTreeItem(medium, pParent));
|
---|
477 | }
|
---|
478 | }
|
---|
479 | restoreSelection(selectedMediums, menuItemVector);
|
---|
480 |
|
---|
481 | updateOkButton();
|
---|
482 | if (m_pAttachedSubTreeRoot)
|
---|
483 | m_pTreeWidget->expandItem(m_pAttachedSubTreeRoot);
|
---|
484 |
|
---|
485 | if (m_pNotAttachedSubTreeRoot)
|
---|
486 | m_pTreeWidget->expandItem(m_pNotAttachedSubTreeRoot);
|
---|
487 |
|
---|
488 | }
|
---|
489 |
|
---|
490 | UIMediumItem* UIMediumSelector::searchItem(const QTreeWidgetItem *pParent, const QString &mediumId)
|
---|
491 | {
|
---|
492 | if (!m_pTreeWidget)
|
---|
493 | return 0;
|
---|
494 | if (!pParent)
|
---|
495 | {
|
---|
496 | pParent = m_pTreeWidget->invisibleRootItem();
|
---|
497 | }
|
---|
498 | if (!pParent)
|
---|
499 | return 0;
|
---|
500 |
|
---|
501 | for (int i = 0; i < pParent->childCount(); ++i)
|
---|
502 | {
|
---|
503 | QTreeWidgetItem *pChild = pParent->child(i);
|
---|
504 | if (!pChild)
|
---|
505 | continue;
|
---|
506 | UIMediumItem *mediumItem = dynamic_cast<UIMediumItem*>(pChild);
|
---|
507 | if (mediumItem)
|
---|
508 | {
|
---|
509 | if (mediumItem->id() == mediumId)
|
---|
510 | return mediumItem;
|
---|
511 | }
|
---|
512 | searchItem(pChild, mediumId);
|
---|
513 | }
|
---|
514 | return 0;
|
---|
515 | }
|
---|