VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumItem.h@ 82781

Last change on this file since 82781 was 78374, checked in by vboxsync, 5 years ago

FE/Qt: bugref:8400. Reataching the medium to the vms after a medium type change.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.1 KB
Line 
1/* $Id: UIMediumItem.h 78374 2019-05-03 11:41:50Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIMediumItem class declaration.
4 */
5
6/*
7 * Copyright (C) 2009-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef FEQT_INCLUDED_SRC_medium_UIMediumItem_h
19#define FEQT_INCLUDED_SRC_medium_UIMediumItem_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24/* GUI includes: */
25#include "UIMedium.h"
26#include "UIMediumDetailsWidget.h"
27#include "QITreeWidget.h"
28
29/** QITreeWidgetItem extension representing Media Manager item. */
30class SHARED_LIBRARY_STUFF UIMediumItem : public QITreeWidgetItem, public UIDataMedium
31{
32 Q_OBJECT;
33
34public:
35
36 /** Constructs top-level item.
37 * @param guiMedium Brings the medium to wrap around.
38 * @param pParent Brings the parent tree reference. */
39 UIMediumItem(const UIMedium &guiMedium, QITreeWidget *pParent);
40 /** Constructs sub-level item.
41 * @param guiMedium Brings the medium to wrap around.
42 * @param pParent Brings the parent item reference. */
43 UIMediumItem(const UIMedium &guiMedium, UIMediumItem *pParent);
44 /** Constructs sub-level item under a QITreeWidgetItem.
45 * @param guiMedium Brings the medium to wrap around.
46 * @param pParent Brings the parent item reference. */
47 UIMediumItem(const UIMedium &guiMedium, QITreeWidgetItem *pParent);
48
49 /** Copies UIMedium wrapped by <i>this</i> item. */
50 //virtual bool copy();
51 /** Moves UIMedium wrapped by <i>this</i> item. */
52 virtual bool move();
53 /** Removes UIMedium wrapped by <i>this</i> item. */
54 virtual bool remove() = 0;
55 /** Releases UIMedium wrapped by <i>this</i> item.
56 * @param fInduced Brings whether this action is caused by other user's action,
57 * not a direct order to release particularly selected medium. */
58 virtual bool release(bool fInduced = false);
59
60 /** Refreshes item fully. */
61 void refreshAll();
62
63 /** Returns UIMedium wrapped by <i>this</i> item. */
64 const UIMedium &medium() const { return m_guiMedium; }
65 /** Defines UIMedium wrapped by <i>this</i> item. */
66 void setMedium(const UIMedium &guiMedium);
67
68 /** Returns UIMediumDeviceType of the wrapped UIMedium. */
69 UIMediumDeviceType mediumType() const { return m_guiMedium.type(); }
70
71 /** Returns KMediumState of the wrapped UIMedium. */
72 KMediumState state() const { return m_guiMedium.state(); }
73
74 /** Returns QUuid <i>ID</i> of the wrapped UIMedium. */
75 QUuid id() const { return m_guiMedium.id(); }
76 /** Returns QString <i>name</i> of the wrapped UIMedium. */
77 QString name() const { return m_guiMedium.name(); }
78
79 /** Returns QString <i>location</i> of the wrapped UIMedium. */
80 QString location() const { return m_guiMedium.location(); }
81
82 /** Returns QString <i>hard-disk format</i> of the wrapped UIMedium. */
83 QString hardDiskFormat() const { return m_guiMedium.hardDiskFormat(); }
84 /** Returns QString <i>hard-disk type</i> of the wrapped UIMedium. */
85 QString hardDiskType() const { return m_guiMedium.hardDiskType(); }
86
87 /** Returns QString <i>storage details</i> of the wrapped UIMedium. */
88 QString details() const { return m_guiMedium.storageDetails(); }
89 /** Returns QString <i>encryption password ID</i> of the wrapped UIMedium. */
90 QString encryptionPasswordID() const { return m_guiMedium.encryptionPasswordID(); }
91
92 /** Returns QString <i>tool-tip</i> of the wrapped UIMedium. */
93 QString toolTip() const { return m_guiMedium.toolTip(); }
94
95 /** Returns a vector of IDs of all machines wrapped UIMedium is attached to. */
96 const QList<QUuid> &machineIds() const { return m_guiMedium.machineIds(); }
97 /** Returns QString <i>usage</i> of the wrapped UIMedium. */
98 QString usage() const { return m_guiMedium.usage(); }
99 /** Returns whether wrapped UIMedium is used. */
100 bool isUsed() const { return m_guiMedium.isUsed(); }
101 /** Returns whether wrapped UIMedium is used in snapshots. */
102 bool isUsedInSnapshots() const { return m_guiMedium.isUsedInSnapshots(); }
103
104 /** Returns whether <i>this</i> item is less than @a other one. */
105 bool operator<(const QTreeWidgetItem &other) const;
106 /** Returns whether the medium can be modified. For
107 * simplicity's sake this returns false if one of the attached vms is not
108 * in PoweredOff or Aborted state. */
109 bool isMediumModifiable() const;
110 /** Returns true if the medium is attached to the vm with @p uId. */
111 bool isMediumAttachedTo(QUuid uId);
112 bool changeMediumType(KMediumType enmOldType, KMediumType enmNewType);
113
114protected:
115
116 /** Release UIMedium wrapped by <i>this</i> item from virtual @a comMachine. */
117 virtual bool releaseFrom(CMachine comMachine) = 0;
118
119 /** Returns default text. */
120 virtual QString defaultText() const /* override */;
121
122private:
123 /** A simple struct used to save some parameters of machine device attachment.
124 * Used for re-attaching the medium to vms after a medium type change. */
125 struct AttachmentCache
126 {
127 QString m_strControllerName;
128 QUuid m_uMachineId;
129 LONG m_port;
130 LONG m_device;
131 };
132
133 /** Refreshes item information such as icon, text and tool-tip. */
134 void refresh();
135
136 /** Releases UIMedium wrapped by <i>this</i> item from virtual machine with @a uMachineId. */
137 bool releaseFrom(const QUuid &uMachineId);
138 /** Is called by detaching the medium and modifiying it to restore the attachement. */
139 bool attachTo(const AttachmentCache &attachmentCache);
140
141 /** Formats field text. */
142 static QString formatFieldText(const QString &strText, bool fCompact = true, const QString &strElipsis = "middle");
143
144 /** Holds the UIMedium wrapped by <i>this</i> item. */
145 UIMedium m_guiMedium;
146};
147
148
149/** UIMediumItem extension representing hard-disk item. */
150class SHARED_LIBRARY_STUFF UIMediumItemHD : public UIMediumItem
151{
152public:
153
154 /** Constructs top-level item.
155 * @param guiMedium Brings the medium to wrap around.
156 * @param pParent Brings the parent tree reference. */
157 UIMediumItemHD(const UIMedium &guiMedium, QITreeWidget *pParent);
158 /** Constructs sub-level item.
159 * @param guiMedium Brings the medium to wrap around.
160 * @param pParent Brings the parent item reference. */
161 UIMediumItemHD(const UIMedium &guiMedium, UIMediumItem *pParent);
162 /** Constructs sub-level item under a QITreeWidgetItem.
163 * @param guiMedium Brings the medium to wrap around.
164 * @param pParent Brings the parent item reference. */
165 UIMediumItemHD(const UIMedium &guiMedium, QITreeWidgetItem *pParent);
166
167protected:
168
169 /** Removes UIMedium wrapped by <i>this</i> item. */
170 virtual bool remove() /* override */;
171 /** Releases UIMedium wrapped by <i>this</i> item from virtual @a comMachine. */
172 virtual bool releaseFrom(CMachine comMachine) /* override */;
173
174private:
175
176 /** Proposes user to remove CMedium storage wrapped by <i>this</i> item. */
177 bool maybeRemoveStorage();
178};
179
180/** UIMediumItem extension representing optical-disk item. */
181class SHARED_LIBRARY_STUFF UIMediumItemCD : public UIMediumItem
182{
183public:
184
185 /** Constructs top-level item.
186 * @param guiMedium Brings the medium to wrap around.
187 * @param pParent Brings the parent tree reference. */
188 UIMediumItemCD(const UIMedium &guiMedium, QITreeWidget *pParent);
189 /** Constructs sub-level item under a QITreeWidgetItem.
190 * @param guiMedium Brings the medium to wrap around.
191 * @param pParent Brings the parent item reference. */
192 UIMediumItemCD(const UIMedium &guiMedium, QITreeWidgetItem *pParent);
193
194protected:
195
196 /** Removes UIMedium wrapped by <i>this</i> item. */
197 virtual bool remove() /* override */;
198 /** Releases UIMedium wrapped by <i>this</i> item from virtual @a comMachine. */
199 virtual bool releaseFrom(CMachine comMachine) /* override */;
200};
201
202/** UIMediumItem extension representing floppy-disk item. */
203class SHARED_LIBRARY_STUFF UIMediumItemFD : public UIMediumItem
204{
205public:
206
207 /** Constructs top-level item.
208 * @param guiMedium Brings the medium to wrap around.
209 * @param pParent Brings the parent tree reference. */
210 UIMediumItemFD(const UIMedium &guiMedium, QITreeWidget *pParent);
211 /** Constructs sub-level item under a QITreeWidgetItem.
212 * @param guiMedium Brings the medium to wrap around.
213 * @param pParent Brings the parent item reference. */
214 UIMediumItemFD(const UIMedium &guiMedium, QITreeWidgetItem *pParent);
215
216protected:
217
218 /** Removes UIMedium wrapped by <i>this</i> item. */
219 virtual bool remove() /* override */;
220 /** Releases UIMedium wrapped by <i>this</i> item from virtual @a comMachine. */
221 virtual bool releaseFrom(CMachine comMachine) /* override */;
222};
223
224#endif /* !FEQT_INCLUDED_SRC_medium_UIMediumItem_h */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use