summaryrefslogtreecommitdiff
path: root/src/VBox/Frontends/VirtualBox/src/snapshots/UISnapshotPane.h
blob: f5877be3ccccdbc3ef9b0df6ff997cde8a05b96b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/* $Id$ */
/** @file
 * VBox Qt GUI - UISnapshotPane class declaration.
 */

/*
 * Copyright (C) 2006-2019 Oracle Corporation
 *
 * This file is part of VirtualBox Open Source Edition (OSE), as
 * available from http://www.virtualbox.org. This file is free software;
 * you can redistribute it and/or modify it under the terms of the GNU
 * General Public License (GPL) as published by the Free Software
 * Foundation, in version 2 as it comes in the "COPYING" file of the
 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
 */

#ifndef FEQT_INCLUDED_SRC_snapshots_UISnapshotPane_h
#define FEQT_INCLUDED_SRC_snapshots_UISnapshotPane_h
#ifndef RT_WITHOUT_PRAGMA_ONCE
# pragma once
#endif

/* GUI includes: */
#include "QIWithRetranslateUI.h"
#include "UICommon.h"

/* COM includes: */
#include "CMachine.h"

/* Forward declarations: */
class QIcon;
class QReadWriteLock;
class QTimer;
class QTreeWidgetItem;
class QITreeWidgetItem;
class UIActionPool;
class UISnapshotDetailsWidget;
class UISnapshotItem;
class UISnapshotTree;
class UIToolBar;


/** Snapshot age format. */
enum SnapshotAgeFormat
{
    SnapshotAgeFormat_InSeconds,
    SnapshotAgeFormat_InMinutes,
    SnapshotAgeFormat_InHours,
    SnapshotAgeFormat_InDays,
    SnapshotAgeFormat_Max
};


/** QWidget extension providing GUI with the pane to control snapshot related functionality. */
class UISnapshotPane : public QIWithRetranslateUI<QWidget>
{
    Q_OBJECT;

signals:

    /** Notifies listeners about current item change. */
    void sigCurrentItemChange();

public:

    /** Constructs snapshot pane passing @a pParent to the base-class. */
    UISnapshotPane(UIActionPool *pActionPool, bool fShowToolbar = true, QWidget *pParent = 0);
    /** Destructs snapshot pane. */
    virtual ~UISnapshotPane() /* override */;

    /** Defines the @a comMachine object to be parsed. */
    void setMachine(const CMachine &comMachine);

    /** Returns cached snapshot-item icon depending on @a fOnline flag. */
    const QIcon *snapshotItemIcon(bool fOnline) const;

    /** Returns whether "current state" item selected. */
    bool isCurrentStateItemSelected() const;

protected:

    /** @name Qt event handlers.
      * @{ */
        /** Handles translation event. */
        virtual void retranslateUi() /* override */;

        /** Handles resize @a pEvent. */
        virtual void resizeEvent(QResizeEvent *pEvent) /* override */;

        /** Handles show @a pEvent. */
        virtual void showEvent(QShowEvent *pEvent) /* override */;
    /** @} */

private slots:

    /** @name Main event handlers.
      * @{ */
        /** Handles machine data change for machine with @a uMachineId. */
        void sltHandleMachineDataChange(const QUuid &uMachineId);
        /** Handles machine @a enmState change for machine with @a uMachineId. */
        void sltHandleMachineStateChange(const QUuid &uMachineId, const KMachineState enmState);

        /** Handles session @a enmState change for machine with @a uMachineId. */
        void sltHandleSessionStateChange(const QUuid &uMachineId, const KSessionState enmState);

        /** Handles snapshot take event for machine with @a uMachineId. */
        void sltHandleSnapshotTake(const QUuid &uMachineId, const QUuid &uSnapshotId);
        /** Handles snapshot delete event for machine with @a uMachineId. */
        void sltHandleSnapshotDelete(const QUuid &uMachineId, const QUuid &uSnapshotId);
        /** Handles snapshot change event for machine with @a uMachineId. */
        void sltHandleSnapshotChange(const QUuid &uMachineId, const QUuid &uSnapshotId);
        /** Handles snapshot restore event for machine with @a uMachineId. */
        void sltHandleSnapshotRestore(const QUuid &uMachineId, const QUuid &uSnapshotId);
    /** @} */

    /** @name Timer event handlers.
      * @{ */
        /** Updates snapshots age. */
        void sltUpdateSnapshotsAge();
    /** @} */

