VirtualBox

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

Last change on this file was 106061, checked in by vboxsync, 3 weeks ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.9 KB
Line 
1/* $Id: UIChooserAbstractModel.h 106061 2024-09-16 14:03:52Z 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 /** Returns node extra-data value of certain @a enmType. */
145 static QString valueToString(UIChooserNodeDataValueType enmType);
146 /** @} */
147
148 /** @name Cloud update stuff.
149 * @{ */
150 /** Returns whether real cloud nodes should be kept updated. */
151 bool isKeepCloudNodesUpdated() const { return m_fKeepCloudNodesUpdated; }
152 /** Defines whether real cloud nodes should be kept updated. */
153 void setKeepCloudNodesUpdated(bool fUpdate);
154
155 /** Inserts cloud entity @a key into a set of keys currently being updated. */
156 void insertCloudEntityKey(const UICloudEntityKey &key);
157 /** Removes cloud entity @a key from a set of keys currently being updated. */
158 void removeCloudEntityKey(const UICloudEntityKey &key);
159 /** Returns whether cloud entity @a key is a part of key set currently being updated. */
160 bool containsCloudEntityKey(const UICloudEntityKey &key) const;
161
162 /** Returns whether at least one cloud profile currently being updated. */
163 bool isCloudProfileUpdateInProgress() const;
164
165 /** Returns a list of real cloud machine items. */
166 QList<UIVirtualMachineItemCloud*> cloudMachineItems() const;
167 /** @} */
168
169public slots:
170
171 /** @name Cloud machine stuff.
172 * @{ */
173 /** Handles cloud machine refresh started. */
174 void sltHandleCloudMachineRefreshStarted();
175 /** Handles cloud machine refresh finished. */
176 void sltHandleCloudMachineRefreshFinished();
177 /** @} */
178
179 /** @name Group saving stuff.
180 * @{ */
181 /** Handles group settings saving complete. */
182 void sltGroupSettingsSaveComplete();
183 /** Handles group definitions saving complete. */
184 void sltGroupDefinitionsSaveComplete();
185 /** @} */
186
187protected slots:
188
189 /** @name Main event handling stuff.
190 * @{ */
191 /** Handles local machine @a enmState change for machine with certain @a uMachineId. */
192 virtual void sltLocalMachineStateChanged(const QUuid &uMachineId, const KMachineState enmState);
193 /** Handles local machine data change for machine with certain @a uMachineId. */
194 virtual void sltLocalMachineDataChanged(const QUuid &uMachineId);
195 /** Handles local machine registering/unregistering for machine with certain @a uMachineId. */
196 virtual void sltLocalMachineRegistrationChanged(const QUuid &uMachineId, const bool fRegistered);
197 /** Handles local machine registering/unregistering for machine with certain @a uMachineId. */
198 virtual void sltLocalMachineGroupsChanged(const QUuid &uMachineId);
199
200 /** Handles session @a enmState change for machine with certain @a uMachineId. */
201 virtual void sltSessionStateChanged(const QUuid &uMachineId, const KSessionState enmState);
202
203 /** Handles snapshot change for machine/snapshot with certain @a uMachineId / @a uSnapshotId. */
204 virtual void sltSnapshotChanged(const QUuid &uMachineId, const QUuid &uSnapshotId);
205
206 /** Handles event about cloud provider with @a uProviderId being uninstalled. */
207 virtual void sltHandleCloudProviderUninstall(const QUuid &uProviderId);
208 /** @} */
209
210 /** @name Children stuff.
211 * @{ */
212 /** Handles reload machine with certain @a uMachineId request. */
213 virtual void sltReloadMachine(const QUuid &uMachineId);
214
215 /** Handles command to commit data. */
216 virtual void sltCommitData();
217 /** Handles command to detach COM. */
218 virtual void sltDetachCOM();
219 /** @} */
220
221 /** @name Cloud stuff.
222 * @{ */
223 /** Handles cloud machine unregistering for @a uId.
224 * @param strProviderShortName Brings provider short name.
225 * @param strProfileName Brings profile name. */
226 virtual void sltCloudMachineUnregistered(const QString &strProviderShortName,
227 const QString &strProfileName,
228 const QUuid &uId);
229 /** Handles cloud machine unregistering for a list of @a ids.
230 * @param strProviderShortName Brings provider short name.
231 * @param strProfileName Brings profile name. */
232 virtual void sltCloudMachinesUnregistered(const QString &strProviderShortName,
233 const QString &strProfileName,
234 const QList<QUuid> &ids);
235 /** Handles cloud machine registering for @a comMachine.
236 * @param strProviderShortName Brings provider short name.
237 * @param strProfileName Brings profile name. */
238 virtual void sltCloudMachineRegistered(const QString &strProviderShortName,
239 const QString &strProfileName,
240 const CCloudMachine &comMachine);
241 /** Handles cloud machine registering for a list of @a machines.
242 * @param strProviderShortName Brings provider short name.
243 * @param strProfileName Brings profile name. */
244 virtual void sltCloudMachinesRegistered(const QString &strProviderShortName,
245 const QString &strProfileName,
246 const QVector<CCloudMachine> &machines);
247
248 /** Handles read cloud machine list task complete signal. */
249 virtual void sltHandleReadCloudMachineListTaskComplete();
250
251 /** Handles Cloud Profile Manager cumulative change. */
252 virtual void sltHandleCloudProfileManagerCumulativeChange();
253 /** @} */
254
255protected:
256
257 /** @name Children stuff.
258 * @{ */
259 /** Creates and registers read cloud machine list task with @a guiCloudProfileKey.
260 * @param fWithRefresh Brings whether machines should be refreshed as well. */
261 void createReadCloudMachineListTask(const UICloudEntityKey &guiCloudProfileKey, bool fWithRefresh);
262 /** @} */
263
264private slots:
265
266 /** @name Group saving stuff.
267 * @{ */
268 /** Handles request to save settings. */
269 void sltSaveSettings();
270 /** @} */
271
272private:
273
274 /** @name Prepare/Cleanup cascade.
275 * @{ */
276 /** Prepares all. */
277 void prepare();
278 /** Prepares connections. */
279 void prepareConnections();
280
281 /** Cleanups connections. */
282 void cleanupConnections();
283 /** Cleanups all. */
284 void cleanup();
285 /** @} */
286
287 /** @name Children stuff.
288 * @{ */
289 /** Reloads local tree. */
290 void reloadLocalTree();
291 /** Reloads cloud tree. */
292 void reloadCloudTree();
293
294 /** Adds local machine item based on certain @a comMachine and optionally @a fMakeItVisible. */
295 void addLocalMachineIntoTheTree(const CMachine &comMachine, bool fMakeItVisible = false);
296 /** Adds cloud machine item based on certain @a comMachine and optionally @a fMakeItVisible, into @a strGroup. */
297 void addCloudMachineIntoTheTree(const QString &strGroup, const CCloudMachine &comMachine, bool fMakeItVisible = false);
298
299 /** Acquires local group node, creates one if necessary.
300 * @param strName Brings the name of group we looking for.
301 * @param pParentNode Brings the parent we starting to look for a group from.
302 * @param fAllGroupsOpened Brings whether we should open all the groups till the required one. */
303 UIChooserNode *getLocalGroupNode(const QString &strName, UIChooserNode *pParentNode, bool fAllGroupsOpened);
304 /** Acquires cloud group node, never create new, returns root if nothing found.
305 * @param strName Brings the name of group we looking for.
306 * @param pParentNode Brings the parent we starting to look for a group from.
307 * @param fAllGroupsOpened Brings whether we should open all the groups till the required one. */
308 UIChooserNode *getCloudGroupNode(const QString &strName, UIChooserNode *pParentNode, bool fAllGroupsOpened);
309
310 /** Returns whether group node * with specified @a enmDataType and @a strName should be opened,
311 * searching starting from the passed @a pParentNode. */
312 bool shouldGroupNodeBeOpened(UIChooserNode *pParentNode,
313 UIChooserNodeDataPrefixType enmDataType,
314 const QString &strName) const;
315 /** Returns whether global node should be favorite,
316 * searching starting from the passed @a pParentNode. */
317 bool shouldGlobalNodeBeFavorite(UIChooserNode *pParentNode) const;
318
319 /** Wipes out empty groups starting from @a pParentItem. */
320 void wipeOutEmptyGroupsStartingFrom(UIChooserNode *pParentNode);
321
322 /** Acquires desired position for a child of @a pParentNode with specified @a enmDataType and @a strName. */
323 int getDesiredNodePosition(UIChooserNode *pParentNode, UIChooserNodeDataPrefixType enmDataType, const QString &strName);
324 /** Acquires defined position for a child of @a pParentNode with specified @a enmDataType and @a strName. */
325 int getDefinedNodePosition(UIChooserNode *pParentNode, UIChooserNodeDataPrefixType enmDataType, const QString &strName);
326
327 /** Creates local machine node based on certain @a comMachine as a child of specified @a pParentNode. */
328 void createLocalMachineNode(UIChooserNode *pParentNode, const CMachine &comMachine);
329 /** Creates fake cloud machine node in passed @a enmState as a child of specified @a pParentNode. */
330 void createCloudMachineNode(UIChooserNode *pParentNode, UIFakeCloudVirtualMachineItemState enmState);
331 /** Creates real cloud machine node based on certain @a comMachine as a child of specified @a pParentNode. */
332 void createCloudMachineNode(UIChooserNode *pParentNode, const CCloudMachine &comMachine);
333
334 /** Gathers a list of possible group node names for machine nodes listed in @a exceptions, starting from @a pCurrentNode. */
335 QStringList gatherPossibleGroupNodeNames(UIChooserNode *pCurrentNode, QList<UIChooserNode*> exceptions) const;
336
337 /** Returns whether passed @a pParentNode contains child node with passed @a uId. */
338 bool checkIfNodeContainChildWithId(UIChooserNode *pParentNode, const QUuid &uId) const;
339 /** @} */
340
341 /** @name Group saving stuff.
342 * @{ */
343 /** Saves group settings. */
344 void saveGroupSettings();
345 /** Saves group definitions. */
346 void saveGroupDefinitions();
347
348 /** Gathers group @a settings of @a pParentGroup. */
349 void gatherGroupSettings(QMap<QString, QStringList> &settings, UIChooserNode *pParentGroup);
350 /** Gathers group @a definitions of @a pParentGroup. */
351 void gatherGroupDefinitions(QMap<QString, QStringList> &definitions, UIChooserNode *pParentGroup);
352
353 /** Makes sure group settings saving is finished. */
354 void makeSureGroupSettingsSaveIsFinished();
355 /** Makes sure group definitions saving is finished. */
356 void makeSureGroupDefinitionsSaveIsFinished();
357 /** @} */
358
359 /** @name Cloud stuff.
360 * @{ */
361 /** Searches for provider node with passed @a uProviderId. */
362 UIChooserNode *searchProviderNode(const QUuid &uProviderId);
363 /** Searches for provider node with passed @a strProviderShortName. */
364 UIChooserNode *searchProviderNode(const QString &strProviderShortName);
365
366 /** Searches for profile node with passed @a strProfileName under passed @a pProviderNode. */
367 UIChooserNode *searchProfileNode(UIChooserNode *pProviderNode, const QString &strProfileName);
368 /** Searches for profile node with passed @a strProviderShortName and @a strProfileName. */
369 UIChooserNode *searchProfileNode(const QString &strProviderShortName, const QString &strProfileName);
370
371 /** Searches for machine node with passed @a uMachineId under passed @a pProfileNode. */
372 UIChooserNode *searchMachineNode(UIChooserNode *pProfileNode, const QUuid &uMachineId);
373 /** Searches for machine with passed @a strProviderShortName, @a strProfileName and @a uMachineId. */
374 UIChooserNode *searchMachineNode(const QString &strProviderShortName, const QString &strProfileName, const QUuid &uMachineId);
375
376 /** Searches for fake node under passed @a pProfileNode. */
377 UIChooserNode *searchFakeNode(UIChooserNode *pProfileNode);
378 /** Searches for fake with passed @a strProviderShortName and @a strProfileName. */
379 UIChooserNode *searchFakeNode(const QString &strProviderShortName, const QString &strProfileName);
380 /** @} */
381
382 /** @name Cloud update stuff.
383 * @{ */
384 /** Enumerates all cloud machine nodes. */
385 QList<UIChooserNode*> enumerateCloudMachineNodes() const;
386
387 /** Stops all cloud updates.
388 * @param fForced Brings whether cloud updates should be killed. */
389 void stopCloudUpdates(bool fForced = false);
390 /** @} */
391
392 /** @name General stuff.
393 * @{ */
394 /** Holds the parent widget reference. */
395 UIChooser *m_pParent;
396 /** @} */
397
398 /** @name Children stuff.
399 * @{ */
400 /** Holds the invisible root node instance. */
401 UIChooserNode *m_pInvisibleRootNode;
402 /** @} */
403
404 /** @name Search stuff.
405 * @{ */
406 /** Stores the results of the current search. */
407 QList<UIChooserNode*> m_searchResults;
408 /** @} */
409
410 /** @name Group saving stuff.
411 * @{ */
412 /** Holds the consolidated map of group settings/definitions. */
413 QMap<QString, QStringList> m_groups;
414 /** @} */
415
416 /** @name Cloud update stuff.
417 * @{ */
418 /** Holds whether real cloud nodes should be kept updated. */
419 bool m_fKeepCloudNodesUpdated;
420
421 /** Holds the set of cloud entity keys currently being updated. */
422 QSet<UICloudEntityKey> m_cloudEntityKeysBeingUpdated;
423 /** @} */
424};
425
426#endif /* !FEQT_INCLUDED_SRC_manager_chooser_UIChooserAbstractModel_h */
Note: See TracBrowser for help on using the repository browser.

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