1 | /* $Id: UISnapshotPane.h 63838 2016-09-14 16:51:05Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UISnapshotPane class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2016 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 ___UISnapshotPane_h___
|
---|
19 | #define ___UISnapshotPane_h___
|
---|
20 |
|
---|
21 | /* Qt includes: */
|
---|
22 | #include <QIcon>
|
---|
23 | #include <QTimer>
|
---|
24 | #include <QReadWriteLock>
|
---|
25 |
|
---|
26 | /* GUI includes: */
|
---|
27 | #include "QIWithRetranslateUI.h"
|
---|
28 | #include "VBoxGlobal.h"
|
---|
29 |
|
---|
30 | /* COM includes: */
|
---|
31 | #include "CMachine.h"
|
---|
32 |
|
---|
33 | /* Forward declarations: */
|
---|
34 | class QTreeWidget;
|
---|
35 | class QTreeWidgetItem;
|
---|
36 | class SnapshotWgtItem;
|
---|
37 |
|
---|
38 |
|
---|
39 | /** Snapshot age format. */
|
---|
40 | enum SnapshotAgeFormat
|
---|
41 | {
|
---|
42 | SnapshotAgeFormat_InSeconds,
|
---|
43 | SnapshotAgeFormat_InMinutes,
|
---|
44 | SnapshotAgeFormat_InHours,
|
---|
45 | SnapshotAgeFormat_InDays,
|
---|
46 | SnapshotAgeFormat_Max
|
---|
47 | };
|
---|
48 |
|
---|
49 |
|
---|
50 | /** QWidget extension providing GUI with the pane to control snapshot related functionality. */
|
---|
51 | class UISnapshotPane : public QIWithRetranslateUI<QWidget>
|
---|
52 | {
|
---|
53 | Q_OBJECT;
|
---|
54 |
|
---|
55 | public:
|
---|
56 |
|
---|
57 | /** Constructs snapshot pane passing @a pParent to the base-class. */
|
---|
58 | UISnapshotPane(QWidget *pParent);
|
---|
59 |
|
---|
60 | /** Defines the @a comMachine to be parsed. */
|
---|
61 | void setMachine(const CMachine &comMachine);
|
---|
62 |
|
---|
63 | /** Returns cached snapshot-item icon depending on @a fOnline flag. */
|
---|
64 | const QIcon &snapshotItemIcon(bool fOnline) const { return !fOnline ? m_snapshotIconOffline : m_snapshotIconOnline; }
|
---|
65 |
|
---|
66 | protected:
|
---|
67 |
|
---|
68 | /** Handles translation event. */
|
---|
69 | virtual void retranslateUi() /* override */;
|
---|
70 |
|
---|
71 | private slots:
|
---|
72 |
|
---|
73 | /** @name Tree-view handlers
|
---|
74 | * @{ */
|
---|
75 | /** Handles cursor change to @a pItem. */
|
---|
76 | void sltCurrentItemChanged(QTreeWidgetItem *pItem = 0);
|
---|
77 | /** Handles context menu request for @a point. */
|
---|
78 | void sltContextMenuRequested(const QPoint &point);
|
---|
79 | /** Handles modification for @a pItem. */
|
---|
80 | void sltItemChanged(QTreeWidgetItem *pItem);
|
---|
81 | /** Handles double-click for @a pItem. */
|
---|
82 | void sltItemDoubleClicked(QTreeWidgetItem *pItem);
|
---|
83 | /** @} */
|
---|
84 |
|
---|
85 | /** @name Main event handlers
|
---|
86 | * @{ */
|
---|
87 | /** Handles machine data change for machine with @a strMachineID. */
|
---|
88 | void sltMachineDataChange(QString strMachineID);
|
---|
89 | /** Handles machine @a enmState change for machine with @a strMachineID. */
|
---|
90 | void sltMachineStateChange(QString strMachineID, KMachineState enmState);
|
---|
91 | /** Handles session @a enmState change for machine with @a strMachineID. */
|
---|
92 | void sltSessionStateChange(QString strMachineID, KSessionState enmState);
|
---|
93 | /** @} */
|
---|
94 |
|
---|
95 | /** @name Timer event handlers
|
---|
96 | * @{ */
|
---|
97 | /** Updates snapshots age. */
|
---|
98 | void sltUpdateSnapshotsAge();
|
---|
99 | /** @} */
|
---|
100 |
|
---|
101 | /** @name Snapshot operations
|
---|
102 | * @{ */
|
---|
103 | /** Proposes to take a snapshot. */
|
---|
104 | void sltTakeSnapshot() { takeSnapshot(); }
|
---|
105 | /** Proposes to restore the snapshot. */
|
---|
106 | void sltRestoreSnapshot() { restoreSnapshot(); }
|
---|
107 | /** Proposes to delete the snapshot. */
|
---|
108 | void sltDeleteSnapshot() { deleteSnapshot(); }
|
---|
109 | /** Displays the snapshot details dialog. */
|
---|
110 | void sltShowSnapshotDetails() { showSnapshotDetails(); }
|
---|
111 | /** Proposes to clone the snapshot. */
|
---|
112 | void sltCloneSnapshot() { cloneSnapshot(); }
|
---|
113 | /** @} */
|
---|
114 |
|
---|
115 | private:
|
---|
116 |
|
---|
117 | /** @name Snapshot operations
|
---|
118 | * @{ */
|
---|
119 | /** Proposes to take a snapshot. */
|
---|
120 | bool takeSnapshot();
|
---|
121 | /** Proposes to restore the snapshot. */
|
---|
122 | bool restoreSnapshot(bool fSuppressNonCriticalWarnings = false);
|
---|
123 | /** Proposes to delete the snapshot. */
|
---|
124 | bool deleteSnapshot();
|
---|
125 | /** Displays the snapshot details dialog. */
|
---|
126 | void showSnapshotDetails();
|
---|
127 | /** Proposes to clone the snapshot. */
|
---|
128 | void cloneSnapshot();
|
---|
129 | /** @} */
|
---|
130 |
|
---|
131 | /** Refreshes everything. */
|
---|
132 | void refreshAll();
|
---|
133 | /** Populates snapshot items for corresponding @a comSnapshot using @a pItem as parent. */
|
---|
134 | void populateSnapshots(const CSnapshot &comSnapshot, QTreeWidgetItem *pItem);
|
---|
135 |
|
---|
136 | /** Searches for an item with corresponding @a strSnapshotID. */
|
---|
137 | SnapshotWgtItem *findItem(const QString &strSnapshotID) const;
|
---|
138 | /** Returns the "current state" item. */
|
---|
139 | SnapshotWgtItem *currentStateItem() const;
|
---|
140 |
|
---|
141 | /** Searches for smallest snapshot age starting with @a pItem as parent. */
|
---|
142 | SnapshotAgeFormat traverseSnapshotAge(QTreeWidgetItem *pItem) const;
|
---|
143 |
|
---|
144 | /** Casts QTreeWidgetItem to SnapshotWgtItem if possible. */
|
---|
145 | static SnapshotWgtItem *toSnapshotItem(QTreeWidgetItem *pItem);
|
---|
146 | /** Casts const QTreeWidgetItem to const SnapshotWgtItem if possible. */
|
---|
147 | static const SnapshotWgtItem *toSnapshotItem(const QTreeWidgetItem *pItem);
|
---|
148 |
|
---|
149 | /** Holds the machine COM wrapper. */
|
---|
150 | CMachine m_comMachine;
|
---|
151 | /** Holds the machine ID. */
|
---|
152 | QString m_strMachineID;
|
---|
153 | /** Holds the cached session state. */
|
---|
154 | KSessionState m_enmSessionState;
|
---|
155 | /** Holds the current snapshot item reference. */
|
---|
156 | SnapshotWgtItem *m_pCurrentSnapshotItem;
|
---|
157 | /** Holds the snapshot item editing protector. */
|
---|
158 | QReadWriteLock m_lockReadWrite;
|
---|
159 |
|
---|
160 | /** Holds the snapshot item action group instance. */
|
---|
161 | QActionGroup *m_pSnapshotItemActionGroup;
|
---|
162 | /** Holds the current item action group instance. */
|
---|
163 | QActionGroup *m_pCurrentStateItemActionGroup;
|
---|
164 |
|
---|
165 | /** Holds the snapshot take action instance. */
|
---|
166 | QAction *m_pActionTakeSnapshot;
|
---|
167 | /** Holds the snapshot restore action instance. */
|
---|
168 | QAction *m_pActionRestoreSnapshot;
|
---|
169 | /** Holds the snapshot delete action instance. */
|
---|
170 | QAction *m_pActionDeleteSnapshot;
|
---|
171 | /** Holds the show snapshot details action instance. */
|
---|
172 | QAction *m_pActionShowSnapshotDetails;
|
---|
173 | /** Holds the snapshot clone action instance. */
|
---|
174 | QAction *m_pActionCloneSnapshot;
|
---|
175 |
|
---|
176 | /** Holds the snapshot age update timer. */
|
---|
177 | QTimer m_ageUpdateTimer;
|
---|
178 |
|
---|
179 | /** Holds whether the snapshot operations are allowed. */
|
---|
180 | bool m_fShapshotOperationsAllowed;
|
---|
181 |
|
---|
182 | /** Holds the cached snapshot-item pixmap for 'offline' state. */
|
---|
183 | QIcon m_snapshotIconOffline;
|
---|
184 | /** Holds the cached snapshot-item pixmap for 'online' state. */
|
---|
185 | QIcon m_snapshotIconOnline;
|
---|
186 |
|
---|
187 | /** Holds the tree-widget instance. */
|
---|
188 | QTreeWidget *m_pTreeWidget;
|
---|
189 | };
|
---|
190 |
|
---|
191 | #endif /* !___UISnapshotPane_h___ */
|
---|
192 |
|
---|