[17384] | 1 | /** @file
|
---|
| 2 | *
|
---|
| 3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
| 4 | * VBoxMedium class declaration
|
---|
| 5 | */
|
---|
| 6 |
|
---|
| 7 | /*
|
---|
[28800] | 8 | * Copyright (C) 2009 Oracle Corporation
|
---|
[17384] | 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 |
|
---|
[23223] | 22 | /* Global includes */
|
---|
[17384] | 23 | #include <QPixmap>
|
---|
[17385] | 24 | #include <QLinkedList>
|
---|
[17384] | 25 |
|
---|
[23223] | 26 | /* Local includes */
|
---|
| 27 | #include "COMDefs.h"
|
---|
| 28 |
|
---|
[30681] | 29 | #include <iprt/cpp/utils.h>
|
---|
| 30 |
|
---|
[17384] | 31 | /**
|
---|
[24294] | 32 | * Cache used to override some attributes in the user-friendly "don't show diffs" mode.
|
---|
| 33 | */
|
---|
| 34 | struct 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 | /**
|
---|
[17384] | 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 | *
|
---|
[23223] | 68 | * Note that this class "abuses" the KMediumState_NotCreated state value to
|
---|
[17384] | 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
|
---|
[23223] | 72 | * accessible medium. The real KMediumState_NotCreated state is not necessary
|
---|
[17384] | 73 | * because this class is only used with created (existing) media.
|
---|
| 74 | */
|
---|
| 75 | class VBoxMedium
|
---|
| 76 | {
|
---|
| 77 | public:
|
---|
| 78 |
|
---|
| 79 | /**
|
---|
| 80 | * Creates a null medium descriptor which is not associated with any medium.
|
---|
[23223] | 81 | * The state field is set to KMediumState_NotCreated.
|
---|
[17384] | 82 | */
|
---|
| 83 | VBoxMedium()
|
---|
[23223] | 84 | : mType (VBoxDefs::MediumType_Invalid)
|
---|
| 85 | , mState (KMediumState_NotCreated)
|
---|
| 86 | , mIsReadOnly (false)
|
---|
| 87 | , mIsUsedInSnapshots (false)
|
---|
| 88 | , mParent (0) { refresh(); }
|
---|
[17384] | 89 |
|
---|
| 90 | /**
|
---|
| 91 | * Creates a media descriptor associated with the given medium.
|
---|
| 92 | *
|
---|
[23223] | 93 | * The state field remain KMediumState_NotCreated until #blockAndQueryState()
|
---|
[17384] | 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 | */
|
---|
[23223] | 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(); }
|
---|
[17384] | 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 | */
|
---|
[23223] | 114 | VBoxMedium (const CMedium &aMedium, VBoxDefs::MediumType aType, KMediumState aState)
|
---|
| 115 | : mMedium (aMedium)
|
---|
| 116 | , mType (aType)
|
---|
[17384] | 117 | , mState (aState)
|
---|
[23223] | 118 | , mIsReadOnly (false)
|
---|
| 119 | , mIsUsedInSnapshots (false)
|
---|
| 120 | , mParent (0) { refresh(); }
|
---|
[17384] | 121 |
|
---|
[24294] | 122 | VBoxMedium& operator= (const VBoxMedium &aOther);
|
---|
| 123 |
|
---|
[17384] | 124 | void blockAndQueryState();
|
---|
| 125 | void refresh();
|
---|
| 126 |
|
---|
[23223] | 127 | const CMedium &medium() const { return mMedium; }
|
---|
[17384] | 128 |
|
---|
[23223] | 129 | VBoxDefs::MediumType type() const { return mType; }
|
---|
[17384] | 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 | */
|
---|
[23223] | 137 | KMediumState state (bool aNoDiffs = false) const
|
---|
[17384] | 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 |
|
---|
[19239] | 159 | QString id() const { return mId; }
|
---|
[23223] | 160 | QString name (bool aNoDiffs = false) const { return aNoDiffs ? root().mName : mName; }
|
---|
| 161 | QString location (bool aNoDiffs = false) const { return aNoDiffs ? root().mLocation : mLocation; }
|
---|
[24294] | 162 |
|
---|
[23223] | 163 | QString size (bool aNoDiffs = false) const { return aNoDiffs ? root().mSize : mSize; }
|
---|
| 164 | QString logicalSize (bool aNoDiffs = false) const { return aNoDiffs ? root().mLogicalSize : mLogicalSize; }
|
---|
[24294] | 165 |
|
---|
[23223] | 166 | QString hardDiskFormat (bool aNoDiffs = false) const { return aNoDiffs ? root().mHardDiskFormat : mHardDiskFormat; }
|
---|
| 167 | QString hardDiskType (bool aNoDiffs = false) const { return aNoDiffs ? root().mHardDiskType : mHardDiskType; }
|
---|
[24294] | 168 |
|
---|
[23223] | 169 | QString usage (bool aNoDiffs = false) const { return aNoDiffs ? root().mUsage : mUsage; }
|
---|
[24294] | 170 | QString tip() const { return mToolTip; }
|
---|
[17384] | 171 |
|
---|
[24294] | 172 | const NoDiffsCache& cache() const { return mNoDiffs; }
|
---|
| 173 |
|
---|
[17384] | 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
|
---|
[33540] | 184 | * comma-separated VM names (with snapshot names, if any, in parenthesis).
|
---|
[17384] | 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 | /**
|
---|
[23223] | 194 | * Returns @c true if this medium corresponds to real host drive.
|
---|
[17384] | 195 | */
|
---|
[23223] | 196 | bool isHostDrive() const { return mIsHostDrive; }
|
---|
[17384] | 197 |
|
---|
| 198 | /**
|
---|
[23223] | 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 | /**
|
---|
[17384] | 204 | * Returns a vector of IDs of all machines this medium is attached
|
---|
| 205 | * to in their current state (i.e. excluding snapshots).
|
---|
| 206 | */
|
---|
[23223] | 207 | const QList <QString> &curStateMachineIds() const { return mCurStateMachineIds; }
|
---|
[17384] | 208 |
|
---|
| 209 | /**
|
---|
| 210 | * Returns a parent medium. For non-hard disk media, this is always NULL.
|
---|
| 211 | */
|
---|
[24294] | 212 | VBoxMedium* parent() const { return mParent; }
|
---|
[17384] | 213 |
|
---|
[24294] | 214 | VBoxMedium& root() const;
|
---|
[17384] | 215 |
|
---|
[23585] | 216 | QString toolTip (bool aNoDiffs = false, bool aCheckRO = false, bool aNullAllowed = false) const;
|
---|
[17384] | 217 | QPixmap icon (bool aNoDiffs = false, bool aCheckRO = false) const;
|
---|
| 218 |
|
---|
| 219 | /** Shortcut to <tt>#toolTip (aNoDiffs, true)</tt>. */
|
---|
[23585] | 220 | QString toolTipCheckRO (bool aNoDiffs = false, bool aNullAllowed = false) const { return toolTip (aNoDiffs, true, aNullAllowed); }
|
---|
[17384] | 221 |
|
---|
| 222 | /** Shortcut to <tt>#icon (aNoDiffs, true)</tt>. */
|
---|
[23223] | 223 | QPixmap iconCheckRO (bool aNoDiffs = false) const { return icon (aNoDiffs, true); }
|
---|
[17384] | 224 |
|
---|
[23223] | 225 | QString details (bool aNoDiffs = false, bool aPredictDiff = false, bool aUseHTML = false) const;
|
---|
[17384] | 226 |
|
---|
| 227 | /** Shortcut to <tt>#details (aNoDiffs, aPredictDiff, true)</tt>. */
|
---|
[23223] | 228 | QString detailsHTML (bool aNoDiffs = false, bool aPredictDiff = false) const { return details (aNoDiffs, aPredictDiff, true); }
|
---|
[17384] | 229 |
|
---|
| 230 | /** Returns @c true if this media descriptor is a null object. */
|
---|
| 231 | bool isNull() const { return mMedium.isNull(); }
|
---|
| 232 |
|
---|
| 233 | private:
|
---|
| 234 |
|
---|
| 235 | void checkNoDiffs (bool aNoDiffs);
|
---|
| 236 |
|
---|
| 237 | CMedium mMedium;
|
---|
| 238 |
|
---|
[23223] | 239 | VBoxDefs::MediumType mType;
|
---|
[17384] | 240 |
|
---|
[23223] | 241 | KMediumState mState;
|
---|
[17384] | 242 | QString mLastAccessError;
|
---|
| 243 | COMResult mResult;
|
---|
| 244 |
|
---|
[19239] | 245 | QString mId;
|
---|
[24294] | 246 | QString mName;
|
---|
[17384] | 247 | QString mLocation;
|
---|
[24294] | 248 |
|
---|
[17384] | 249 | QString mSize;
|
---|
[24294] | 250 | QString mLogicalSize;
|
---|
[17384] | 251 |
|
---|
| 252 | QString mHardDiskFormat;
|
---|
| 253 | QString mHardDiskType;
|
---|
| 254 |
|
---|
| 255 | QString mUsage;
|
---|
| 256 | QString mToolTip;
|
---|
| 257 |
|
---|
| 258 | bool mIsReadOnly : 1;
|
---|
| 259 | bool mIsUsedInSnapshots : 1;
|
---|
[23223] | 260 | bool mIsHostDrive : 1;
|
---|
[17384] | 261 |
|
---|
[19239] | 262 | QList <QString> mCurStateMachineIds;
|
---|
[17384] | 263 |
|
---|
| 264 | VBoxMedium *mParent;
|
---|
| 265 |
|
---|
[24294] | 266 | NoDiffsCache mNoDiffs;
|
---|
[17384] | 267 |
|
---|
[24294] | 268 | static QString mTable;
|
---|
| 269 | static QString mRow;
|
---|
[17384] | 270 | };
|
---|
| 271 |
|
---|
| 272 | typedef QLinkedList <VBoxMedium> VBoxMediaList;
|
---|
| 273 |
|
---|
| 274 | #endif /* __VBoxMedium_h__ */
|
---|
| 275 |
|
---|