VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/snapshots/UISnapshotPane.h@ 102493

Last change on this file since 102493 was 99607, checked in by vboxsync, 17 months ago

FE/Qt: bugref:6832: Snapshot pane: Make sure snapshot-item name is visible on GUI startup or reload triggered while current VM being switched; We had to implement some private functionality cause out-of-the-box Qt was not capable of required thing.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.2 KB
Line 
1/* $Id: UISnapshotPane.h 99607 2023-05-04 14:18:46Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UISnapshotPane class declaration.
4 */
5
6/*
7 * Copyright (C) 2006-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_snapshots_UISnapshotPane_h
29#define FEQT_INCLUDED_SRC_snapshots_UISnapshotPane_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34/* Qt includes: */
35#include <QUuid>
36
37/* GUI includes: */
38#include "QIWithRetranslateUI.h"
39#include "UICommon.h"
40
41/* COM includes: */
42#include "COMEnums.h"
43#include "CMachine.h"
44
45/* Forward declarations: */
46class QIcon;
47class QReadWriteLock;
48class QTimer;
49class QTreeWidgetItem;
50class QVBoxLayout;
51class QIToolBar;
52class QITreeWidgetItem;
53class UIActionPool;
54class UISnapshotDetailsWidget;
55class UISnapshotItem;
56class UISnapshotTree;
57class UIVirtualMachineItem;
58class CSnapshot;
59
60
61/** Snapshot age format. */
62enum SnapshotAgeFormat
63{
64 SnapshotAgeFormat_InSeconds,
65 SnapshotAgeFormat_InMinutes,
66 SnapshotAgeFormat_InHours,
67 SnapshotAgeFormat_InDays,
68 SnapshotAgeFormat_Max
69};
70
71
72/** QWidget extension providing GUI with the pane to control snapshot related functionality. */
73class UISnapshotPane : public QIWithRetranslateUI<QWidget>
74{
75 Q_OBJECT;
76
77signals:
78
79 /** Notifies listeners about current item change. */
80 void sigCurrentItemChange();
81
82public:
83
84 /** Constructs snapshot pane passing @a pParent to the base-class. */
85 UISnapshotPane(UIActionPool *pActionPool, bool fShowToolbar = true, QWidget *pParent = 0);
86 /** Destructs snapshot pane. */
87 virtual ~UISnapshotPane() RT_OVERRIDE;
88
89 /** Defines the machine @a items to be parsed. */
90 void setMachineItems(const QList<UIVirtualMachineItem*> &items);
91
92 /** Returns cached snapshot-item icon depending on @a fOnline flag. */
93 const QIcon *snapshotItemIcon(bool fOnline) const;
94
95 /** Returns whether "current state" item selected. */
96 bool isCurrentStateItemSelected() const;
97
98 /** Returns currently selected snapshot ID if any. */
99 QUuid currentSnapshotId();
100
101protected:
102
103 /** @name Qt event handlers.
104 * @{ */
105 /** Handles translation event. */
106 virtual void retranslateUi() RT_OVERRIDE;
107
108 /** Handles resize @a pEvent. */
109 virtual void resizeEvent(QResizeEvent *pEvent) RT_OVERRIDE;
110
111 /** Handles show @a pEvent. */
112 virtual void showEvent(QShowEvent *pEvent) RT_OVERRIDE;
113 /** @} */
114
115private slots:
116
117 /** @name Main event handlers.
118 * @{ */
119 /** Handles machine data change for machine with @a uMachineId. */
120 void sltHandleMachineDataChange(const QUuid &uMachineId);
121 /** Handles machine @a enmState change for machine with @a uMachineId. */
122 void sltHandleMachineStateChange(const QUuid &uMachineId, const KMachineState enmState);
123
124 /** Handles session @a enmState change for machine with @a uMachineId. */
125 void sltHandleSessionStateChange(const QUuid &uMachineId, const KSessionState enmState);
126
127 /** Handles snapshot take event for machine with @a uMachineId. */
128 void sltHandleSnapshotTake(const QUuid &uMachineId, const QUuid &uSnapshotId);
129 /** Handles snapshot delete event for machine with @a uMachineId. */
130 void sltHandleSnapshotDelete(const QUuid &uMachineId, const QUuid &uSnapshotId);
131 /** Handles snapshot change event for machine with @a uMachineId. */
132 void sltHandleSnapshotChange(const QUuid &uMachineId, const QUuid &uSnapshotId);
133 /** Handles snapshot restore event for machine with @a uMachineId. */
134 void sltHandleSnapshotRestore(const QUuid &uMachineId, const QUuid &uSnapshotId);
135 /** @} */
136
137 /** @name Timer event handlers.
138 * @{ */
139 /** Updates snapshots age. */
140 void sltUpdateSnapshotsAge();
141 /** @} */
142
143 /** @name Toolbar handlers.
144 * @{ */
145 /** Handles command to take a snapshot. */
146 void sltTakeSnapshot() { takeSnapshot(); }
147 /** Handles command to restore the snapshot. */
148 void sltRestoreSnapshot() { restoreSnapshot(); }
149 /** Handles command to delete the snapshot. */
150 void sltDeleteSnapshot() { deleteSnapshot(); }
151 /** Handles command to make snapshot details @a fVisible. */
152 void sltToggleSnapshotDetailsVisibility(bool fVisible);
153 /** Handles command to apply snapshot details changes. */
154 void sltApplySnapshotDetailsChanges();
155 /** @} */
156
157 /** @name Tree-widget handlers.
158 * @{ */
159 /** Handles tree-widget current item change. */
160 void sltHandleCurrentItemChange();
161 /** Handles context menu request for tree-widget @a position. */
162 void sltHandleContextMenuRequest(const QPoint &position);
163 /** Handles tree-widget @a pItem change. */
164 void sltHandleItemChange(QTreeWidgetItem *pItem);
165 /** Handles tree-widget @a pItem double-click. */
166 void sltHandleItemDoubleClick(QTreeWidgetItem *pItem);
167 /** Handles tree-widget's scroll-bar visibility change. */
168 void sltHandleScrollBarVisibilityChange();
169 /** @} */
170
171private:
172
173 /** @name Prepare/cleanup cascade.
174 * @{ */
175 /** Prepares all. */
176 void prepare();
177 /** Prepares connections. */
178 void prepareConnections();
179 /** Prepares actions. */
180 void prepareActions();
181 /** Prepares widgets. */
182 void prepareWidgets();
183 /** Prepares toolbar. */
184 void prepareToolbar();
185 /** Prepares tree-widget. */
186 void prepareTreeWidget();
187 /** Prepares details-widget. */
188 void prepareDetailsWidget();
189 /** Load settings: */
190 void loadSettings();
191
192 /** Refreshes everything. */
193 void refreshAll();
194 /** Populates snapshot items for corresponding @a comSnapshot using @a pItem as parent. */
195 void populateSnapshots(const QUuid &uMachineId, const CSnapshot &comSnapshot, QITreeWidgetItem *pItem);
196
197 /** Cleanups all. */
198 void cleanup();
199 /** @} */
200
201 /** @name Toolbar helpers.
202 * @{ */
203 /** Updates action states. */
204 void updateActionStates();
205
206 /** Proposes to take a snapshot. */
207 bool takeSnapshot(bool fAutomatically = false);
208 /** Proposes to delete the snapshot. */
209 bool deleteSnapshot(bool fAutomatically = false);
210 /** Proposes to restore the snapshot. */
211 bool restoreSnapshot(bool fAutomatically = false);
212 /** @} */
213
214 /** @name Tree-widget helpers.
215 * @{ */
216 /** Handles command to adjust snapshot tree. */
217 void adjustTreeWidget();
218
219 /** Searches for an item with corresponding @a uSnapshotID. */
220 UISnapshotItem *findItem(const QUuid &uSnapshotID) const;
221
222 /** Searches for smallest snapshot age starting with @a pItem as parent. */
223 SnapshotAgeFormat traverseSnapshotAge(QTreeWidgetItem *pItem) const;
224
225 /** Expand all the children starting with @a pItem. */
226 void expandItemChildren(QTreeWidgetItem *pItem);
227 /** @} */
228
229 /** @name General variables.
230 * @{ */
231 /** Holds the action-pool reference. */
232 UIActionPool *m_pActionPool;
233 /** Holds whether we should show toolbar. */
234 bool m_fShowToolbar;
235
236 /** Holds the COM machine object list. */
237 QMap<QUuid, CMachine> m_machines;
238 /** Holds the cached session state list. */
239 QMap<QUuid, KSessionState> m_sessionStates;
240 /** Holds the list of operation allowance states. */
241 QMap<QUuid, bool> m_operationAllowed;
242
243 /** Holds the snapshot item editing protector. */
244 QReadWriteLock *m_pLockReadWrite;
245
246 /** Holds the cached snapshot-item pixmap for 'offline' state. */
247 QIcon *m_pIconSnapshotOffline;
248 /** Holds the cached snapshot-item pixmap for 'online' state. */
249 QIcon *m_pIconSnapshotOnline;
250
251 /** Holds the snapshot age update timer. */
252 QTimer *m_pTimerUpdateAge;
253 /** @} */
254
255 /** @name Widget variables.
256 * @{ */
257 /** Holds the main layout instance. */
258 QVBoxLayout *m_pLayoutMain;
259
260 /** Holds the toolbar instance. */
261 QIToolBar *m_pToolBar;
262
263 /** Holds the snapshot tree instance. */
264 UISnapshotTree *m_pSnapshotTree;
265
266 /** Holds the "current snapshot" item list. */
267 QMap<QUuid, UISnapshotItem*> m_currentSnapshotItems;
268 /** Holds the "current state" item list. */
269 QMap<QUuid, UISnapshotItem*> m_currentStateItems;
270
271 /** Holds the details-widget instance. */
272 UISnapshotDetailsWidget *m_pDetailsWidget;
273 /** @} */
274};
275
276#endif /* !FEQT_INCLUDED_SRC_snapshots_UISnapshotPane_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