VirtualBox

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

Last change on this file since 88586 was 88586, checked in by vboxsync, 4 years ago

FE/Qt: bugref:8161: More rework for Chooser pane; Save group definition changes even after group toggling; That allows to avoid saving on app shutdown.

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