VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMedium.h@ 104158

Last change on this file since 104158 was 103803, checked in by vboxsync, 9 months ago

FE/Qt. bugref:10618. Splitting COMEnums.h file into individual enum header files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 20.5 KB
Line 
1/* $Id: UIMedium.h 103803 2024-03-12 11:15:18Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIMedium class declaration.
4 */
5
6/*
7 * Copyright (C) 2009-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#ifndef FEQT_INCLUDED_SRC_medium_UIMedium_h
29#define FEQT_INCLUDED_SRC_medium_UIMedium_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34/* Qt includes: */
35#include <QMap>
36#include <QPixmap>
37
38/* GUI includes: */
39#include "UILibraryDefs.h"
40#include "UIMediumDefs.h"
41
42/* COM includes: */
43#include "CMedium.h"
44
45/** Storage medium cache used to
46 * override some UIMedium attributes in the
47 * user-friendly "don't show diffs" mode. */
48struct NoDiffsCache
49{
50 /** Constructor. */
51 NoDiffsCache() : isSet(false), state(KMediumState_NotCreated) {}
52
53 /** Operator= reimplementation. */
54 NoDiffsCache& operator=(const NoDiffsCache &other)
55 {
56 isSet = other.isSet;
57 state = other.state;
58 result = other.result;
59 toolTip = other.toolTip;
60 return *this;
61 }
62
63 /** Holds whether the cache is set. */
64 bool isSet : 1;
65
66 /** Holds overriden medium state. */
67 KMediumState state;
68 /** Holds overriden medium acquiring result. */
69 COMResult result;
70 /** Holds overriden medium tool-tip. */
71 QString toolTip;
72};
73
74/** Storage medium descriptor wrapping CMedium wrapper for IMedium interface.
75 *
76 * Maintains the results of the last CMedium state (accessibility) check and precomposes
77 * string parameters such as name, location and size which can be used for various GUI tasks.
78 *
79 * Many getter methods take the boolean @a fNoDiffs argument.
80 * Unless explicitly stated otherwise, this argument, when set to @c true,
81 * will cause the corresponding property of this object's root medium to be returned instead
82 * of its own one. This is useful when hard drive medium is reflected in the user-friendly
83 * "don't show diffs" mode. For non-hard drive media, the value of this argument is irrelevant
84 * because the root object for such medium is the medium itself.
85 *
86 * Note that this class "abuses" the KMediumState_NotCreated state value to indicate that the
87 * accessibility check of the given medium (see #blockAndQueryState()) has not been done yet
88 * and therefore some parameters such as #size() are meaningless because they can be read only
89 * from the accessible medium. The real KMediumState_NotCreated state is not necessary because
90 * this class is only used with created (existing) media. */
91class SHARED_LIBRARY_STUFF UIMedium
92{
93public:
94
95 /** Default constructor.
96 * Creates NULL UIMedium which is not associated with any CMedium. */
97 UIMedium();
98
99 /** Lazy wrapping constructor.
100 * Creates the UIMedium associated with the given @a medium of the given @a type. */
101 UIMedium(const CMedium &medium, UIMediumDeviceType type);
102
103 /** Wrapping constructor with known medium state.
104 * Similarly to the previous one it creates the UIMedium associated with the
105 * given @a medium of the given @a type but sets the UIMedium @a state to passed one.
106 * Suitable when the medium state is known such as right after the medium creation. */
107 UIMedium(const CMedium &medium, UIMediumDeviceType type, KMediumState state);
108
109 /** Copy constructor.
110 * Creates the UIMedium on the basis of the passed @a other one. */
111 UIMedium(const UIMedium &other);
112
113 /** Operator= reimplementation. */
114 UIMedium& operator=(const UIMedium &other);
115
116 /** Queries the actual medium state.
117 * @note This method blocks for the duration of the state check.
118 * Since this check may take quite a while,
119 * the calling thread must not be the UI thread. */
120 void blockAndQueryState();
121
122 /** Refreshes the precomposed user-readable strings.
123 * @note Note that some string such as #size() are meaningless if the medium state is
124 * KMediumState_NotCreated (i.e. the medium has not yet been checked for accessibility). */
125 void refresh();
126
127 /** Returns the type of UIMedium object. */
128 UIMediumDeviceType type() const { return m_type; }
129
130 /** Returns the CMedium wrapped by this UIMedium object. */
131 const CMedium& medium() const { return m_medium; }
132
133 /** Returns @c true if CMedium wrapped by this UIMedium object has ID == #nullID().
134 * @note Also make sure wrapped CMedium is NULL object if his ID == #nullID(). */
135 bool isNull() const
136 {
137 AssertReturn(m_uId != nullID() || m_medium.isNull(), true);
138 return m_uId == nullID();
139 }
140
141 /** Returns the medium state.
142 * @param fNoDiffs @c true to enable user-friendly "don't show diffs" mode.
143 * @note In "don't show diffs" mode, this method returns the worst state
144 * (in terms of inaccessibility) detected on the given hard drive chain. */
145 KMediumState state(bool fNoDiffs = false) const;
146
147 /** Returns the result of the last blockAndQueryState() call.
148 * Indicates an error and contain a proper error info if the last state check fails.
149 * @param fNoDiffs @c true to enable user-friendly "don't show diffs" mode.
150 * @note In "don't show diffs" mode, this method returns the worst result
151 * (in terms of inaccessibility) detected on the given hard drive chain. */
152 const COMResult& result(bool fNoDiffs = false) const;
153
154 /** Returns the error result of the last blockAndQueryState() call. */
155 QString lastAccessError() const { return m_strLastAccessError; }
156
157 /** Returns the medium ID. */
158 QUuid id() const { return m_uId; }
159
160 /** Returns the medium root ID. */
161 QUuid rootID() const { return m_uRootId; }
162 /** Returns the medium parent ID. */
163 QUuid parentID() const { return m_uParentId; }
164
165 /** Updates medium parent. */
166 void updateParentID();
167
168 /** Returns the medium cache key. */
169 QUuid key() const { return m_uKey; }
170 /** Defines the medium cache @a uKey. */
171 void setKey(const QUuid &uKey) { m_uKey = uKey; }
172
173 /** Returns the medium name.
174 * @param fNoDiffs @c true to enable user-friendly "don't show diffs" mode.
175 * @note In "don't show diffs" mode, this method returns the name of root in the given hard drive chain. */
176 QString name(bool fNoDiffs = false) const { return fNoDiffs ? root().m_strName : m_strName; }
177 /** Returns the medium location.
178 * @param fNoDiffs @c true to enable user-friendly "don't show diffs" mode.
179 * @note In "don't show diffs" mode, this method returns the location of root in the given hard drive chain. */
180 QString location(bool fNoDiffs = false) const { return fNoDiffs ? root().m_strLocation : m_strLocation; }
181 /** Returns the medium description.
182 * @param fNoDiffs @c true to enable user-friendly "don't show diffs" mode.
183 * @note In "don't show diffs" mode, this method returns the description of root in the given hard drive chain. */
184 QString description(bool fNoDiffs = false) const { return fNoDiffs ? root().m_strDescription : m_strDescription; }
185
186 /** Returns the medium size in bytes.
187 * @param fNoDiffs @c true to enable user-friendly "don't show diffs" mode.
188 * @note In "don't show diffs" mode, this method returns the size of root in the given hard drive chain. */
189 qulonglong sizeInBytes(bool fNoDiffs = false) const { return fNoDiffs ? root().m_uSize : m_uSize; }
190 /** Returns the logical medium size in bytes.
191 * @param fNoDiffs @c true to enable user-friendly "don't show diffs" mode.
192 * @note In "don't show diffs" mode, this method returns the size of root in the given hard drive chain. */
193 qulonglong logicalSizeInBytes(bool fNoDiffs = false) const { return fNoDiffs ? root().m_uLogicalSize : m_uLogicalSize; }
194 /** Returns the medium size.
195 * @param fNoDiffs @c true to enable user-friendly "don't show diffs" mode.
196 * @note In "don't show diffs" mode, this method returns the size of root in the given hard drive chain. */
197 QString size(bool fNoDiffs = false) const { return fNoDiffs ? root().m_strSize : m_strSize; }
198 /** Returns the logical medium size.
199 * @param fNoDiffs @c true to enable user-friendly "don't show diffs" mode.
200 * @note In "don't show diffs" mode, this method returns the logical size of root in the given hard drive chain. */
201 QString logicalSize(bool fNoDiffs = false) const { return fNoDiffs ? root().m_strLogicalSize : m_strLogicalSize; }
202
203 /** Returns the medium disk type.
204 * @param fNoDiffs @c true to enable user-friendly "don't show diffs" mode.
205 * @note In "don't show diffs" mode, this method returns the disk type of root in the given hard drive chain. */
206 KMediumType mediumType(bool fNoDiffs = false) const { return fNoDiffs ? root().m_enmMediumType : m_enmMediumType; }
207 /** Returns the medium disk variant.
208 * @param fNoDiffs @c true to enable user-friendly "don't show diffs" mode.
209 * @note In "don't show diffs" mode, this method returns the disk variant of root in the given hard drive chain. */
210 KMediumVariant mediumVariant(bool fNoDiffs = false) const { return fNoDiffs ? root().m_enmMediumVariant : m_enmMediumVariant; }
211
212 /** Returns the hard drive medium disk type.
213 * @param fNoDiffs @c true to enable user-friendly "don't show diffs" mode.
214 * @note In "don't show diffs" mode, this method returns the disk type of root in the given hard drive chain. */
215 QString hardDiskType(bool fNoDiffs = false) const { return fNoDiffs ? root().m_strHardDiskType : m_strHardDiskType; }
216 /** Returns the hard drive medium disk format.
217 * @param fNoDiffs @c true to enable user-friendly "don't show diffs" mode.
218 * @note In "don't show diffs" mode, this method returns the disk format of root in the given hard drive chain. */
219 QString hardDiskFormat(bool fNoDiffs = false) const { return fNoDiffs ? root().m_strHardDiskFormat : m_strHardDiskFormat; }
220
221 /** Returns whether the hard drive medium disk has childred.
222 * @param fNoDiffs @c true to enable user-friendly "don't show diffs" mode.
223 * @note In "don't show diffs" mode, this method returns the disk format of root in the given hard drive chain. */
224 bool hasChildren(bool fNoDiffs = false) const { return fNoDiffs ? root().m_fHasChildren : m_fHasChildren; }
225
226 /** Returns the hard drive medium storage details. */
227 QString storageDetails() const { return m_strStorageDetails; }
228 /** Returns the hard drive medium encryption password ID. */
229 QString encryptionPasswordID() const { return m_strEncryptionPasswordID; }
230
231 /** Returns the medium usage data.
232 * @param fNoDiffs @c true to enable user-friendly "don't show diffs" mode.
233 * @note In "don't show diffs" mode, this method returns the usage data of root in the given hard drive chain. */
234 QString usage(bool fNoDiffs = false) const { return fNoDiffs ? root().m_strUsage : m_strUsage; }
235
236 /** Returns the short version of medium tool-tip. */
237 QString tip() const { return m_strToolTip; }
238
239 /** Returns the full version of medium tool-tip.
240 * @param fNoDiffs @c true to enable user-friendly "don't show diffs" mode.
241 * @param fCheckRO @c true to perform the #readOnly() check and add a notice accordingly.
242 * @param fNullAllowed @c true to allow NULL medium description to be mentioned in the tool-tip.
243 * @note In "don't show diffs" mode (where the attributes of the base hard drive are shown instead
244 * of the attributes of the differencing hard drive), extra information will be added to the
245 * tooltip to give the user a hint that the medium is actually a differencing hard drive. */
246 QString toolTip(bool fNoDiffs = false, bool fCheckRO = false, bool fNullAllowed = false) const;
247
248 /** Shortcut to <tt>#toolTip(fNoDiffs, true, fNullAllowed)</tt>. */
249 QString toolTipCheckRO(bool fNoDiffs = false, bool fNullAllowed = false) const { return toolTip(fNoDiffs, true, fNullAllowed); }
250
251 /** Returns an icon corresponding to the medium state.
252 * Distinguishes between the Inaccessible state and the situation when querying the state itself failed.
253 * @param fNoDiffs @c true to enable user-friendly "don't show diffs" mode.
254 * @param fCheckRO @c true to perform the #readOnly() check and change the icon accordingly.
255 * @note In "don't show diffs" mode (where the attributes of the base hard drive are shown instead
256 * of the attributes of the differencing hard drive), the most worst medium state on the given
257 * hard drive chain will be used to select the medium icon. */
258 QPixmap icon(bool fNoDiffs = false, bool fCheckRO = false) const;
259
260 /** Shortcut to <tt>#icon(fNoDiffs, true)</tt>. */
261 QPixmap iconCheckRO(bool fNoDiffs = false) const { return icon(fNoDiffs, true); }
262
263 /** Returns the details of this medium as a single-line string.
264 * @param fNoDiffs @c true to enable user-friendly "don't show diffs" mode.
265 * @param fPredictDiff @c true to mark the hard drive as differencing if attaching
266 * it would create a differencing hard drive.
267 * @param fUseHTML @c true to allow for emphasizing using bold and italics.
268 * @note For hard drives, the details include the location, type and the logical size of the hard drive.
269 * Note that if @a fNoDiffs is @c true, these properties are queried on the root hard drive of the
270 * given hard drive because the primary purpose of the returned string is to be human readable
271 * (so that seeing a complex diff hard drive name is usually not desirable).
272 * @note For other medium types, the location and the actual size are returned.
273 * Arguments @a fPredictDiff and @a fNoDiffs are ignored in this case.
274 * @note Use #detailsHTML() instead of passing @c true for @a fUseHTML.
275 * @note The medium object may become uninitialized by a third party while this method is reading its properties.
276 * In this case, the method will return an empty string. */
277 QString details(bool fNoDiffs = false, bool fPredictDiff = false, bool fUseHTML = false) const;
278
279 /** Shortcut to <tt>#details(fNoDiffs, fPredictDiff, true)</tt>. */
280 QString detailsHTML(bool fNoDiffs = false, bool fPredictDiff = false) const { return details(fNoDiffs, fPredictDiff, true); }
281
282 /** Returns the medium cache for "don't show diffs" mode. */
283 const NoDiffsCache& cache() const { return m_noDiffs; }
284
285 /** Returns whether this medium is hidden.
286 * @note The medium is considered 'hidden' if it has corresponding
287 * medium property or is connected to 'hidden' VMs only. */
288 bool isHidden() const { return m_fHidden || m_fUsedByHiddenMachinesOnly; }
289
290 /** Returns whether this medium is read-only
291 * (either because it is Immutable or because it has child hard drives).
292 * @note Read-only medium can only be attached indirectly. */
293 bool isReadOnly() const { return m_fReadOnly; }
294
295 /** Returns whether this medium is attached to any VM in any snapshot. */
296 bool isUsedInSnapshots() const { return m_fUsedInSnapshots; }
297
298 /** Returns whether this medium corresponds to real host drive. */
299 bool isHostDrive() const { return m_fHostDrive; }
300
301 /** Returns whether this medium is encrypted. */
302 bool isEncrypted() const { return m_fEncrypted; }
303
304 /** Returns whether this medium is attached to any VM (in the current state or in a snapshot) in which case
305 * #usage() will contain a string with comma-separated VM names (with snapshot names, if any, in parenthesis). */
306 bool isUsed() const { return !m_strUsage.isNull(); }
307
308 /** Returns whether this medium is attached to the given machine in the current state. */
309 bool isAttachedInCurStateTo(const QUuid &uMachineId) const { return m_curStateMachineIds.indexOf(uMachineId) >= 0; }
310
311 /** Returns a vector of IDs of all machines this medium is attached to. */
312 const QList<QUuid>& machineIds() const { return m_machineIds; }
313 /** Returns a vector of IDs of all machines this medium is attached to
314 * in their current state (i.e. excluding snapshots). */
315 const QList<QUuid>& curStateMachineIds() const { return m_curStateMachineIds; }
316
317 /** Returns NULL medium ID. */
318 static QUuid nullID();
319
320 /** Returns passed @a uID if it's valid or #nullID() overwise. */
321 static QUuid normalizedID(const QUuid &uID);
322
323 /** Determines if passed @a medium is attached to hidden machines only. */
324 static bool isMediumAttachedToHiddenMachinesOnly(const UIMedium &medium);
325
326private:
327
328 /** Returns medium root. */
329 UIMedium root() const;
330 /** Returns medium parent. */
331 UIMedium parent() const;
332
333 /** Checks if m_noDiffs is filled in and does it if not.
334 * @param fNoDiffs @if false, this method immediately returns. */
335 void checkNoDiffs(bool fNoDiffs);
336
337 /** Returns string representation for passed @a comMedium type. */
338 static QString mediumTypeToString(const CMedium &comMedium);
339
340 /** Holds the type of UIMedium object. */
341 UIMediumDeviceType m_type;
342
343 /** Holds the CMedium wrapped by this UIMedium object. */
344 CMedium m_medium;
345
346 /** Holds the medium state. */
347 KMediumState m_state;
348 /** Holds the result of the last blockAndQueryState() call. */
349 COMResult m_result;
350 /** Holds the error result of the last blockAndQueryState() call. */
351 QString m_strLastAccessError;
352
353 /** Holds the medium ID. */
354 QUuid m_uId;
355 /** Holds the medium root ID. */
356 QUuid m_uRootId;
357 /** Holds the medium parent ID. */
358 QUuid m_uParentId;
359
360 /** Holds the medium cache key. */
361 QUuid m_uKey;
362
363 /** Holds the medium name. */
364 QString m_strName;
365 /** Holds the medium location. */
366 QString m_strLocation;
367 /** Holds the medium description. */
368 QString m_strDescription;
369
370 /** Holds the medium size in bytes. */
371 qulonglong m_uSize;
372 /** Holds the logical medium size in bytes. */
373 qulonglong m_uLogicalSize;
374 /** Holds the medium size. */
375 QString m_strSize;
376 /** Holds the logical medium size. */
377 QString m_strLogicalSize;
378
379 /** Holds the medium disk type. */
380 KMediumType m_enmMediumType;
381 /** Holds the medium disk variant. */
382 KMediumVariant m_enmMediumVariant;
383
384 /** Holds the hard drive medium disk type. */
385 QString m_strHardDiskType;
386 /** Holds the hard drive medium disk format. */
387 QString m_strHardDiskFormat;
388 /** Holds whether the hard drive medium disk has children. */
389 bool m_fHasChildren;
390 /** Holds the hard drive medium storage details. */
391 QString m_strStorageDetails;
392 /** Holds the hard drive medium encryption password ID. */
393 QString m_strEncryptionPasswordID;
394
395 /** Holds the medium usage. */
396 QString m_strUsage;
397 /** Holds the medium tool-tip. */
398 QString m_strToolTip;
399 /** Holds the vector of IDs of all machines this medium is attached to. */
400 QList<QUuid> m_machineIds;
401 /** Hodls the vector of IDs of all machines this medium is attached to
402 * in their current state (i.e. excluding snapshots). */
403 QList<QUuid> m_curStateMachineIds;
404
405 /** Holds the medium cache for "don't show diffs" mode. */
406 NoDiffsCache m_noDiffs;
407
408 /** Holds whether this medium is 'hidden' by the corresponding medium property. */
409 bool m_fHidden : 1;
410 /** Holds whether this medium is 'hidden' because it's used by 'hidden' VMs only. */
411 bool m_fUsedByHiddenMachinesOnly : 1;
412 /** Holds whether this medium is read-only. */
413 bool m_fReadOnly : 1;
414 /** Holds whether this medium is attached to any VM in any snapshot. */
415 bool m_fUsedInSnapshots : 1;
416 /** Holds whether this medium corresponds to real host drive. */
417 bool m_fHostDrive : 1;
418 /** Holds whether this medium is encrypted. */
419 bool m_fEncrypted : 1;
420
421 /** Holds the NULL medium ID. */
422 static QUuid m_uNullID;
423 /** Holds the medium tool-tip table template. */
424 static QString m_sstrTable;
425 /** Holds the medium tool-tip table row template. */
426 static QString m_sstrRow;
427};
428Q_DECLARE_METATYPE(UIMedium);
429
430typedef QMap<QUuid, UIMedium> UIMediumMap;
431
432#endif /* !FEQT_INCLUDED_SRC_medium_UIMedium_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