VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/VBoxMedium.h@ 35740

Last change on this file since 35740 was 33540, checked in by vboxsync, 14 years ago

*: spelling fixes, thanks Timeless!

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.2 KB
Line 
1/** @file
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * VBoxMedium class declaration
5 */
6
7/*
8 * Copyright (C) 2009 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#ifndef __VBoxMedium_h__
20#define __VBoxMedium_h__
21
22/* Global includes */
23#include <QPixmap>
24#include <QLinkedList>
25
26/* Local includes */
27#include "COMDefs.h"
28
29#include <iprt/cpp/utils.h>
30
31/**
32 * Cache used to override some attributes in the user-friendly "don't show diffs" mode.
33 */
34struct NoDiffsCache
35{
36 NoDiffsCache() : isSet (false), state (KMediumState_NotCreated) {}
37 NoDiffsCache& operator= (const NoDiffsCache &aOther)
38 {
39 isSet = aOther.isSet;
40 state = aOther.state;
41 result = aOther.result;
42 toolTip = aOther.toolTip;
43 return *this;
44 }
45
46 bool isSet : 1;
47
48 KMediumState state;
49 COMResult result;
50 QString toolTip;
51};
52
53/**
54 * Media descriptor for the GUI.
55 *
56 * Maintains the results of the last state (accessibility) check and precomposes
57 * string parameters such as location, size which can be used in various GUI
58 * controls.
59 *
60 * Many getter methods take the boolean @a aNoDiffs argument. Unless explicitly
61 * stated otherwise, this argument, when set to @c true, will cause the
62 * corresponding property of this object's root medium to be returned instead of
63 * its own one. This is useful when hard disk media is represented in the
64 * user-friendly "don't show diffs" mode. For non-hard disk media, the value of
65 * this argument is irrelevant because the root object for such medium is
66 * the medium itself.
67 *
68 * Note that this class "abuses" the KMediumState_NotCreated state value to
69 * indicate that the accessibility check of the given medium (see
70 * #blockAndQueryState()) has not been done yet and therefore some parameters
71 * such as #size() are meaningless because they can be read only from the
72 * accessible medium. The real KMediumState_NotCreated state is not necessary
73 * because this class is only used with created (existing) media.
74 */
75class VBoxMedium
76{
77public:
78
79 /**
80 * Creates a null medium descriptor which is not associated with any medium.
81 * The state field is set to KMediumState_NotCreated.
82 */
83 VBoxMedium()
84 : mType (VBoxDefs::MediumType_Invalid)
85 , mState (KMediumState_NotCreated)
86 , mIsReadOnly (false)
87 , mIsUsedInSnapshots (false)
88 , mParent (0) { refresh(); }
89
90 /**
91 * Creates a media descriptor associated with the given medium.
92 *
93 * The state field remain KMediumState_NotCreated until #blockAndQueryState()
94 * is called. All precomposed strings are filled up by implicitly calling
95 * #refresh(), see the #refresh() details for more info.
96 *
97 * One of the hardDisk, dvdImage, or floppyImage members is assigned from
98 * aMedium according to aType. @a aParent must be always NULL for non-hard
99 * disk media.
100 */
101 VBoxMedium (const CMedium &aMedium, VBoxDefs::MediumType aType, VBoxMedium *aParent = 0)
102 : mMedium (aMedium)
103 , mType (aType)
104 , mState (KMediumState_NotCreated)
105 , mIsReadOnly (false)
106 , mIsUsedInSnapshots (false)
107 , mParent (aParent) { refresh(); }
108
109 /**
110 * Similar to the other non-null constructor but sets the media state to
111 * @a aState. Suitable when the media state is known such as right after
112 * creation.
113 */
114 VBoxMedium (const CMedium &aMedium, VBoxDefs::MediumType aType, KMediumState aState)
115 : mMedium (aMedium)
116 , mType (aType)
117 , mState (aState)
118 , mIsReadOnly (false)
119 , mIsUsedInSnapshots (false)
120 , mParent (0) { refresh(); }
121
122 VBoxMedium& operator= (const VBoxMedium &aOther);
123
124 void blockAndQueryState();
125 void refresh();
126
127 const CMedium &medium() const { return mMedium; }
128
129 VBoxDefs::MediumType type() const { return mType; }
130
131 /**
132 * Media state. In "don't show diffs" mode, this is the worst state (in
133 * terms of inaccessibility) detected on the given hard disk chain.
134 *
135 * @param aNoDiffs @c true to enable user-friendly "don't show diffs" mode.
136 */
137 KMediumState state (bool aNoDiffs = false) const
138 {
139 unconst (this)->checkNoDiffs (aNoDiffs);
140 return aNoDiffs ? mNoDiffs.state : mState;
141 }
142
143 QString lastAccessError() const { return mLastAccessError; }
144
145 /**
146 * Result of the last blockAndQueryState() call. Will indicate an error and
147 * contain a proper error info if the last state check fails. In "don't show
148 * diffs" mode, this is the worst result (in terms of inaccessibility)
149 * detected on the given hard disk chain.
150 *
151 * @param aNoDiffs @c true to enable user-friendly "don't show diffs" mode.
152 */
153 const COMResult &result (bool aNoDiffs = false) const
154 {
155 unconst (this)->checkNoDiffs (aNoDiffs);
156 return aNoDiffs ? mNoDiffs.result : mResult;
157 }
158
159 QString id() const { return mId; }
160 QString name (bool aNoDiffs = false) const { return aNoDiffs ? root().mName : mName; }
161 QString location (bool aNoDiffs = false) const { return aNoDiffs ? root().mLocation : mLocation; }
162
163 QString size (bool aNoDiffs = false) const { return aNoDiffs ? root().mSize : mSize; }
164 QString logicalSize (bool aNoDiffs = false) const { return aNoDiffs ? root().mLogicalSize : mLogicalSize; }
165
166 QString hardDiskFormat (bool aNoDiffs = false) const { return aNoDiffs ? root().mHardDiskFormat : mHardDiskFormat; }
167 QString hardDiskType (bool aNoDiffs = false) const { return aNoDiffs ? root().mHardDiskType : mHardDiskType; }
168
169 QString usage (bool aNoDiffs = false) const { return aNoDiffs ? root().mUsage : mUsage; }
170 QString tip() const { return mToolTip; }
171
172 const NoDiffsCache& cache() const { return mNoDiffs; }
173
174 /**
175 * Returns @c true if this medium is read-only (either because it is
176 * Immutable or because it has child hard disks). Read-only media can only
177 * be attached indirectly.
178 */
179 bool isReadOnly() const { return mIsReadOnly; }
180
181 /**
182 * Returns @c true if this medium is attached to any VM (in the current
183 * state or in a snapshot) in which case #usage() will contain a string with
184 * comma-separated VM names (with snapshot names, if any, in parenthesis).
185 */
186 bool isUsed() const { return !mUsage.isNull(); }
187
188 /**
189 * Returns @c true if this medium is attached to any VM in any snapshot.
190 */
191 bool isUsedInSnapshots() const { return mIsUsedInSnapshots; }
192
193 /**
194 * Returns @c true if this medium corresponds to real host drive.
195 */
196 bool isHostDrive() const { return mIsHostDrive; }
197
198 /**
199 * Returns @c true if this medium is attached to the given machine in the current state.
200 */
201 bool isAttachedInCurStateTo (const QString &aMachineId) const { return mCurStateMachineIds.indexOf (aMachineId) >= 0; }
202
203 /**
204 * Returns a vector of IDs of all machines this medium is attached
205 * to in their current state (i.e. excluding snapshots).
206 */
207 const QList <QString> &curStateMachineIds() const { return mCurStateMachineIds; }
208
209 /**
210 * Returns a parent medium. For non-hard disk media, this is always NULL.
211 */
212 VBoxMedium* parent() const { return mParent; }
213
214 VBoxMedium& root() const;
215
216 QString toolTip (bool aNoDiffs = false, bool aCheckRO = false, bool aNullAllowed = false) const;
217 QPixmap icon (bool aNoDiffs = false, bool aCheckRO = false) const;
218
219 /** Shortcut to <tt>#toolTip (aNoDiffs, true)</tt>. */
220 QString toolTipCheckRO (bool aNoDiffs = false, bool aNullAllowed = false) const { return toolTip (aNoDiffs, true, aNullAllowed); }
221
222 /** Shortcut to <tt>#icon (aNoDiffs, true)</tt>. */
223 QPixmap iconCheckRO (bool aNoDiffs = false) const { return icon (aNoDiffs, true); }
224
225 QString details (bool aNoDiffs = false, bool aPredictDiff = false, bool aUseHTML = false) const;
226
227 /** Shortcut to <tt>#details (aNoDiffs, aPredictDiff, true)</tt>. */
228 QString detailsHTML (bool aNoDiffs = false, bool aPredictDiff = false) const { return details (aNoDiffs, aPredictDiff, true); }
229
230 /** Returns @c true if this media descriptor is a null object. */
231 bool isNull() const { return mMedium.isNull(); }
232
233private:
234
235 void checkNoDiffs (bool aNoDiffs);
236
237 CMedium mMedium;
238
239 VBoxDefs::MediumType mType;
240
241 KMediumState mState;
242 QString mLastAccessError;
243 COMResult mResult;
244
245 QString mId;
246 QString mName;
247 QString mLocation;
248
249 QString mSize;
250 QString mLogicalSize;
251
252 QString mHardDiskFormat;
253 QString mHardDiskType;
254
255 QString mUsage;
256 QString mToolTip;
257
258 bool mIsReadOnly : 1;
259 bool mIsUsedInSnapshots : 1;
260 bool mIsHostDrive : 1;
261
262 QList <QString> mCurStateMachineIds;
263
264 VBoxMedium *mParent;
265
266 NoDiffsCache mNoDiffs;
267
268 static QString mTable;
269 static QString mRow;
270};
271
272typedef QLinkedList <VBoxMedium> VBoxMediaList;
273
274#endif /* __VBoxMedium_h__ */
275
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use