VirtualBox

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

Last change on this file since 24511 was 24294, checked in by vboxsync, 15 years ago

FE/Qt4: VBoxMedium cumulative patch: fixed tool-tip regression (for complex tool-tips) caused by Qt bugs related to html <nobr> tag ignoring; Possible fixed crash while copying CMedium object wrapped in VBoxMedium extension.

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

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