3
* VBox frontends: Qt GUI ("VirtualBox"):
4
* VBoxMedium class declaration
8
* Copyright (C) 2009 Sun Microsystems, Inc.
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.
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.
23
#ifndef __VBoxMedium_h__
24
#define __VBoxMedium_h__
30
#include <QLinkedList>
33
* Media descriptor for the GUI.
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
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
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.
59
* Creates a null medium descriptor which is not associated with any medium.
60
* The state field is set to KMediaState_NotCreated.
63
: mType (VBoxDefs::MediaType_Invalid)
64
, mState (KMediaState_NotCreated)
65
, mIsReadOnly (false), mIsUsedInSnapshots (false)
69
* Creates a media descriptor associated with the given medium.
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.
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
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(); }
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
91
VBoxMedium (const CMedium &aMedium, VBoxDefs::MediaType aType,
93
: mMedium (aMedium), mType (aType)
95
, mIsReadOnly (false), mIsUsedInSnapshots (false)
96
, mParent (NULL) { init(); }
98
void blockAndQueryState();
101
const CMedium &medium() const { return mMedium; };
103
VBoxDefs::MediaType type() const { return mType; }
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.
109
* @param aNoDiffs @c true to enable user-friendly "don't show diffs" mode.
111
KMediaState state (bool aNoDiffs = false) const
113
unconst (this)->checkNoDiffs (aNoDiffs);
114
return aNoDiffs ? mNoDiffs.state : mState;
117
QString lastAccessError() const { return mLastAccessError; }
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.
125
* @param aNoDiffs @c true to enable user-friendly "don't show diffs" mode.
127
const COMResult &result (bool aNoDiffs = false) const
129
unconst (this)->checkNoDiffs (aNoDiffs);
130
return aNoDiffs ? mNoDiffs.result : mResult;
133
const CHardDisk &hardDisk() const { return mHardDisk; }
134
const CDVDImage &dvdImage() const { return mDVDImage; }
135
const CFloppyImage &floppyImage() const { return mFloppyImage; }
137
QString id() const { return mId; }
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; }
144
QString size (bool aNoDiffs = false) const
145
{ return aNoDiffs ? root().mSize : mSize; }
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; }
154
QString usage (bool aNoDiffs = false) const
155
{ return aNoDiffs ? root().mUsage : mUsage; }
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.
162
bool isReadOnly() const { return mIsReadOnly; }
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).
169
bool isUsed() const { return !mUsage.isNull(); }
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.
175
bool isUsedInSnapshots() const { return mIsUsedInSnapshots; }
178
* Returns @c true if this medium is attached to the given machine in the
181
bool isAttachedInCurStateTo (const QString &aMachineId) const
182
{ return mCurStateMachineIds.indexOf (aMachineId) >= 0; }
185
* Returns a vector of IDs of all machines this medium is attached
186
* to in their current state (i.e. excluding snapshots).
188
const QList <QString> &curStateMachineIds() const
189
{ return mCurStateMachineIds; }
192
* Returns a parent medium. For non-hard disk media, this is always NULL.
194
VBoxMedium *parent() const { return mParent; }
196
VBoxMedium &root() const;
198
QString toolTip(bool aNoDiffs = false, bool aCheckRO = false) const;
199
QPixmap icon (bool aNoDiffs = false, bool aCheckRO = false) const;
201
/** Shortcut to <tt>#toolTip (aNoDiffs, true)</tt>. */
202
QString toolTipCheckRO (bool aNoDiffs = false) const
203
{ return toolTip (aNoDiffs, true); }
205
/** Shortcut to <tt>#icon (aNoDiffs, true)</tt>. */
206
QPixmap iconCheckRO (bool aNoDiffs = false) const
207
{ return icon (aNoDiffs, true); }
209
QString details (bool aNoDiffs = false, bool aPredictDiff = false,
210
bool aUseHTML = false) const;
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); }
216
/** Returns @c true if this media descriptor is a null object. */
217
bool isNull() const { return mMedium.isNull(); }
223
void checkNoDiffs (bool aNoDiffs);
227
VBoxDefs::MediaType mType;
230
QString mLastAccessError;
235
CFloppyImage mFloppyImage;
242
QString mHardDiskFormat;
243
QString mHardDiskType;
244
QString mLogicalSize;
249
bool mIsReadOnly : 1;
250
bool mIsUsedInSnapshots : 1;
252
QList <QString> mCurStateMachineIds;
257
* Used to override some attributes in the user-friendly "don't show diffs"
262
NoDiffs() : isSet (false), state (KMediaState_NotCreated) {}
273
typedef QLinkedList <VBoxMedium> VBoxMediaList;
275
#endif /* __VBoxMedium_h__ */