VirtualBox

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

Last change on this file since 17384 was 17384, checked in by vboxsync, 16 years ago

FE/Qt4: split VBoxMedium out of VBoxGlobal

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

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