1 | /* $Id: UIChooserAbstractModel.h 86655 2020-10-20 14:59:16Z 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 |
|
---|
31 | /* COM includes: */
|
---|
32 | #include "COMEnums.h"
|
---|
33 |
|
---|
34 | /* Typedefs: */
|
---|
35 | typedef QPair<QString, QString> UICloudAccountKey;
|
---|
36 |
|
---|
37 | /* Forward declaration: */
|
---|
38 | class UIChooser;
|
---|
39 | class UIChooserNode;
|
---|
40 | class UITask;
|
---|
41 | class CCloudMachine;
|
---|
42 | class CMachine;
|
---|
43 |
|
---|
44 | /** QObject extension used as VM Chooser-pane abstract model.
|
---|
45 | * This class is used to load/save a tree of abstract invisible
|
---|
46 | * nodes representing VMs and their groups from/to extra-data. */
|
---|
47 | class UIChooserAbstractModel : public QObject
|
---|
48 | {
|
---|
49 | Q_OBJECT;
|
---|
50 |
|
---|
51 | signals:
|
---|
52 |
|
---|
53 | /** @name Cloud machine stuff.
|
---|
54 | * @{ */
|
---|
55 | /** Notifies listeners about state change for cloud machine with certain @a uId. */
|
---|
56 | void sigCloudMachineStateChange(const QUuid &uId);
|
---|
57 | /** @} */
|
---|
58 |
|
---|
59 | /** @name Group saving stuff.
|
---|
60 | * @{ */
|
---|
61 | /** Commands to start group saving. */
|
---|
62 | void sigStartGroupSaving();
|
---|
63 | /** Notifies listeners about group saving state changed. */
|
---|
64 | void sigGroupSavingStateChanged();
|
---|
65 | /** @} */
|
---|
66 |
|
---|
67 | /** @name Cloud update stuff.
|
---|
68 | * @{ */
|
---|
69 | /** Notifies listeners about cloud update state changed. */
|
---|
70 | void sigCloudUpdateStateChanged();
|
---|
71 | /** @} */
|
---|
72 |
|
---|
73 | public:
|
---|
74 |
|
---|
75 | /** Constructs abstract Chooser-model passing @a pParent to the base-class. */
|
---|
76 | UIChooserAbstractModel(UIChooser *pParent);
|
---|
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 account @a key into a set of keys currently being updated. */
|
---|
136 | void insertCloudAccountKey(const UICloudAccountKey &key);
|
---|
137 | /** Removes cloud account @a key from a set of keys currently being updated. */
|
---|
138 | void removeCloudAccountKey(const UICloudAccountKey &key);
|
---|
139 | /** Returns whether cloud account @a key is a part of key set currently being updated. */
|
---|
140 | bool containsCloudAccountKey(const UICloudAccountKey &key) const;
|
---|
141 | /** Returns whether at least one cloud account update is in progress. */
|
---|
142 | bool isCloudUpdateInProgress() const;
|
---|
143 | /** @} */
|
---|
144 |
|
---|
145 | public slots:
|
---|
146 |
|
---|
147 | /** @name Cloud machine stuff.
|
---|
148 | * @{ */
|
---|
149 | /** Handles cloud machine state change. */
|
---|
150 | void sltHandleCloudMachineStateChange();
|
---|
151 | /** @} */
|
---|
152 |
|
---|
153 | /** @name Group saving stuff.
|
---|
154 | * @{ */
|
---|
155 | /** Handles group settings saving complete. */
|
---|
156 | void sltGroupSettingsSaveComplete();
|
---|
157 | /** Handles group definitions saving complete. */
|
---|
158 | void sltGroupDefinitionsSaveComplete();
|
---|
159 | /** @} */
|
---|
160 |
|
---|
161 | protected slots:
|
---|
162 |
|
---|
163 | /** @name Main event handling stuff.
|
---|
164 | * @{ */
|
---|
165 | /** Handles local machine @a enmState change for machine with certain @a uMachineId. */
|
---|
166 | virtual void sltLocalMachineStateChanged(const QUuid &uMachineId, const KMachineState enmState);
|
---|
167 | /** Handles local machine data change for machine with certain @a uMachineId. */
|
---|
168 | virtual void sltLocalMachineDataChanged(const QUuid &uMachineId);
|
---|
169 | /** Handles local machine registering/unregistering for machine with certain @a uMachineId. */
|
---|
170 | virtual void sltLocalMachineRegistrationChanged(const QUuid &uMachineId, const bool fRegistered);
|
---|
171 |
|
---|
172 | /** Handles session @a enmState change for machine with certain @a uMachineId. */
|
---|
173 | virtual void sltSessionStateChanged(const QUuid &uMachineId, const KSessionState enmState);
|
---|
174 |
|
---|
175 | /** Handles snapshot change for machine/snapshot with certain @a uMachineId / @a uSnapshotId. */
|
---|
176 | virtual void sltSnapshotChanged(const QUuid &uMachineId, const QUuid &uSnapshotId);
|
---|
177 |
|
---|
178 | /** Handles event about cloud provider with @a uProviderId being uninstalled. */
|
---|
179 | virtual void sltHandleCloudProviderUninstall(const QUuid &uProviderId);
|
---|
180 | /** @} */
|
---|
181 |
|
---|
182 | /** @name Children stuff.
|
---|
183 | * @{ */
|
---|
184 | /** Handles reload machine with certain @a uMachineId request. */
|
---|
185 | virtual void sltReloadMachine(const QUuid &uMachineId);
|
---|
186 | /** @} */
|
---|
187 |
|
---|
188 | /** @name Cloud stuff.
|
---|
189 | * @{ */
|
---|
190 | /** Handles cloud machine unregistering for @a uId.
|
---|
191 | * @param strProviderShortName Brings provider short name.
|
---|
192 | * @param strProfileName Brings profile name. */
|
---|
193 | virtual void sltCloudMachineUnregistered(const QString &strProviderShortName,
|
---|
194 | const QString &strProfileName,
|
---|
195 | const QUuid &uId);
|
---|
196 | /** Handles cloud machine unregistering for a list of @a ids.
|
---|
197 | * @param strProviderShortName Brings provider short name.
|
---|
198 | * @param strProfileName Brings profile name. */
|
---|
199 | virtual void sltCloudMachinesUnregistered(const QString &strProviderShortName,
|
---|
200 | const QString &strProfileName,
|
---|
201 | const QList<QUuid> &ids);
|
---|
202 | /** Handles cloud machine registering for @a comMachine.
|
---|
203 | * @param strProviderShortName Brings provider short name.
|
---|
204 | * @param strProfileName Brings profile name. */
|
---|
205 | virtual void sltCloudMachineRegistered(const QString &strProviderShortName,
|
---|
206 | const QString &strProfileName,
|
---|
207 | const CCloudMachine &comMachine);
|
---|
208 | /** Handles cloud machine registering for a list of @a machines.
|
---|
209 | * @param strProviderShortName Brings provider short name.
|
---|
210 | * @param strProfileName Brings profile name. */
|
---|
211 | virtual void sltCloudMachinesRegistered(const QString &strProviderShortName,
|
---|
212 | const QString &strProfileName,
|
---|
213 | const QVector<CCloudMachine> &machines);
|
---|
214 |
|
---|
215 | /** Handles list cloud machines task complete signal. */
|
---|
216 | virtual void sltHandleCloudListMachinesTaskComplete(UITask *pTask);
|
---|
217 |
|
---|
218 | /** Handles Cloud Profile Manager cumulative change. */
|
---|
219 | virtual void sltHandleCloudProfileManagerCumulativeChange();
|
---|
220 | /** @} */
|
---|
221 |
|
---|
222 | private slots:
|
---|
223 |
|
---|
224 | /** @name Group saving stuff.
|
---|
225 | * @{ */
|
---|
226 | /** Handles request to start group saving. */
|
---|
227 | void sltStartGroupSaving();
|
---|
228 | /** @} */
|
---|
229 |
|
---|
230 | private:
|
---|
231 |
|
---|
232 | /** @name Prepare/Cleanup cascade.
|
---|
233 | * @{ */
|
---|
234 | /** Prepares all. */
|
---|
235 | void prepare();
|
---|
236 | /** Prepares connections. */
|
---|
237 | void prepareConnections();
|
---|
238 | /** @} */
|
---|
239 |
|
---|
240 | /** @name Children stuff.
|
---|
241 | * @{ */
|
---|
242 | /** Reloads local tree. */
|
---|
243 | void reloadLocalTree();
|
---|
244 | /** Reloads cloud tree. */
|
---|
245 | void reloadCloudTree();
|
---|
246 |
|
---|
247 | /** Adds local machine item based on certain @a comMachine and optionally @a fMakeItVisible. */
|
---|
248 | void addLocalMachineIntoTheTree(const CMachine &comMachine, bool fMakeItVisible = false);
|
---|
249 | /** Adds cloud machine item based on certain @a comMachine and optionally @a fMakeItVisible, into @a strGroup. */
|
---|
250 | void addCloudMachineIntoTheTree(const QString &strGroup, const CCloudMachine &comMachine, bool fMakeItVisible = false);
|
---|
251 |
|
---|
252 | /** Acquires local group node, creates one if necessary.
|
---|
253 | * @param strName Brings the name of group we looking for.
|
---|
254 | * @param pParentNode Brings the parent we starting to look for a group from.
|
---|
255 | * @param fAllGroupsOpened Brings whether we should open all the groups till the required one. */
|
---|
256 | UIChooserNode *getLocalGroupNode(const QString &strName, UIChooserNode *pParentNode, bool fAllGroupsOpened);
|
---|
257 | /** Acquires cloud group node, never create new, returns root if nothing found.
|
---|
258 | * @param strName Brings the name of group we looking for.
|
---|
259 | * @param pParentNode Brings the parent we starting to look for a group from.
|
---|
260 | * @param fAllGroupsOpened Brings whether we should open all the groups till the required one. */
|
---|
261 | UIChooserNode *getCloudGroupNode(const QString &strName, UIChooserNode *pParentNode, bool fAllGroupsOpened);
|
---|
262 |
|
---|
263 | /** Returns whether group node * with specified @a enmDataType and @a strName should be opened,
|
---|
264 | * searching starting from the passed @a pParentNode. */
|
---|
265 | bool shouldGroupNodeBeOpened(UIChooserNode *pParentNode,
|
---|
266 | UIChooserNodeDataPrefixType enmDataType,
|
---|
267 | const QString &strName) const;
|
---|
268 | /** Returns whether global node should be favorite,
|
---|
269 | * searching starting from the passed @a pParentNode. */
|
---|
270 | bool shouldGlobalNodeBeFavorite(UIChooserNode *pParentNode) const;
|
---|
271 |
|
---|
272 | /** Wipes out empty groups starting from @a pParentItem. */
|
---|
273 | void wipeOutEmptyGroupsStartingFrom(UIChooserNode *pParentNode);
|
---|
274 |
|
---|
275 | /** Acquires desired position for a child of @a pParentNode with specified @a enmDataType and @a strName. */
|
---|
276 | int getDesiredNodePosition(UIChooserNode *pParentNode, UIChooserNodeDataPrefixType enmDataType, const QString &strName);
|
---|
277 | /** Acquires defined position for a child of @a pParentNode with specified @a enmDataType and @a strName. */
|
---|
278 | int getDefinedNodePosition(UIChooserNode *pParentNode, UIChooserNodeDataPrefixType enmDataType, const QString &strName);
|
---|
279 |
|
---|
280 | /** Creates local machine node based on certain @a comMachine as a child of specified @a pParentNode. */
|
---|
281 | void createLocalMachineNode(UIChooserNode *pParentNode, const CMachine &comMachine);
|
---|
282 | /** Creates cloud machine node based on certain @a comMachine as a child of specified @a pParentNode. */
|
---|
283 | void createCloudMachineNode(UIChooserNode *pParentNode, const CCloudMachine &comMachine);
|
---|
284 |
|
---|
285 | /** Gathers a list of possible group node names for machine nodes listed in @a exceptions, starting from @a pCurrentNode. */
|
---|
286 | QStringList gatherPossibleGroupNodeNames(UIChooserNode *pCurrentNode, QList<UIChooserNode*> exceptions) const;
|
---|
287 | /** @} */
|
---|
288 |
|
---|
289 | /** @name Group saving stuff.
|
---|
290 | * @{ */
|
---|
291 | /** Saves group settings. */
|
---|
292 | void saveGroupSettings();
|
---|
293 | /** Saves group definitions. */
|
---|
294 | void saveGroupDefinitions();
|
---|
295 |
|
---|
296 | /** Gathers group @a settings of @a pParentGroup. */
|
---|
297 | void gatherGroupSettings(QMap<QString, QStringList> &settings, UIChooserNode *pParentGroup);
|
---|
298 | /** Gathers group @a definitions of @a pParentGroup. */
|
---|
299 | void gatherGroupDefinitions(QMap<QString, QStringList> &definitions, UIChooserNode *pParentGroup);
|
---|
300 |
|
---|
301 | /** Makes sure group settings saving is finished. */
|
---|
302 | void makeSureGroupSettingsSaveIsFinished();
|
---|
303 | /** Makes sure group definitions saving is finished. */
|
---|
304 | void makeSureGroupDefinitionsSaveIsFinished();
|
---|
305 | /** @} */
|
---|
306 |
|
---|
307 | /** @name General stuff.
|
---|
308 | * @{ */
|
---|
309 | /** Holds the parent widget reference. */
|
---|
310 | UIChooser *m_pParent;
|
---|
311 | /** @} */
|
---|
312 |
|
---|
313 | /** @name Children stuff.
|
---|
314 | * @{ */
|
---|
315 | /** Holds the invisible root node instance. */
|
---|
316 | UIChooserNode *m_pInvisibleRootNode;
|
---|
317 | /** @} */
|
---|
318 |
|
---|
319 | /** @name Search stuff.
|
---|
320 | * @{ */
|
---|
321 | /** Stores the results of the current search. */
|
---|
322 | QList<UIChooserNode*> m_searchResults;
|
---|
323 | /** @} */
|
---|
324 |
|
---|
325 | /** @name Group saving stuff.
|
---|
326 | * @{ */
|
---|
327 | /** Holds the consolidated map of group settings/definitions. */
|
---|
328 | QMap<QString, QStringList> m_groups;
|
---|
329 | /** @} */
|
---|
330 |
|
---|
331 | /** @name Cloud update stuff.
|
---|
332 | * @{ */
|
---|
333 | /** Holds the set of cloud account keys currently being updated. */
|
---|
334 | QSet<UICloudAccountKey> m_cloudAccountKeysBeingUpdated;
|
---|
335 | /** @} */
|
---|
336 | };
|
---|
337 |
|
---|
338 | #endif /* !FEQT_INCLUDED_SRC_manager_chooser_UIChooserAbstractModel_h */
|
---|