VirtualBox

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

Last change on this file was 104915, checked in by vboxsync, 3 months ago

FE/Qt: UIMediumEnumerator: Moving some unrelated stuff to UIMediumTools namespace as that's more suitable place for this one.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.8 KB
Line 
1/* $Id: UIMediumEnumerator.h 104915 2024-06-13 13:18:04Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIMediumEnumerator class declaration.
4 */
5
6/*
7 * Copyright (C) 2013-2024 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#ifndef FEQT_INCLUDED_SRC_medium_UIMediumEnumerator_h
29#define FEQT_INCLUDED_SRC_medium_UIMediumEnumerator_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34/* Qt includes: */
35#include <QObject>
36#include <QReadWriteLock>
37#include <QSet>
38
39/* GUI includes: */
40#include "UILibraryDefs.h"
41#include "UIMedium.h"
42
43/* COM includes: */
44#include "CMedium.h"
45#include "CMediumAttachment.h"
46
47/* Forward declarations: */
48class UITask;
49class UIThreadPool;
50
51/** A map of CMedium objects ordered by their IDs. */
52typedef QMap<QUuid, CMedium> CMediumMap;
53
54/** QObject extension operating as medium-enumeration object.
55 * Manages access to cached UIMedium information via public API.
56 * Updates cache on corresponding Main events using thread-pool interface. */
57class SHARED_LIBRARY_STUFF UIMediumEnumerator : public QObject
58{
59 Q_OBJECT;
60
61signals:
62
63 /** Notifies listeners about UIMedium with @a uMediumID created. */
64 void sigMediumCreated(const QUuid &uMediumID);
65 /** Notifies listeners about UIMedium with @a uMediumID deleted. */
66 void sigMediumDeleted(const QUuid &uMediumID);
67
68 /** Notifies listeners about consolidated medium-enumeration process has started. */
69 void sigMediumEnumerationStarted();
70 /** Notifies listeners about UIMedium with @a uMediumID updated. */
71 void sigMediumEnumerated(const QUuid &uMediumID);
72 /** Notifies listeners about consolidated medium-enumeration process has finished. */
73 void sigMediumEnumerationFinished();
74
75 /** Notifies listeners about update of recently media list. */
76 void sigRecentMediaListUpdated(UIMediumDeviceType enmMediumType);
77
78public:
79
80 /** Creates singleton instance. */
81 static void create();
82 /** Destroys singleton instance. */
83 static void destroy();
84 /** Returns singleton instance. */
85 static UIMediumEnumerator *instance();
86 /** Returns whether singleton intance really exists. */
87 static bool exists();
88
89 /** Returns cached UIMedium ID list. */
90 QList<QUuid> mediumIDs() const;
91 /** Returns a wrapper of cached UIMedium with specified @a uMediumID. */
92 UIMedium medium(const QUuid &uMediumID) const;
93
94 /** Creates UIMedium thus caching it internally on the basis of passed @a guiMedium information. */
95 void createMedium(const UIMedium &guiMedium);
96
97 /** Returns whether full consolidated medium-enumeration process is requested. */
98 bool isFullMediumEnumerationRequested() const { return m_fFullMediumEnumerationRequested; }
99 /** Returns whether any consolidated medium-enumeration process is in progress. */
100 bool isMediumEnumerationInProgress() const { return m_fMediumEnumerationInProgress; }
101 /** Makes a request to enumerate specified @a comMedia.
102 * @note Empty passed map means that full/overall medium-enumeration is requested.
103 * In that case previous map will be replaced with the new one, values
104 * present in both maps will be merged from the previous to new one.
105 * @note Non-empty passed map means that additional medium-enumeration is requested.
106 * In that case previous map will be extended with the new one, values
107 * present in both maps will be merged from the previous to new one. */
108 void enumerateMedia(const CMediumVector &comMedia = CMediumVector());
109 /** Refresh all the lightweight UIMedium information for all the cached UIMedium(s).
110 * @note Please note that this is a lightweight version, which doesn't perform
111 * heavy state/accessibility checks thus doesn't require to be performed
112 * by a worker COM-aware thread. */
113 void refreshMedia();
114
115 /** Update extra data related to recently used/referred media.
116 * @param enmMediumType Passes the medium type.
117 * @param strMediumLocation Passes the medium location. */
118 void updateRecentlyUsedMediumListAndFolder(UIMediumDeviceType enmMediumType, QString strMediumLocation);
119
120public slots:
121
122 /** Handles signal about @a comMedium was created. */
123 void sltHandleMediumCreated(const CMedium &comMedium);
124
125private slots:
126
127 /** Handles machine-data-change event for a machine with specified @a uMachineId. */
128 void sltHandleMachineDataChange(const QUuid &uMachineId);
129
130 /** Handles signal about storage controller change.
131 * @param uMachineId Brings the ID of machine corresponding controller belongs to.
132 * @param strControllerName Brings the name of controller this event is related to. */
133 void sltHandleStorageControllerChange(const QUuid &uMachineId, const QString &strControllerName);
134 /** Handles signal about storage device change.
135 * @param comAttachment Brings corresponding attachment.
136 * @param fRemoved Brings whether medium is removed or added.
137 * @param fSilent Brings whether this change has gone silent for guest. */
138 void sltHandleStorageDeviceChange(CMediumAttachment comAttachment, bool fRemoved, bool fSilent);
139 /** Handles signal about storage medium @a comAttachment state change. */
140 void sltHandleMediumChange(CMediumAttachment comAttachment);
141 /** Handles signal about storage @a comMedium config change. */
142 void sltHandleMediumConfigChange(CMedium comMedium);
143 /** Handles signal about storage medium is (un)registered.
144 * @param uMediumId Brings corresponding medium ID.
145 * @param enmMediumType Brings corresponding medium type.
146 * @param fRegistered Brings whether medium is registered or unregistered. */
147 void sltHandleMediumRegistered(const QUuid &uMediumId, KDeviceType enmMediumType, bool fRegistered);
148
149 /** Handles medium-enumeration @a pTask complete signal. */
150 void sltHandleMediumEnumerationTaskComplete(UITask *pTask);
151
152 /** Handles translation event. */
153 void sltRetranslateUI();
154
155private:
156
157 /** Constructs medium-enumerator object. */
158 UIMediumEnumerator();
159
160 /** Subroutine for mediumIDs() call, executed under proper lock. */
161 QList<QUuid> mediumIDsSub() const;
162 /** Subroutine for medium() call, executed under proper lock. */
163 UIMedium mediumSub(const QUuid &uMediumID) const;
164
165 /** Subroutine for createMedium() call, executed under proper lock. */
166 void createMediumSub(const UIMedium &guiMedium);
167
168 /** Subroutine for enumerateMedia() call, executed under proper lock. */
169 void enumerateMediaSub(const CMediumVector &comMedia = CMediumVector());
170 /** Subroutine for enumerateMedia() call, executed under proper lock. */
171 void refreshMediaSub();
172
173 /** Creates medium-enumeration task for certain @a guiMedium. */
174 void createMediumEnumerationTask(const UIMedium &guiMedium);
175 /** Adds NULL UIMedium to specified @a outputMedia map. */
176 void addNullMediumToMap(UIMediumMap &outputMedia);
177 /** Adds @a inputMedia to specified @a outputMedia map. */
178 void addMediaToMap(const CMediumVector &inputMedia, UIMediumMap &outputMedia);
179
180 /** Parses incoming @a comAttachment, enumerating the media it has attached.
181 * @param result Brings the list of previously enumerated media
182 * IDs to be appended with newly enumerated. */
183 void parseAttachment(CMediumAttachment comAttachment, QList<QUuid> &result);
184 /** Parses incoming @a comMedium, enumerating the media it represents.
185 * @param result Brings the list of previously enumerated media
186 * IDs to be appended with newly enumerated. */
187 void parseMedium(CMedium comMedium, QList<QUuid> &result);
188
189 /** Enumerates all the known media attached to machine with certain @a uMachineId.
190 * @param result Brings the list of previously enumerated media
191 * IDs to be appended with newly enumerated. */
192 void enumerateAllMediaOfMachineWithId(const QUuid &uMachineId, QList<QUuid> &result);
193 /** Enumerates all the children media of medium with certain @a uMediumId.
194 * @param result Brings the list of previously enumerated media
195 * IDs to be appended with newly enumerated. */
196 void enumerateAllMediaOfMediumWithId(const QUuid &uMediumId, QList<QUuid> &result);
197
198 /** Returns singleton instance. */
199 static UIMediumEnumerator *s_pInstance;
200 /** Holds the cleanup protection token. */
201 static QReadWriteLock s_guiCleanupProtectionToken;
202
203 /** Holds whether full consolidated medium-enumeration process is requested. */
204 bool m_fFullMediumEnumerationRequested;
205 /** Holds whether any consolidated medium-enumeration process is in progress. */
206 bool m_fMediumEnumerationInProgress;
207
208 /** Holds a set of current medium-enumeration tasks. */
209 QSet<UITask*> m_tasks;
210
211 /** Holds a map of currently cached (enumerated) media. */
212 UIMediumMap m_media;
213 /** Holds a set of currently registered media IDs. */
214 QSet<QUuid> m_registeredMediaIds;
215
216 /** Holds the list of medium names to be excluded from recently used media extra data. */
217 QStringList m_recentMediaExcludeList;
218};
219
220/** Singleton Medium Enumerator 'official' name. */
221#define gpMediumEnumerator UIMediumEnumerator::instance()
222
223#endif /* !FEQT_INCLUDED_SRC_medium_UIMediumEnumerator_h */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette