1 | /* $Id: UIChooserAbstractModel.h 97605 2022-11-18 10:25:20Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIChooserAbstractModel class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2022 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_manager_chooser_UIChooserAbstractModel_h
|
---|
29 | #define FEQT_INCLUDED_SRC_manager_chooser_UIChooserAbstractModel_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QSet>
|
---|
36 | #include <QUuid>
|
---|
37 |
|
---|
38 | /* GUI includes: */
|
---|
39 | #include "UIChooserDefs.h"
|
---|
40 | #include "UICloudEntityKey.h"
|
---|
41 | #include "UIManagerDefs.h"
|
---|
42 |
|
---|
43 | /* COM includes: */
|
---|
44 | #include "COMEnums.h"
|
---|
45 | #include "CCloudMachine.h" /* required for Qt6 / c++17 */
|
---|
46 |
|
---|
47 | /* Forward declaration: */
|
---|
48 | class UIChooser;
|
---|
49 | class UIChooserNode;
|
---|
50 | class CMachine;
|
---|
51 |
|
---|
52 | /** QObject extension used as VM Chooser-pane abstract model.
|
---|
53 | * This class is used to load/save a tree of abstract invisible
|
---|
54 | * nodes representing VMs and their groups from/to extra-data. */
|
---|
55 | class UIChooserAbstractModel : public QObject
|
---|
56 | {
|
---|
57 | Q_OBJECT;
|
---|
58 |
|
---|
59 | signals:
|
---|
60 |
|
---|
61 | /** @name Cloud machine stuff.
|
---|
62 | * @{ */
|
---|
63 | /** Notifies listeners about state change for cloud machine with certain @a uId. */
|
---|
64 | void sigCloudMachineStateChange(const QUuid &uId);
|
---|
65 | /** @} */
|
---|
66 |
|
---|
67 | /** @name Group saving stuff.
|
---|
68 | * @{ */
|
---|
69 | /** Issues request to save settings. */
|
---|
70 | void sigSaveSettings();
|
---|
71 | /** Notifies listeners about group saving state changed. */
|
---|
72 | void sigGroupSavingStateChanged();
|
---|
73 | /** @} */
|
---|
74 |
|
---|
75 | /** @name Cloud update stuff.
|
---|
76 | * @{ */
|
---|
77 | /** Notifies listeners about cloud update state changed. */
|
---|
78 | void sigCloudUpdateStateChanged();
|
---|
79 | /** @} */
|
---|
80 |
|
---|
81 | public:
|
---|
82 |
|
---|
83 | /** Constructs abstract Chooser-model passing @a pParent to the base-class. */
|
---|
84 | UIChooserAbstractModel(UIChooser *pParent);
|
---|
85 | /** Destructs abstract Chooser-model. */
|
---|
86 | virtual ~UIChooserAbstractModel() RT_OVERRIDE;
|
---|
87 |
|
---|
88 | /** @name General stuff.
|
---|
89 | * @{ */
|
---|
90 | /** Inits model. */
|
---|
91 | virtual void init();
|
---|
92 | /** Deinits model. */
|
---|
93 | virtual void deinit();
|
---|
94 | /** @} */
|
---|
95 |
|
---|
96 | /** @name Children stuff.
|
---|
97 | * @{ */
|
---|
98 | /** Returns invisible root node instance. */
|
---|
99 | UIChooserNode *invisibleRoot() const { return m_pInvisibleRootNode; }
|
---|
100 |
|
---|
101 | /** Wipes out empty groups. */
|
---|
102 | void wipeOutEmptyGroups();
|
---|
103 |
|
---|
104 | /** Returns possible group node names for machine node with passed @a uId to move to. */
|
---|
105 | QStringList possibleGroupNodeNamesForMachineNodeToMove(const QUuid &uId);
|
---|
106 | /** Returns possible group node names for group node with passed @a strFullName to move to. */
|
---|
107 | QStringList possibleGroupNodeNamesForGroupNodeToMove(const QString &strFullName);
|
---|
108 |
|
---|
109 | /** Generates unique group name traversing recursively starting from @a pRoot. */
|
---|
110 | static QString uniqueGroupName(UIChooserNode *pRoot);
|
---|
111 | /** @} */
|
---|
112 |
|
---|
113 | /** @name Search stuff.
|
---|
114 | * @{ */
|
---|
115 | /** Performs a search using @a strSearchTerm and @a iSearchFlags specified. */
|
---|
116 | virtual void performSearch(const QString &strSearchTerm, int iSearchFlags);
|
---|
117 | /** Resets the search result data members and disables item's visual effects.
|
---|
118 | * Also returns a list of all nodes which may be utilized by the calling code. */
|
---|
119 | virtual QList<UIChooserNode*> resetSearch();
|
---|
120 | /** Returns search result. */
|
---|
121 | QList<UIChooserNode*> searchResult() const;
|
---|
122 | /** @} */
|
---|
123 |
|
---|
124 | /** @name Group saving stuff.
|
---|
125 | * @{ */
|
---|
126 | /** Commands to save groups. */
|
---|
127 | void saveGroups();
|
---|
128 | /** Returns whether group saving is in progress. */
|
---|
129 | bool isGroupSavingInProgress() const;
|
---|
130 |
|
---|
131 | /** Returns QString representation for passed @a uId, wiping out {} symbols.
|
---|
132 | * @note Required for backward compatibility after QString=>QUuid change. */
|
---|
133 | static QString toOldStyleUuid(const QUuid &uId);
|
---|
134 |
|
---|
135 | /** Returns node extra-data prefix of certain @a enmType. */
|
---|
136 | static QString prefixToString(UIChooserNodeDataPrefixType enmType);
|
---|
137 | /** Returns node extra-data option of certain @a enmType. */
|
---|
138 | static QString optionToString(UIChooserNodeDataOptionType enmType);
|
---|
139 | /** Returns node extra-data value of certain @a enmType. */
|
---|
140 | static QString valueToString(UIChooserNodeDataValueType enmType);
|
---|
141 | /** @} */
|
---|
142 |
|
---|
143 | /** @name Cloud update stuff.
|
---|
144 | * @{ */
|
---|
145 | /** Inserts cloud entity @a key into a set of keys currently being updated. */
|
---|
146 | void insertCloudEntityKey(const UICloudEntityKey &key);
|
---|
147 | /** Removes cloud entity @a key from a set of keys currently being updated. */
|
---|
148 | void removeCloudEntityKey(const UICloudEntityKey &key);
|
---|
149 | /** Returns whether cloud entity @a key is a part of key set currently being updated. */
|
---|
150 | bool containsCloudEntityKey(const UICloudEntityKey &key) const;
|
---|
151 |
|
---|
152 | /** Returns whether at least one cloud profile currently being updated. */
|
---|
153 | bool isCloudProfileUpdateInProgress() const;
|
---|
154 | /** @} */
|
---|
155 |
|
---|
156 | public slots:
|
---|
157 |
|
---|
158 | /** @name Cloud machine stuff.
|
---|
159 | * @{ */
|
---|
160 | /** Handles cloud machine refresh started. */
|
---|
161 | void sltHandleCloudMachineRefreshStarted();
|
---|
162 | /** Handles cloud machine refresh finished. */
|
---|
163 | void sltHandleCloudMachineRefreshFinished();
|
---|
164 | /** @} */
|
---|
165 |
|
---|
166 | /** @name Group saving stuff.
|
---|
167 | * @{ */
|
---|
168 | /** Handles group settings saving complete. */
|
---|
169 | void sltGroupSettingsSaveComplete();
|
---|
170 | /** Handles group definitions saving complete. */
|
---|
171 | void sltGroupDefinitionsSaveComplete();
|
---|
172 | /** @} */
|
---|
173 |
|
---|
174 | protected slots:
|
---|
175 |
|
---|
176 | /** @name Main event handling stuff.
|
---|
177 | * @{ */
|
---|
178 | /** Handles local machine @a enmState change for machine with certain @a uMachineId. */
|
---|
179 | virtual void sltLocalMachineStateChanged(const QUuid &uMachineId, const KMachineState enmState);
|
---|
180 | /** Handles local machine data change for machine with certain @a uMachineId. */
|
---|
181 | virtual void sltLocalMachineDataChanged(const QUuid &uMachineId);
|
---|
182 | /** Handles local machine registering/unregistering for machine with certain @a uMachineId. */
|
---|
183 | virtual void sltLocalMachineRegistrationChanged(const QUuid &uMachineId, const bool fRegistered);
|
---|
184 | /** Handles local machine registering/unregistering for machine with certain @a uMachineId. */
|
---|
185 | virtual void sltLocalMachineGroupsChanged(const QUuid &uMachineId);
|
---|
186 |
|
---|
187 | /** Handles session @a enmState change for machine with certain @a uMachineId. */
|
---|
188 | virtual void sltSessionStateChanged(const QUuid &uMachineId, const KSessionState enmState);
|
---|
189 |
|
---|
190 | /** Handles snapshot change for machine/snapshot with certain @a uMachineId / @a uSnapshotId. */
|
---|
191 | virtual void sltSnapshotChanged(const QUuid &uMachineId, const QUuid &uSnapshotId);
|
---|
192 |
|
---|
193 | /** Handles event about cloud provider with @a uProviderId being uninstalled. */
|
---|
194 | virtual void sltHandleCloudProviderUninstall(const QUuid &uProviderId);
|
---|
195 | /** @} */
|
---|
196 |
|
---|
197 | /** @name Children stuff.
|
---|
198 | * @{ */
|
---|
199 | /** Handles reload machine with certain @a uMachineId request. */
|
---|
200 | virtual void sltReloadMachine(const QUuid &uMachineId);
|
---|
201 |
|
---|
202 | /** Handles command to commit data. */
|
---|
203 | virtual void sltCommitData();
|
---|
204 | /** Handles command to detach COM. */
|
---|
205 | virtual void sltDetachCOM();
|
---|
206 | /** @} */
|
---|
207 |
|
---|
208 | /** @name Cloud stuff.
|
---|
209 | * @{ */
|
---|
210 | /** Handles cloud machine unregistering for @a uId.
|
---|
211 | * @param strProviderShortName Brings provider short name.
|
---|
212 | * @param strProfileName Brings profile name. */
|
---|
213 | virtual void sltCloudMachineUnregistered(const QString &strProviderShortName,
|
---|
214 | const QString &strProfileName,
|
---|
215 | const QUuid &uId);
|
---|
216 | /** Handles cloud machine unregistering for a list of @a ids.
|
---|
217 | * @param strProviderShortName Brings provider short name.
|
---|
218 | * @param strProfileName Brings profile name. */
|
---|
219 | virtual void sltCloudMachinesUnregistered(const QString &strProviderShortName,
|
---|
220 | const QString &strProfileName,
|
---|
221 | const QList<QUuid> &ids);
|
---|
222 | /** Handles cloud machine registering for @a comMachine.
|
---|
223 | * @param strProviderShortName Brings provider short name.
|
---|
224 | * @param strProfileName Brings profile name. */
|
---|
225 | virtual void sltCloudMachineRegistered(const QString &strProviderShortName,
|
---|
226 | const QString &strProfileName,
|
---|
227 | const CCloudMachine &comMachine);
|
---|
228 | /** Handles cloud machine registering for a list of @a machines.
|
---|
229 | * @param strProviderShortName Brings provider short name.
|
---|
230 | * @param strProfileName Brings profile name. */
|
---|
231 | virtual void sltCloudMachinesRegistered(const QString &strProviderShortName,
|
---|
232 | const QString &strProfileName,
|
---|
233 | const QVector<CCloudMachine> &machines);
|
---|
234 |
|
---|
235 | /** Handles read cloud machine list task complete signal. */
|
---|
236 | virtual void sltHandleReadCloudMachineListTaskComplete();
|
---|
237 |
|
---|
238 | /** Handles Cloud Profile Manager cumulative change. */
|
---|
239 | virtual void sltHandleCloudProfileManagerCumulativeChange();
|
---|
240 | /** @} */
|
---|
241 |
|
---|
242 | protected:
|
---|
243 |
|
---|
244 | /** @name Children stuff.
|
---|
245 | * @{ */
|
---|
246 | /** Creates and registers read cloud machine list task with @a guiCloudProfileKey.
|
---|
247 | * @param fWithRefresh Brings whether machines should be refreshed as well. */
|
---|
248 | void createReadCloudMachineListTask(const UICloudEntityKey &guiCloudProfileKey, bool fWithRefresh);
|
---|
249 | /** @} */
|
---|
250 |
|
---|
251 | private slots:
|
---|
252 |
|
---|
253 | /** @name Group saving stuff.
|
---|
254 | * @{ */
|
---|
255 | /** Handles request to save settings. */
|
---|
256 | void sltSaveSettings();
|
---|
257 | /** @} */
|
---|
258 |
|
---|
259 | private:
|
---|
260 |
|
---|
261 | /** @name Prepare/Cleanup cascade.
|
---|
262 | * @{ */
|
---|
263 | /** Prepares all. */
|
---|
264 | void prepare();
|
---|
265 | /** Prepares connections. */
|
---|
266 | void prepareConnections();
|
---|
267 |
|
---|
268 | /** Cleanups connections. */
|
---|
269 | void cleanupConnections();
|
---|
270 | /** Cleanups all. */
|
---|
271 | void cleanup();
|
---|
272 | /** @} */
|
---|
273 |
|
---|
274 | /** @name Children stuff.
|
---|
275 | * @{ */
|
---|
276 | /** Reloads local tree. */
|
---|
277 | void reloadLocalTree();
|
---|
278 | /** Reloads cloud tree. */
|
---|
279 | void reloadCloudTree();
|
---|
280 |
|
---|
281 | /** Adds local machine item based on certain @a comMachine and optionally @a fMakeItVisible. */
|
---|
282 | void addLocalMachineIntoTheTree(const CMachine &comMachine, bool fMakeItVisible = false);
|
---|
283 | /** Adds cloud machine item based on certain @a comMachine and optionally @a fMakeItVisible, into @a strGroup. */
|
---|
284 | void addCloudMachineIntoTheTree(const QString &strGroup, const CCloudMachine &comMachine, bool fMakeItVisible = false);
|
---|
285 |
|
---|
286 | /** Acquires local group node, creates one if necessary.
|
---|
287 | * @param strName Brings the name of group we looking for.
|
---|
288 | * @param pParentNode Brings the parent we starting to look for a group from.
|
---|
289 | * @param fAllGroupsOpened Brings whether we should open all the groups till the required one. */
|
---|
290 | UIChooserNode *getLocalGroupNode(const QString &strName, UIChooserNode *pParentNode, bool fAllGroupsOpened);
|
---|
291 | /** Acquires cloud group node, never create new, returns root if nothing found.
|
---|
292 | * @param strName Brings the name of group we looking for.
|
---|
293 | * @param pParentNode Brings the parent we starting to look for a group from.
|
---|
294 | * @param fAllGroupsOpened Brings whether we should open all the groups till the required one. */
|
---|
295 | UIChooserNode *getCloudGroupNode(const QString &strName, UIChooserNode *pParentNode, bool fAllGroupsOpened);
|
---|
296 |
|
---|
297 | /** Returns whether group node * with specified @a enmDataType and @a strName should be opened,
|
---|
298 | * searching starting from the passed @a pParentNode. */
|
---|
299 | bool shouldGroupNodeBeOpened(UIChooserNode *pParentNode,
|
---|
300 | UIChooserNodeDataPrefixType enmDataType,
|
---|
301 | const QString &strName) const;
|
---|
302 | /** Returns whether global node should be favorite,
|
---|
303 | * searching starting from the passed @a pParentNode. */
|
---|
304 | bool shouldGlobalNodeBeFavorite(UIChooserNode *pParentNode) const;
|
---|
305 |
|
---|
306 | /** Wipes out empty groups starting from @a pParentItem. */
|
---|
307 | void wipeOutEmptyGroupsStartingFrom(UIChooserNode *pParentNode);
|
---|
308 |
|
---|
309 | /** Acquires desired position for a child of @a pParentNode with specified @a enmDataType and @a strName. */
|
---|
310 | int getDesiredNodePosition(UIChooserNode *pParentNode, UIChooserNodeDataPrefixType enmDataType, const QString &strName);
|
---|
311 | /** Acquires defined position for a child of @a pParentNode with specified @a enmDataType and @a strName. */
|
---|
312 | int getDefinedNodePosition(UIChooserNode *pParentNode, UIChooserNodeDataPrefixType enmDataType, const QString &strName);
|
---|
313 |
|
---|
314 | /** Creates local machine node based on certain @a comMachine as a child of specified @a pParentNode. */
|
---|
315 | void createLocalMachineNode(UIChooserNode *pParentNode, const CMachine &comMachine);
|
---|
316 | /** Creates fake cloud machine node in passed @a enmState as a child of specified @a pParentNode. */
|
---|
317 | void createCloudMachineNode(UIChooserNode *pParentNode, UIFakeCloudVirtualMachineItemState enmState);
|
---|
318 | /** Creates real cloud machine node based on certain @a comMachine as a child of specified @a pParentNode. */
|
---|
319 | void createCloudMachineNode(UIChooserNode *pParentNode, const CCloudMachine &comMachine);
|
---|
320 |
|
---|
321 | /** Gathers a list of possible group node names for machine nodes listed in @a exceptions, starting from @a pCurrentNode. */
|
---|
322 | QStringList gatherPossibleGroupNodeNames(UIChooserNode *pCurrentNode, QList<UIChooserNode*> exceptions) const;
|
---|
323 |
|
---|
324 | /** Returns whether passed @a pParentNode contains child node with passed @a uId. */
|
---|
325 | bool checkIfNodeContainChildWithId(UIChooserNode *pParentNode, const QUuid &uId) const;
|
---|
326 | /** @} */
|
---|
327 |
|
---|
328 | /** @name Group saving stuff.
|
---|
329 | * @{ */
|
---|
330 | /** Saves group settings. */
|
---|
331 | void saveGroupSettings();
|
---|
332 | /** Saves group definitions. */
|
---|
333 | void saveGroupDefinitions();
|
---|
334 |
|
---|
335 | /** Gathers group @a settings of @a pParentGroup. */
|
---|
336 | void gatherGroupSettings(QMap<QString, QStringList> &settings, UIChooserNode *pParentGroup);
|
---|
337 | /** Gathers group @a definitions of @a pParentGroup. */
|
---|
338 | void gatherGroupDefinitions(QMap<QString, QStringList> &definitions, UIChooserNode *pParentGroup);
|
---|
339 |
|
---|
340 | /** Makes sure group settings saving is finished. */
|
---|
341 | void makeSureGroupSettingsSaveIsFinished();
|
---|
342 | /** Makes sure group definitions saving is finished. */
|
---|
343 | void makeSureGroupDefinitionsSaveIsFinished();
|
---|
344 | /** @} */
|
---|
345 |
|
---|
346 | /** @name Cloud stuff.
|
---|
347 | * @{ */
|
---|
348 | /** Searches for provider node with passed @a uProviderId. */
|
---|
349 | UIChooserNode *searchProviderNode(const QUuid &uProviderId);
|
---|
350 | /** Searches for provider node with passed @a strProviderShortName. */
|
---|
351 | UIChooserNode *searchProviderNode(const QString &strProviderShortName);
|
---|
352 |
|
---|
353 | /** Searches for profile node with passed @a strProfileName under passed @a pProviderNode. */
|
---|
354 | UIChooserNode *searchProfileNode(UIChooserNode *pProviderNode, const QString &strProfileName);
|
---|
355 | /** Searches for profile node with passed @a strProviderShortName and @a strProfileName. */
|
---|
356 | UIChooserNode *searchProfileNode(const QString &strProviderShortName, const QString &strProfileName);
|
---|
357 |
|
---|
358 | /** Searches for machine node with passed @a uMachineId under passed @a pProfileNode. */
|
---|
359 | UIChooserNode *searchMachineNode(UIChooserNode *pProfileNode, const QUuid &uMachineId);
|
---|
360 | /** Searches for machine with passed @a strProviderShortName, @a strProfileName and @a uMachineId. */
|
---|
361 | UIChooserNode *searchMachineNode(const QString &strProviderShortName, const QString &strProfileName, const QUuid &uMachineId);
|
---|
362 |
|
---|
363 | /** Searches for fake node under passed @a pProfileNode. */
|
---|
364 | UIChooserNode *searchFakeNode(UIChooserNode *pProfileNode);
|
---|
365 | /** Searches for fake with passed @a strProviderShortName and @a strProfileName. */
|
---|
366 | UIChooserNode *searchFakeNode(const QString &strProviderShortName, const QString &strProfileName);
|
---|
367 | /** @} */
|
---|
368 |
|
---|
369 | /** @name Cloud update stuff.
|
---|
370 | * @{ */
|
---|
371 | /** Stops all cloud updates.
|
---|
372 | * @param fForced Brings whether cloud updates should be killed. */
|
---|
373 | void stopCloudUpdates(bool fForced = false);
|
---|
374 | /** @} */
|
---|
375 |
|
---|
376 | /** @name General stuff.
|
---|
377 | * @{ */
|
---|
378 | /** Holds the parent widget reference. */
|
---|
379 | UIChooser *m_pParent;
|
---|
380 | /** @} */
|
---|
381 |
|
---|
382 | /** @name Children stuff.
|
---|
383 | * @{ */
|
---|
384 | /** Holds the invisible root node instance. */
|
---|
385 | UIChooserNode *m_pInvisibleRootNode;
|
---|
386 | /** @} */
|
---|
387 |
|
---|
388 | /** @name Search stuff.
|
---|
389 | * @{ */
|
---|
390 | /** Stores the results of the current search. */
|
---|
391 | QList<UIChooserNode*> m_searchResults;
|
---|
392 | /** @} */
|
---|
393 |
|
---|
394 | /** @name Group saving stuff.
|
---|
395 | * @{ */
|
---|
396 | /** Holds the consolidated map of group settings/definitions. */
|
---|
397 | QMap<QString, QStringList> m_groups;
|
---|
398 | /** @} */
|
---|
399 |
|
---|
400 | /** @name Cloud update stuff.
|
---|
401 | * @{ */
|
---|
402 | /** Holds the set of cloud entity keys currently being updated. */
|
---|
403 | QSet<UICloudEntityKey> m_cloudEntityKeysBeingUpdated;
|
---|
404 | /** @} */
|
---|
405 | };
|
---|
406 |
|
---|
407 | #endif /* !FEQT_INCLUDED_SRC_manager_chooser_UIChooserAbstractModel_h */
|
---|