VirtualBox

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

Last change on this file was 103977, checked in by vboxsync, 2 months ago

Apply RT_OVERRIDE/NS_OVERRIDE where required to shut up clang.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use