    /** @name Toolbar handlers.
      * @{ */
        /** Handles command to take a snapshot. */
        void sltTakeSnapshot() { takeSnapshot(); }
        /** Handles command to restore the snapshot. */
        void sltRestoreSnapshot() { restoreSnapshot(); }
        /** Handles command to delete the snapshot. */
        void sltDeleteSnapshot() { deleteSnapshot(); }
        /** Handles command to make snapshot details @a fVisible. */
        void sltToggleSnapshotDetailsVisibility(bool fVisible);
        /** Handles command to apply snapshot details changes. */
        void sltApplySnapshotDetailsChanges();
        /** Proposes to clone the snapshot. */
        void sltCloneSnapshot() { cloneSnapshot(); }
    /** @} */

    /** @name Tree-widget handlers.
      * @{ */
        /** Handles tree-widget current item change. */
        void sltHandleCurrentItemChange();
        /** Handles context menu request for tree-widget @a position. */
        void sltHandleContextMenuRequest(const QPoint &position);
        /** Handles tree-widget @a pItem change. */
        void sltHandleItemChange(QTreeWidgetItem *pItem);
        /** Handles tree-widget @a pItem double-click. */
        void sltHandleItemDoubleClick(QTreeWidgetItem *pItem);
    /** @} */

private:

    /** @name Prepare/cleanup cascade.
      * @{ */
        /** Prepares all. */
        void prepare();
        /** Prepares connections. */
        void prepareConnections();
        /** Prepares actions. */
        void prepareActions();
        /** Prepares widgets. */
        void prepareWidgets();
        /** Prepares toolbar. */
        void prepareToolbar();
        /** Prepares tree-widget. */
        void prepareTreeWidget();
        /** Prepares details-widget. */
        void prepareDetailsWidget();
        /** Load settings: */
        void loadSettings();

        /** Refreshes everything. */
        void refreshAll();
        /** Populates snapshot items for corresponding @a comSnapshot using @a pItem as parent. */
        void populateSnapshots(const CSnapshot &comSnapshot, QITreeWidgetItem *pItem);

        /** Cleanups all. */
        void cleanup();
    /** @} */

    /** @name Toolbar helpers.
      * @{ */
        /** Updates action states. */
        void updateActionStates();

        /** Proposes to take a snapshot. */
        bool takeSnapshot(bool fAutomatically = false);
        /** Proposes to delete the snapshot. */
        bool deleteSnapshot(bool fAutomatically = false);
        /** Proposes to restore the snapshot. */
        bool restoreSnapshot(bool fAutomatically = false);
        /** Proposes to clone the snapshot. */
        void cloneSnapshot();
    /** @} */

    /** @name Tree-widget helpers.
      * @{ */
        /** Handles command to adjust snapshot tree. */
        void adjustTreeWidget();

        /** Searches for an item with corresponding @a uSnapshotID. */
        UISnapshotItem *findItem(const QUuid &uSnapshotID) const;

        /** Searches for smallest snapshot age starting with @a pItem as parent. */
        SnapshotAgeFormat traverseSnapshotAge(QTreeWidgetItem *pItem) const;

        /** Expand all the children starting with @a pItem. */
        void expandItemChildren(QTreeWidgetItem *pItem);
    /** @} */

    /** @name General variables.
      * @{ */
        /** Holds the action-pool reference. */
        UIActionPool  *m_pActionPool;
        /** Holds whether we should show toolbar. */
        bool           m_fShowToolbar;
        /** Holds the COM machine object. */
        CMachine       m_comMachine;
        /** Holds the machine object ID. */
        QUuid        m_uMachineId;
        /** Holds the cached session state. */
        KSessionState  m_enmSessionState;

        /** Holds whether the snapshot operations are allowed. */
        bool  m_fShapshotOperationsAllowed;

        /** Holds the snapshot item editing protector. */
        QReadWriteLock *m_pLockReadWrite;

        /** Holds the cached snapshot-item pixmap for 'offline' state. */
        QIcon *m_pIconSnapshotOffline;
        /** Holds the cached snapshot-item pixmap for 'online' state. */
        QIcon *m_pIconSnapshotOnline;

        /** Holds the snapshot age update timer. */
        QTimer *m_pTimerUpdateAge;
    /** @} */

    /** @name Widget variables.
      * @{ */
        /** Holds the toolbar instance. */
        UIToolBar *m_pToolBar;

        /** Holds the snapshot tree instance. */
        UISnapshotTree *m_pSnapshotTree;
        /** Holds the "current snapshot" item reference. */
        UISnapshotItem *m_pCurrentSnapshotItem;
        /** Holds the "current state" item reference. */
        UISnapshotItem *m_pCurrentStateItem;

        /** Holds the details-widget instance. */
        UISnapshotDetailsWidget *m_pDetailsWidget;
    /** @} */
};

#endif /* !FEQT_INCLUDED_SRC_snapshots_UISnapshotPane_h */