VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumEnumerator.cpp

Last change on this file was 104226, checked in by vboxsync, 6 weeks ago

FE/Qt. bugref:10622. Using new UITranslationEventListener in medium manager related classes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 25.5 KB
Line 
1/* $Id: UIMediumEnumerator.cpp 104226 2024-04-08 12:07:43Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIMediumEnumerator class implementation.
4 */
5
6/*
7 * Copyright (C) 2013-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28/* Qt includes: */
29#include <QSet>
30
31/* GUI includes: */
32#include "UICommon.h"
33#include "UIErrorString.h"
34#include "UIGlobalSession.h"
35#include "UILoggingDefs.h"
36#include "UIMediumEnumerator.h"
37#include "UINotificationCenter.h"
38#include "UITask.h"
39#include "UITranslationEventListener.h"
40#include "UIThreadPool.h"
41#include "UIVirtualBoxEventHandler.h"
42
43/* COM includes: */
44#include "CMachine.h"
45#include "CMediumAttachment.h"
46#include "CSnapshot.h"
47
48
49/** Template function to convert a list of
50 * abstract objects to a human readable string list.
51 * @note T should have .toString() member implemented. */
52template<class T> static QStringList toStringList(const QList<T> &list)
53{
54 QStringList l;
55 foreach(const T &t, list)
56 l << t.toString();
57 return l;
58}
59
60
61/** UITask extension used for medium-enumeration purposes.
62 * @note We made setting/getting medium a thread-safe stuff. But this wasn't
63 * dangerous for us before since setter/getter calls are splitted in time
64 * by enumeration logic. Previously we were even using
65 * property/setProperty API for that but latest Qt versions prohibits
66 * property/setProperty API usage from other than the GUI thread so we
67 * had to rework that stuff to be thread-safe for Qt >= 5.11. */
68class UITaskMediumEnumeration : public UITask
69{
70 Q_OBJECT;
71
72public:
73
74 /** Constructs @a guiMedium enumeration task. */
75 UITaskMediumEnumeration(const UIMedium &guiMedium)
76 : UITask(UITask::Type_MediumEnumeration)
77 , m_guiMedium(guiMedium)
78 {}
79
80 /** Returns GUI medium. */
81 UIMedium medium() const
82 {
83 /* Acquire under a proper lock: */
84 m_mutex.lock();
85 const UIMedium guiMedium = m_guiMedium;
86 m_mutex.unlock();
87 return guiMedium;
88 }
89
90private:
91
92 /** Contains medium-enumeration task body. */
93 virtual void run() RT_OVERRIDE
94 {
95 /* Enumerate under a proper lock: */
96 m_mutex.lock();
97 m_guiMedium.blockAndQueryState();
98 m_mutex.unlock();
99 }
100
101 /** Holds the mutex to access m_guiMedium member. */
102 mutable QMutex m_mutex;
103 /** Holds the medium being enumerated. */
104 UIMedium m_guiMedium;
105};
106
107
108/*********************************************************************************************************************************
109* Class UIMediumEnumerator implementation. *
110*********************************************************************************************************************************/
111
112UIMediumEnumerator::UIMediumEnumerator()
113 : m_fFullMediumEnumerationRequested(false)
114 , m_fMediumEnumerationInProgress(false)
115{
116 /* Allow UIMedium to be used in inter-thread signals: */
117 qRegisterMetaType<UIMedium>();
118
119 /* Prepare Main event handlers: */
120 /* Machine related events: */
121 connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigMachineDataChange,
122 this, &UIMediumEnumerator::sltHandleMachineDataChange);
123 /* Medium related events: */
124 connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigStorageControllerChange,
125 this, &UIMediumEnumerator::sltHandleStorageControllerChange);
126 connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigStorageDeviceChange,
127 this, &UIMediumEnumerator::sltHandleStorageDeviceChange);
128 connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigMediumChange,
129 this, &UIMediumEnumerator::sltHandleMediumChange);
130 connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigMediumConfigChange,
131 this, &UIMediumEnumerator::sltHandleMediumConfigChange);
132 connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigMediumRegistered,
133 this, &UIMediumEnumerator::sltHandleMediumRegistered);
134
135 /* Prepare global thread-pool listener: */
136 connect(uiCommon().threadPool(), &UIThreadPool::sigTaskComplete,
137 this, &UIMediumEnumerator::sltHandleMediumEnumerationTaskComplete);
138
139 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
140 this, &UIMediumEnumerator::sltRetranslateUI);
141
142 /* We should make sure media map contains at least NULL medium object: */
143 addNullMediumToMap(m_media);
144 /* Notify listener about initial enumeration started/finished instantly: */
145 LogRel(("GUI: UIMediumEnumerator: Initial medium-enumeration finished!\n"));
146 emit sigMediumEnumerationStarted();
147 emit sigMediumEnumerationFinished();
148}
149
150QList<QUuid> UIMediumEnumerator::mediumIDs() const
151{
152 /* Return keys of current media map: */
153 return m_media.keys();
154}
155
156UIMedium UIMediumEnumerator::medium(const QUuid &uMediumID) const
157{
158 /* Search through current media map
159 * for the UIMedium with passed ID: */
160 if (m_media.contains(uMediumID))
161 return m_media.value(uMediumID);
162 /* Return NULL UIMedium otherwise: */
163 return UIMedium();
164}
165
166void UIMediumEnumerator::createMedium(const UIMedium &guiMedium)
167{
168 /* Get UIMedium ID: */
169 const QUuid uMediumID = guiMedium.id();
170
171 /* Do not create UIMedium(s) with incorrect ID: */
172 AssertReturnVoid(!uMediumID.isNull());
173 /* Make sure UIMedium doesn't exist already: */
174 if (m_media.contains(uMediumID))
175 return;
176
177 /* Insert UIMedium: */
178 m_media[uMediumID] = guiMedium;
179 LogRel(("GUI: UIMediumEnumerator: Medium with key={%s} created\n", uMediumID.toString().toUtf8().constData()));
180
181 /* Notify listener: */
182 emit sigMediumCreated(uMediumID);
183}
184
185void UIMediumEnumerator::enumerateMedia(const CMediumVector &comMedia /* = CMediumVector() */)
186{
187 /* Compose new map of currently cached media & their children.
188 * While composing we are using data from already cached media. */
189 UIMediumMap guiMedia;
190 addNullMediumToMap(guiMedia);
191 if (comMedia.isEmpty())
192 {
193 /* Compose new map of all known media & their children: */
194 addMediaToMap(gpGlobalSession->virtualBox().GetHardDisks(), guiMedia);
195 addMediaToMap(gpGlobalSession->host().GetDVDDrives(), guiMedia);
196 addMediaToMap(gpGlobalSession->virtualBox().GetDVDImages(), guiMedia);
197 addMediaToMap(gpGlobalSession->host().GetFloppyDrives(), guiMedia);
198 addMediaToMap(gpGlobalSession->virtualBox().GetFloppyImages(), guiMedia);
199 }
200 else
201 {
202 /* Compose new map of passed media & their children: */
203 addMediaToMap(comMedia, guiMedia);
204 }
205
206 /* UICommon is cleaning up, abort immediately: */
207 if (uiCommon().isCleaningUp())
208 return;
209
210 if (comMedia.isEmpty())
211 {
212 /* Replace existing media map since
213 * we have full medium enumeration: */
214 m_fFullMediumEnumerationRequested = true;
215 m_media = guiMedia;
216 }
217 else
218 {
219 /* Throw the media to existing map: */
220 foreach (const QUuid &uMediumId, guiMedia.keys())
221 m_media[uMediumId] = guiMedia.value(uMediumId);
222 }
223
224 /* If enumeration hasn't yet started: */
225 if (!m_fMediumEnumerationInProgress)
226 {
227 /* Notify listener about enumeration started: */
228 LogRel(("GUI: UIMediumEnumerator: Medium-enumeration started...\n"));
229 m_fMediumEnumerationInProgress = true;
230 emit sigMediumEnumerationStarted();
231
232 /* Make sure we really have more than one UIMedium (which is NULL): */
233 if ( guiMedia.size() == 1
234 && guiMedia.first().id() == UIMedium::nullID())
235 {
236 /* Notify listener about enumeration finished instantly: */
237 LogRel(("GUI: UIMediumEnumerator: Medium-enumeration finished!\n"));
238 m_fMediumEnumerationInProgress = false;
239 emit sigMediumEnumerationFinished();
240 }
241 }
242
243 /* Start enumeration for media with non-NULL ID: */
244 foreach (const QUuid &uMediumID, guiMedia.keys())
245 if (!uMediumID.isNull())
246 createMediumEnumerationTask(guiMedia[uMediumID]);
247}
248
249void UIMediumEnumerator::refreshMedia()
250{
251 /* Make sure we are not already in progress: */
252 AssertReturnVoid(!m_fMediumEnumerationInProgress);
253
254 /* Refresh all cached media we have: */
255 foreach (const QUuid &uMediumID, m_media.keys())
256 m_media[uMediumID].refresh();
257}
258
259void UIMediumEnumerator::sltRetranslateUI()
260{
261 /* Translating NULL UIMedium by recreating it: */
262 if (m_media.contains(UIMedium::nullID()))
263 m_media[UIMedium::nullID()] = UIMedium();
264}
265
266void UIMediumEnumerator::sltHandleMachineDataChange(const QUuid &uMachineId)
267{
268 //printf("MachineDataChange: machine-id=%s\n",
269 // uMachineId.toString().toUtf8().constData());
270 LogRel2(("GUI: UIMediumEnumerator: MachineDataChange event received, Machine ID = {%s}\n",
271 uMachineId.toString().toUtf8().constData()));
272
273 /* Enumerate all the media of machine with this ID: */
274 QList<QUuid> result;
275 enumerateAllMediaOfMachineWithId(uMachineId, result);
276}
277
278void UIMediumEnumerator::sltHandleStorageControllerChange(const QUuid &uMachineId, const QString &strControllerName)
279{
280 //printf("StorageControllerChanged: machine-id=%s, controller-name=%s\n",
281 // uMachineId.toString().toUtf8().constData(), strControllerName.toUtf8().constData());
282 LogRel2(("GUI: UIMediumEnumerator: StorageControllerChanged event received, Medium ID = {%s}, Controller Name = {%s}\n",
283 uMachineId.toString().toUtf8().constData(), strControllerName.toUtf8().constData()));
284}
285
286void UIMediumEnumerator::sltHandleStorageDeviceChange(CMediumAttachment comAttachment, bool fRemoved, bool fSilent)
287{
288 //printf("StorageDeviceChanged: removed=%d, silent=%d\n",
289 // fRemoved, fSilent);
290 LogRel2(("GUI: UIMediumEnumerator: StorageDeviceChanged event received, Removed = {%d}, Silent = {%d}\n",
291 fRemoved, fSilent));
292
293 /* Parse attachment: */
294 QList<QUuid> result;
295 parseAttachment(comAttachment, result);
296}
297
298void UIMediumEnumerator::sltHandleMediumChange(CMediumAttachment comAttachment)
299{
300 //printf("MediumChanged\n");
301 LogRel2(("GUI: UIMediumEnumerator: MediumChanged event received\n"));
302
303 /* Parse attachment: */
304 QList<QUuid> result;
305 parseAttachment(comAttachment, result);
306}
307
308void UIMediumEnumerator::sltHandleMediumConfigChange(CMedium comMedium)
309{
310 //printf("MediumConfigChanged\n");
311 LogRel2(("GUI: UIMediumEnumerator: MediumConfigChanged event received\n"));
312
313 /* Parse medium: */
314 QList<QUuid> result;
315 parseMedium(comMedium, result);
316}
317
318void UIMediumEnumerator::sltHandleMediumRegistered(const QUuid &uMediumId, KDeviceType enmMediumType, bool fRegistered)
319{
320 //printf("MediumRegistered: medium-id=%s, medium-type=%d, registered=%d\n",
321 // uMediumId.toString().toUtf8().constData(), enmMediumType, fRegistered);
322 //printf(" Medium to recache: %s\n",
323 // uMediumId.toString().toUtf8().constData());
324 LogRel2(("GUI: UIMediumEnumerator: MediumRegistered event received, Medium ID = {%s}, Medium type = {%d}, Registered = {%d}\n",
325 uMediumId.toString().toUtf8().constData(), enmMediumType, fRegistered));
326
327 /* New medium registered: */
328 if (fRegistered)
329 {
330 /* Make sure this medium isn't already cached: */
331 if (!medium(uMediumId).isNull())
332 {
333 /* This medium can be known because of async event nature. Currently medium registration event comes
334 * very late and other even unrelated events can come before it and request for this particular medium
335 * enumeration, so we just ignore repetitive events but enumerate this UIMedium at least once if it
336 * wasn't registered before. */
337 if (!m_registeredMediaIds.contains(uMediumId))
338 {
339 LogRel2(("GUI: UIMediumEnumerator: Medium {%s} is cached but not registered already, so will be enumerated..\n",
340 uMediumId.toString().toUtf8().constData()));
341 createMediumEnumerationTask(m_media.value(uMediumId));
342
343 /* Mark medium registered: */
344 m_registeredMediaIds << uMediumId;
345 }
346 }
347 else
348 {
349 /* Get VBox for temporary usage, it will cache the error info: */
350 CVirtualBox comVBox = gpGlobalSession->virtualBox();
351 /* Open existing medium, this API can be used to open known medium as well, using ID as location for that: */
352 CMedium comMedium = comVBox.OpenMedium(uMediumId.toString(), enmMediumType, KAccessMode_ReadWrite, false);
353 if (!comVBox.isOk())
354 LogRel(("GUI: UIMediumEnumerator: Unable to open registered medium! %s\n",
355 UIErrorString::simplifiedErrorInfo(comVBox).toUtf8().constData()));
356 else
357 {
358 /* Create new UIMedium: */
359 const UIMedium guiMedium(comMedium, UIMediumDefs::mediumTypeToLocal(comMedium.GetDeviceType()));
360 const QUuid &uUIMediumKey = guiMedium.key();
361
362 /* Cache corresponding UIMedium: */
363 m_media.insert(uUIMediumKey, guiMedium);
364 LogRel2(("GUI: UIMediumEnumerator: Medium {%s} is now cached and will be enumerated..\n",
365 uUIMediumKey.toString().toUtf8().constData()));
366
367 /* And notify listeners: */
368 emit sigMediumCreated(uUIMediumKey);
369
370 /* Enumerate corresponding UIMedium: */
371 createMediumEnumerationTask(m_media.value(uMediumId));
372
373 /* Mark medium registered: */
374 m_registeredMediaIds << uMediumId;
375 }
376 }
377 }
378 /* Old medium unregistered: */
379 else
380 {
381 /* Make sure this medium is still cached: */
382 if (medium(uMediumId).isNull())
383 {
384 /* This medium can be wiped out already because of async event nature. Currently
385 * medium unregistration event comes very late and other even unrealted events
386 * can come before it and request for this particular medium enumeration. If medium
387 * enumeration is performed fast enough (before medium unregistration event comes),
388 * medium will be wiped out already, so we just ignore it. */
389 LogRel2(("GUI: UIMediumEnumerator: Medium {%s} was not currently cached!\n",
390 uMediumId.toString().toUtf8().constData()));
391 }
392 else
393 {
394 /* Forget corresponding UIMedium: */
395 m_media.remove(uMediumId);
396 LogRel2(("GUI: UIMediumEnumerator: Medium {%s} is no more cached!\n",
397 uMediumId.toString().toUtf8().constData()));
398
399 /* And notify listeners: */
400 emit sigMediumDeleted(uMediumId);
401
402 /* Besides that we should enumerate all the
403 * 1st level children of deleted medium: */
404 QList<QUuid> result;
405 enumerateAllMediaOfMediumWithId(uMediumId, result);
406 }
407
408 /* Mark medium unregistered: */
409 m_registeredMediaIds.remove(uMediumId);
410 }
411}
412
413void UIMediumEnumerator::sltHandleMediumEnumerationTaskComplete(UITask *pTask)
414{
415 /* Make sure that is one of our tasks: */
416 if (pTask->type() != UITask::Type_MediumEnumeration)
417 return;
418 AssertReturnVoid(m_tasks.contains(pTask));
419
420 /* Get enumerated UIMedium: */
421 const UIMedium guiMedium = qobject_cast<UITaskMediumEnumeration*>(pTask)->medium();
422 const QUuid uMediumKey = guiMedium.key();
423 LogRel2(("GUI: UIMediumEnumerator: Medium with key={%s} enumerated\n",
424 uMediumKey.toString().toUtf8().constData()));
425
426 /* Remove task from internal set: */
427 m_tasks.remove(pTask);
428
429 /* Make sure such UIMedium still exists: */
430 if (!m_media.contains(uMediumKey))
431 {
432 LogRel2(("GUI: UIMediumEnumerator: Medium with key={%s} already deleted by a third party\n",
433 uMediumKey.toString().toUtf8().constData()));
434 return;
435 }
436
437 /* Check if UIMedium ID was changed: */
438 const QUuid uMediumID = guiMedium.id();
439 /* UIMedium ID was changed to nullID: */
440 if (uMediumID == UIMedium::nullID())
441 {
442 /* Delete this UIMedium: */
443 m_media.remove(uMediumKey);
444 LogRel2(("GUI: UIMediumEnumerator: Medium with key={%s} closed and deleted (after enumeration)\n",
445 uMediumKey.toString().toUtf8().constData()));
446
447 /* And notify listener about delete: */
448 emit sigMediumDeleted(uMediumKey);
449 }
450 /* UIMedium ID was changed to something proper: */
451 else if (uMediumID != uMediumKey)
452 {
453 /* We have to reinject enumerated UIMedium: */
454 m_media.remove(uMediumKey);
455 m_media[uMediumID] = guiMedium;
456 m_media[uMediumID].setKey(uMediumID);
457 LogRel2(("GUI: UIMediumEnumerator: Medium with key={%s} has it changed to {%s}\n",
458 uMediumKey.toString().toUtf8().constData(),
459 uMediumID.toString().toUtf8().constData()));
460
461 /* And notify listener about delete/create: */
462 emit sigMediumDeleted(uMediumKey);
463 emit sigMediumCreated(uMediumID);
464 }
465 /* UIMedium ID was not changed: */
466 else
467 {
468 /* Just update enumerated UIMedium: */
469 m_media[uMediumID] = guiMedium;
470 LogRel2(("GUI: UIMediumEnumerator: Medium with key={%s} updated\n",
471 uMediumID.toString().toUtf8().constData()));
472
473 /* And notify listener about update: */
474 emit sigMediumEnumerated(uMediumID);
475 }
476
477 /* If there are no more tasks we know about: */
478 if (m_tasks.isEmpty())
479 {
480 /* Notify listener: */
481 LogRel(("GUI: UIMediumEnumerator: Medium-enumeration finished!\n"));
482 m_fMediumEnumerationInProgress = false;
483 emit sigMediumEnumerationFinished();
484 }
485}
486
487void UIMediumEnumerator::createMediumEnumerationTask(const UIMedium &guiMedium)
488{
489 /* Prepare medium-enumeration task: */
490 UITask *pTask = new UITaskMediumEnumeration(guiMedium);
491 /* Append to internal set: */
492 m_tasks << pTask;
493 /* Post into global thread-pool: */
494 uiCommon().threadPool()->enqueueTask(pTask);
495}
496
497void UIMediumEnumerator::addNullMediumToMap(UIMediumMap &media)
498{
499 /* Insert NULL UIMedium to the passed media map.
500 * Get existing one from the previous map if any. */
501 const UIMedium guiMedium = m_media.contains(UIMedium::nullID())
502 ? m_media[UIMedium::nullID()]
503 : UIMedium();
504 media.insert(UIMedium::nullID(), guiMedium);
505}
506
507void UIMediumEnumerator::addMediaToMap(const CMediumVector &inputMedia, UIMediumMap &outputMedia)
508{
509 /* Iterate through passed inputMedia vector: */
510 foreach (const CMedium &comMedium, inputMedia)
511 {
512 /* If UICommon is cleaning up, abort immediately: */
513 if (uiCommon().isCleaningUp())
514 break;
515
516 /* Insert UIMedium to the passed media map.
517 * Get existing one from the previous map if any.
518 * Create on the basis of comMedium otherwise. */
519 const QUuid uMediumID = comMedium.GetId();
520 const UIMedium guiMedium = m_media.contains(uMediumID)
521 ? m_media.value(uMediumID)
522 : UIMedium(comMedium, UIMediumDefs::mediumTypeToLocal(comMedium.GetDeviceType()));
523 outputMedia.insert(guiMedium.id(), guiMedium);
524
525 /* Insert comMedium children into map as well: */
526 addMediaToMap(comMedium.GetChildren(), outputMedia);
527 }
528}
529
530void UIMediumEnumerator::parseAttachment(CMediumAttachment comAttachment, QList<QUuid> &result)
531{
532 /* Make sure attachment is valid: */
533 if (comAttachment.isNull())
534 {
535 LogRel2(("GUI: UIMediumEnumerator: Attachment is NULL!\n"));
536 /// @todo is this possible case?
537 AssertFailed();
538 }
539 else
540 {
541 /* Acquire attachment medium: */
542 CMedium comMedium = comAttachment.GetMedium();
543 if (!comAttachment.isOk())
544 LogRel(("GUI: UIMediumEnumerator: Unable to acquire attachment medium! %s\n",
545 UIErrorString::simplifiedErrorInfo(comAttachment).toUtf8().constData()));
546 else
547 {
548 /* Parse medium: */
549 parseMedium(comMedium, result);
550
551 // WORKAROUND:
552 // In current architecture there is no way to determine medium previously mounted
553 // to this attachment, so we will have to enumerate all other cached media which
554 // belongs to the same VM, since they may no longer belong to it.
555
556 /* Acquire parent VM: */
557 CMachine comMachine = comAttachment.GetMachine();
558 if (!comAttachment.isOk())
559 LogRel(("GUI: UIMediumEnumerator: Unable to acquire attachment parent machine! %s\n",
560 UIErrorString::simplifiedErrorInfo(comAttachment).toUtf8().constData()));
561 else
562 {
563 /* Acquire machine ID: */
564 const QUuid uMachineId = comMachine.GetId();
565 if (!comMachine.isOk())
566 LogRel(("GUI: UIMediumEnumerator: Unable to acquire machine ID! %s\n",
567 UIErrorString::simplifiedErrorInfo(comMachine).toUtf8().constData()));
568 else
569 {
570 /* Enumerate all the media of machine with this ID: */
571 enumerateAllMediaOfMachineWithId(uMachineId, result);
572 }
573 }
574 }
575 }
576}
577
578void UIMediumEnumerator::parseMedium(CMedium comMedium, QList<QUuid> &result)
579{
580 /* Make sure medium is valid: */
581 if (comMedium.isNull())
582 {
583 /* This medium is NULL by some reason, the obvious case when this
584 * can happen is when optical/floppy device is created empty. */
585 LogRel2(("GUI: UIMediumEnumerator: Medium is NULL!\n"));
586 }
587 else
588 {
589 /* Acquire medium ID: */
590 const QUuid uMediumId = comMedium.GetId();
591 if (!comMedium.isOk())
592 LogRel(("GUI: UIMediumEnumerator: Unable to acquire medium ID! %s\n",
593 UIErrorString::simplifiedErrorInfo(comMedium).toUtf8().constData()));
594 else
595 {
596 //printf(" Medium to recache: %s\n", uMediumId.toString().toUtf8().constData());
597
598 /* Make sure this medium is already cached: */
599 if (medium(uMediumId).isNull())
600 {
601 /* This medium isn't cached by some reason, which can be different.
602 * One of such reasons is when config-changed event comes earlier than
603 * corresponding registration event. For now we are ignoring that at all. */
604 LogRel2(("GUI: UIMediumEnumerator: Medium {%s} isn't cached yet!\n",
605 uMediumId.toString().toUtf8().constData()));
606 }
607 else
608 {
609 /* Enumerate corresponding UIMedium: */
610 LogRel2(("GUI: UIMediumEnumerator: Medium {%s} will be enumerated..\n",
611 uMediumId.toString().toUtf8().constData()));
612 createMediumEnumerationTask(m_media.value(uMediumId));
613 result << uMediumId;
614 }
615 }
616 }
617}
618
619void UIMediumEnumerator::enumerateAllMediaOfMachineWithId(const QUuid &uMachineId, QList<QUuid> &result)
620{
621 /* For each the cached UIMedium we have: */
622 foreach (const QUuid &uMediumId, mediumIDs())
623 {
624 /* Check if medium isn't NULL, used by our
625 * machine and wasn't already enumerated. */
626 const UIMedium guiMedium = medium(uMediumId);
627 if ( !guiMedium.isNull()
628 && guiMedium.machineIds().contains(uMachineId)
629 && !result.contains(uMediumId))
630 {
631 /* Enumerate corresponding UIMedium: */
632 //printf(" Medium to recache: %s\n",
633 // uMediumId.toString().toUtf8().constData());
634 LogRel2(("GUI: UIMediumEnumerator: Medium {%s} of machine {%s} will be enumerated..\n",
635 uMediumId.toString().toUtf8().constData(),
636 uMachineId.toString().toUtf8().constData()));
637 createMediumEnumerationTask(guiMedium);
638 result << uMediumId;
639 }
640 }
641}
642
643void UIMediumEnumerator::enumerateAllMediaOfMediumWithId(const QUuid &uParentMediumId, QList<QUuid> &result)
644{
645 /* For each the cached UIMedium we have: */
646 foreach (const QUuid &uMediumId, mediumIDs())
647 {
648 /* Check if medium isn't NULL, and is
649 * a child of specified parent medium. */
650 const UIMedium guiMedium = medium(uMediumId);
651 if ( !guiMedium.isNull()
652 && guiMedium.parentID() == uParentMediumId)
653 {
654 /* Enumerate corresponding UIMedium: */
655 //printf(" Medium to recache: %s\n",
656 // uMediumId.toString().toUtf8().constData());
657 LogRel2(("GUI: UIMediumEnumerator: Medium {%s} a child of medium {%s} will be enumerated..\n",
658 uMediumId.toString().toUtf8().constData(),
659 uParentMediumId.toString().toUtf8().constData()));
660 createMediumEnumerationTask(guiMedium);
661 result << uMediumId;
662 }
663 }
664}
665
666
667#include "UIMediumEnumerator.moc"
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use