1 | /* $Id: UIChooserAbstractModel.h 84545 2020-05-26 16:17:40Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIChooserAbstractModel class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2020 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_manager_chooser_UIChooserAbstractModel_h
|
---|
19 | #define FEQT_INCLUDED_SRC_manager_chooser_UIChooserAbstractModel_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | /* GUI includes: */
|
---|
25 | #include "UIChooserDefs.h"
|
---|
26 |
|
---|
27 | /* COM includes: */
|
---|
28 | #include "COMEnums.h"
|
---|
29 |
|
---|
30 | /* Forward declaration: */
|
---|
31 | class QUuid;
|
---|
32 | class UIChooser;
|
---|
33 | class UIChooserNode;
|
---|
34 | class UITask;
|
---|
35 | class CCloudMachine;
|
---|
36 | class CMachine;
|
---|
37 |
|
---|
38 | /** QObject extension used as VM Chooser-pane abstract model.
|
---|
39 | * This class is used to load/save a tree of abstract invisible
|
---|
40 | * nodes representing VMs and their groups from/to extra-data. */
|
---|
41 | class UIChooserAbstractModel : public QObject
|
---|
42 | {
|
---|
43 | Q_OBJECT;
|
---|
44 |
|
---|
45 | signals:
|
---|
46 |
|
---|
47 | /** @name Cloud machine stuff.
|
---|
48 | * @{ */
|
---|
49 | /** Notifies about state change for cloud machine with certain @a uId. */
|
---|
50 | void sigCloudMachineStateChange(const QUuid &uId);
|
---|
51 | /** @} */
|
---|
52 |
|
---|
53 | /** @name Group saving stuff.
|
---|
54 | * @{ */
|
---|
55 | /** Commands to start group saving. */
|
---|
56 | void sigStartGroupSaving();
|
---|
57 | /** Notifies about group saving state changed. */
|
---|
58 | void sigGroupSavingStateChanged();
|
---|
59 | /** @} */
|
---|
60 |
|
---|
61 | public:
|
---|
62 |
|
---|
63 | /** Constructs abstract Chooser-model passing @a pParent to the base-class. */
|
---|
64 | UIChooserAbstractModel(UIChooser *pParent);
|
---|
65 |
|
---|
66 | /** @name General stuff.
|
---|
67 | * @{ */
|
---|
68 | /** Inits model. */
|
---|
69 | virtual void init();
|
---|
70 | /** Deinits model. */
|
---|
71 | virtual void deinit();
|
---|
72 | /** @} */
|
---|
73 |
|
---|
74 | /** @name Children stuff.
|
---|
75 | * @{ */
|
---|
76 | /** Returns invisible root node instance. */
|
---|
77 | UIChooserNode *invisibleRoot() const { return m_pInvisibleRootNode; }
|
---|
78 |
|
---|
79 | /** Wipes out empty groups. */
|
---|
80 | void wipeOutEmptyGroups();
|
---|
81 |
|
---|
82 | /** Returns possible group node names for VM node with passed @a uId to move to. */
|
---|
83 | QStringList possibleGroupNodeNamesForMachineNodeToMove(const QUuid &uId);
|
---|
84 |
|
---|
85 | /** Generates unique group name traversing recursively starting from @a pRoot. */
|
---|
86 | static QString uniqueGroupName(UIChooserNode *pRoot);
|
---|
87 | /** @} */
|
---|
88 |
|
---|
89 | /** @name Search stuff.
|
---|
90 | * @{ */
|
---|
91 | /** Performs a search starting from the m_pInvisibleRootNode. */
|
---|
92 | virtual void performSearch(const QString &strSearchTerm, int iItemSearchFlags);
|
---|
93 | /** Cleans the search result data members and disables item's visual effects.
|
---|
94 | * Also returns a list of all nodes which may be utilized by the calling code. */
|
---|
95 | virtual QList<UIChooserNode*> resetSearch();
|
---|
96 | /** Returns search result. */
|
---|
97 | QList<UIChooserNode*> searchResult() const;
|
---|
98 | /** @} */
|
---|
99 |
|
---|
100 | /** @name Group saving stuff.
|
---|
101 | * @{ */
|
---|
102 | /** Commands to save groups. */
|
---|
103 | void saveGroups();
|
---|
104 | /** Returns whether group saving is in progress. */
|
---|
105 | bool isGroupSavingInProgress() const;
|
---|
106 |
|
---|
107 | /** Returns QString representation for passed @a uId, wiping out {} symbols.
|
---|
108 | * @note Required for backward compatibility after QString=>QUuid change. */
|
---|
109 | static QString toOldStyleUuid(const QUuid &uId);
|
---|
110 |
|
---|
111 | /** Returns node extra-data prefix of certain @a enmType. */
|
---|
112 | static QString prefixToString(UIChooserNodeDataPrefixType enmType);
|
---|
113 | /** Returns node extra-data option of certain @a enmType. */
|
---|
114 | static QString optionToString(UIChooserNodeDataOptionType enmType);
|
---|
115 | /** Returns node extra-data value of certain @a enmType. */
|
---|
116 | static QString valueToString(UIChooserNodeDataValueType enmType);
|
---|
117 | /** @} */
|
---|
118 |
|
---|
119 | public slots:
|
---|
120 |
|
---|
121 | /** @name Cloud machine stuff.
|
---|
122 | * @{ */
|
---|
123 | /** Handles cloud machine state change. */
|
---|
124 | void sltHandleCloudMachineStateChange();
|
---|
125 | /** @} */
|
---|
126 |
|
---|
127 | /** @name Group saving stuff.
|
---|
128 | * @{ */
|
---|
129 | /** Handles group settings saving complete. */
|
---|
130 | void sltGroupSettingsSaveComplete();
|
---|
131 | /** Handles group definitions saving complete. */
|
---|
132 | void sltGroupDefinitionsSaveComplete();
|
---|
133 | /** @} */
|
---|
134 |
|
---|
135 | protected slots:
|
---|
136 |
|
---|
137 | /** @name Main event handling stuff.
|
---|
138 | * @{ */
|
---|
139 | /** Handles local machine @a enmState change for machine with certain @a uMachineId. */
|
---|
140 | virtual void sltLocalMachineStateChanged(const QUuid &uMachineId, const KMachineState enmState);
|
---|
141 | /** Handles local machine data change for machine with certain @a uMachineId. */
|
---|
142 | virtual void sltLocalMachineDataChanged(const QUuid &uMachineId);
|
---|
143 | /** Handles local machine registering/unregistering for machine with certain @a uMachineId. */
|
---|
144 | virtual void sltLocalMachineRegistered(const QUuid &uMachineId, const bool fRegistered);
|
---|
145 | /** Handles cloud machine registering/unregistering for machine with certain @a uMachineId.
|
---|
146 | * @param strProviderShortName Brings provider short name.
|
---|
147 | * @param strProfileName Brings profile name. */
|
---|
148 | virtual void sltCloudMachineRegistered(const QString &strProviderShortName, const QString &strProfileName,
|
---|
149 | const QUuid &uMachineId, const bool fRegistered);
|
---|
150 | /** Handles session @a enmState change for machine with certain @a uMachineId. */
|
---|
151 | virtual void sltSessionStateChanged(const QUuid &uMachineId, const KSessionState enmState);
|
---|
152 | /** Handles snapshot change for machine/snapshot with certain @a uMachineId / @a uSnapshotId. */
|
---|
153 | virtual void sltSnapshotChanged(const QUuid &uMachineId, const QUuid &uSnapshotId);
|
---|
154 | /** @} */
|
---|
155 |
|
---|
156 | /** @name Children stuff.
|
---|
157 | * @{ */
|
---|
158 | /** Handles reload machine with certain @a uMachineId request. */
|
---|
159 | virtual void sltReloadMachine(const QUuid &uMachineId);
|
---|
160 | /** @} */
|
---|
161 |
|
---|
162 | /** @name Cloud stuff.
|
---|
163 | * @{ */
|
---|
164 | /** Handles list cloud machines task complete signal. */
|
---|
165 | virtual void sltHandleCloudListMachinesTaskComplete(UITask *pTask);
|
---|
166 | /** @} */
|
---|
167 |
|
---|
168 | private slots:
|
---|
169 |
|
---|
170 | /** @name Group saving stuff.
|
---|
171 | * @{ */
|
---|
172 | /** Handles request to start group saving. */
|
---|
173 | void sltStartGroupSaving();
|
---|
174 | /** @} */
|
---|
175 |
|
---|
176 | private:
|
---|
177 |
|
---|
178 | /** @name Prepare/Cleanup cascade.
|
---|
179 | * @{ */
|
---|
180 | /** Prepares all. */
|
---|
181 | void prepare();
|
---|
182 | /** Prepares connections. */
|
---|
183 | void prepareConnections();
|
---|
184 | /** @} */
|
---|
185 |
|
---|
186 | /** @name Children stuff.
|
---|
187 | * @{ */
|
---|
188 | /** Adds local machine item based on certain @a comMachine and optionally @a fMakeItVisible. */
|
---|
189 | void addLocalMachineIntoTheTree(const CMachine &comMachine, bool fMakeItVisible = false);
|
---|
190 | /** Adds cloud machine item based on certain @a comMachine and optionally @a fMakeItVisible, into @a strGroup. */
|
---|
191 | void addCloudMachineIntoTheTree(const QString &strGroup, const CCloudMachine &comMachine, bool fMakeItVisible = false);
|
---|
192 |
|
---|
193 | /** Acquires local group node, creates one if necessary.
|
---|
194 | * @param strName Brings the name of group we looking for.
|
---|
195 | * @param pParentNode Brings the parent we starting to look for a group from.
|
---|
196 | * @param fAllGroupsOpened Brings whether we should open all the groups till the required one. */
|
---|
197 | UIChooserNode *getLocalGroupNode(const QString &strName, UIChooserNode *pParentNode, bool fAllGroupsOpened);
|
---|
198 | /** Acquires cloud group node, never create new, returns root if nothing found.
|
---|
199 | * @param strName Brings the name of group we looking for.
|
---|
200 | * @param pParentNode Brings the parent we starting to look for a group from.
|
---|
201 | * @param fAllGroupsOpened Brings whether we should open all the groups till the required one. */
|
---|
202 | UIChooserNode *getCloudGroupNode(const QString &strName, UIChooserNode *pParentNode, bool fAllGroupsOpened);
|
---|
203 |
|
---|
204 | /** Returns whether group node * with specified @a enmDataType and @a strName should be opened,
|
---|
205 | * searching starting from the passed @a pParentNode. */
|
---|
206 | bool shouldGroupNodeBeOpened(UIChooserNode *pParentNode,
|
---|
207 | UIChooserNodeDataPrefixType enmDataType,
|
---|
208 | const QString &strName) const;
|
---|
209 | /** Returns whether global node should be favorite,
|
---|
210 | * searching starting from the passed @a pParentNode. */
|
---|
211 | bool shouldGlobalNodeBeFavorite(UIChooserNode *pParentNode) const;
|
---|
212 |
|
---|
213 | /** Wipes out empty groups starting from @a pParentItem. */
|
---|
214 | void wipeOutEmptyGroupsStartingFrom(UIChooserNode *pParentNode);
|
---|
215 |
|
---|
216 | /** Acquires desired position for a child of @a pParentNode with specified @a enmDataType and @a strName. */
|
---|
217 | int getDesiredNodePosition(UIChooserNode *pParentNode, UIChooserNodeDataPrefixType enmDataType, const QString &strName);
|
---|
218 | /** Acquires defined position for a child of @a pParentNode with specified @a enmDataType and @a strName. */
|
---|
219 | int getDefinedNodePosition(UIChooserNode *pParentNode, UIChooserNodeDataPrefixType enmDataType, const QString &strName);
|
---|
220 |
|
---|
221 | /** Creates local machine node based on certain @a comMachine as a child of specified @a pParentNode. */
|
---|
222 | void createLocalMachineNode(UIChooserNode *pParentNode, const CMachine &comMachine);
|
---|
223 | /** Creates cloud machine node based on certain @a comMachine as a child of specified @a pParentNode. */
|
---|
224 | void createCloudMachineNode(UIChooserNode *pParentNode, const CCloudMachine &comMachine);
|
---|
225 |
|
---|
226 | /** Gathers a list of possible group node names for machine nodes listed in @a exceptions, starting from @a pCurrentNode. */
|
---|
227 | QStringList gatherPossibleGroupNodeNames(UIChooserNode *pCurrentNode, QList<UIChooserNode*> exceptions) const;
|
---|
228 | /** @} */
|
---|
229 |
|
---|
230 | /** @name Group saving stuff.
|
---|
231 | * @{ */
|
---|
232 | /** Saves group settings. */
|
---|
233 | void saveGroupSettings();
|
---|
234 | /** Saves group definitions. */
|
---|
235 | void saveGroupDefinitions();
|
---|
236 |
|
---|
237 | /** Gathers group @a settings of @a pParentGroup. */
|
---|
238 | void gatherGroupSettings(QMap<QString, QStringList> &settings, UIChooserNode *pParentGroup);
|
---|
239 | /** Gathers group @a definitions of @a pParentGroup. */
|
---|
240 | void gatherGroupDefinitions(QMap<QString, QStringList> &definitions, UIChooserNode *pParentGroup);
|
---|
241 |
|
---|
242 | /** Makes sure group settings saving is finished. */
|
---|
243 | void makeSureGroupSettingsSaveIsFinished();
|
---|
244 | /** Makes sure group definitions saving is finished. */
|
---|
245 | void makeSureGroupDefinitionsSaveIsFinished();
|
---|
246 | /** @} */
|
---|
247 |
|
---|
248 | /** @name General stuff.
|
---|
249 | * @{ */
|
---|
250 | /** Holds the parent widget reference. */
|
---|
251 | UIChooser *m_pParent;
|
---|
252 | /** @} */
|
---|
253 |
|
---|
254 | /** @name Children stuff.
|
---|
255 | * @{ */
|
---|
256 | /** Holds the invisible root node instance. */
|
---|
257 | UIChooserNode *m_pInvisibleRootNode;
|
---|
258 | /** @} */
|
---|
259 |
|
---|
260 | /** @name Search stuff.
|
---|
261 | * @{ */
|
---|
262 | /** Stores the results of the current search. */
|
---|
263 | QList<UIChooserNode*> m_searchResults;
|
---|
264 | /** @} */
|
---|
265 |
|
---|
266 | /** @name Group saving stuff.
|
---|
267 | * @{ */
|
---|
268 | /** Holds the consolidated map of group settings/definitions. */
|
---|
269 | QMap<QString, QStringList> m_groups;
|
---|
270 | /** @} */
|
---|
271 | };
|
---|
272 |
|
---|
273 | #endif /* !FEQT_INCLUDED_SRC_manager_chooser_UIChooserAbstractModel_h */
|
---|