VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserAbstractModel.h@ 108151

Last change on this file since 108151 was 108151, checked in by vboxsync, 3 months ago

FE/Qt: bugref:10814: VBox Manager / Chooser pane: Cleanup default item meaning for global item type; It was used with Global node/item type only which is obsolete now.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette