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