1 | /* $Id: UIChooserAbstractModel.h 84415 2020-05-20 15:28:43Z 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 <QThread>
|
---|
26 |
|
---|
27 | /* GUI includes: */
|
---|
28 | #include "UIChooserDefs.h"
|
---|
29 |
|
---|
30 | /* COM includes: */
|
---|
31 | #include "COMEnums.h"
|
---|
32 |
|
---|
33 | /* Forward declaration: */
|
---|
34 | class QUuid;
|
---|
35 | class UIChooser;
|
---|
36 | class UIChooserNode;
|
---|
37 | class UITask;
|
---|
38 | class CCloudMachine;
|
---|
39 | class CMachine;
|
---|
40 |
|
---|
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. */
|
---|
45 | class UIChooserAbstractModel : public QObject
|
---|
46 | {
|
---|
47 | Q_OBJECT;
|
---|
48 |
|
---|
49 | signals:
|
---|
50 |
|
---|
51 | /** @name Cloud machine stuff.
|
---|
52 | * @{ */
|
---|
53 | /** Notifies 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 | /** Commands to start group saving. */
|
---|
60 | void sigStartGroupSaving();
|
---|
61 | /** Notifies about group saving state changed. */
|
---|
62 | void sigGroupSavingStateChanged();
|
---|
63 | /** @} */
|
---|
64 |
|
---|
65 | public:
|
---|
66 |
|
---|
67 | /** Constructs abstract Chooser-model passing @a pParent to the base-class. */
|
---|
68 | UIChooserAbstractModel(UIChooser *pParent);
|
---|
69 |
|
---|
70 | /** @name General stuff.
|
---|
71 | * @{ */
|
---|
72 | /** Inits model. */
|
---|
73 | virtual void init();
|
---|
74 | /** Deinits model. */
|
---|
75 | virtual void deinit();
|
---|
76 | /** @} */
|
---|
77 |
|
---|
78 | /** @name Children stuff.
|
---|
79 | * @{ */
|
---|
80 | /** Returns invisible root node instance. */
|
---|
81 | UIChooserNode *invisibleRoot() const { return m_pInvisibleRootNode; }
|
---|
82 |
|
---|
83 | /** Wipes out empty groups. */
|
---|
84 | void wipeOutEmptyGroups();
|
---|
85 |
|
---|
86 | /** Generates unique group name traversing recursively starting from @a pRoot. */
|
---|
87 | static QString uniqueGroupName(UIChooserNode *pRoot);
|
---|
88 | /** @} */
|
---|
89 |
|
---|
90 | /** @name Search stuff.
|
---|
91 | * @{ */
|
---|
92 | /** Performs a search starting from the m_pInvisibleRootNode. */
|
---|
93 | virtual void performSearch(const QString &strSearchTerm, int iItemSearchFlags);
|
---|
94 | /** Cleans the search result data members and disables item's visual effects.
|
---|
95 | * Also returns a list of all nodes which may be utilized by the calling code. */
|
---|
96 | virtual QList<UIChooserNode*> resetSearch();
|
---|
97 | /** Returns search result. */
|
---|
98 | QList<UIChooserNode*> searchResult() const;
|
---|
99 | /** @} */
|
---|
100 |
|
---|
101 | /** @name Group saving stuff.
|
---|
102 | * @{ */
|
---|
103 | /** Commands to save group settings. */
|
---|
104 | void saveGroupSettings();
|
---|
105 | /** Returns whether group saving is in progress. */
|
---|
106 | bool isGroupSavingInProgress() const;
|
---|
107 |
|
---|
108 | /** Returns QString representation for passed @a uId, wiping out {} symbols.
|
---|
109 | * @note Required for backward compatibility after QString=>QUuid change. */
|
---|
110 | static QString toOldStyleUuid(const QUuid &uId);
|
---|
111 |
|
---|
112 | /** Returns node extra-data prefix of certain @a enmType. */
|
---|
113 | static QString prefixToString(UIChooserNodeDataPrefixType enmType);
|
---|
114 | /** Returns node extra-data option of certain @a enmType. */
|
---|
115 | static QString optionToString(UIChooserNodeDataOptionType enmType);
|
---|
116 | /** Returns node extra-data value of certain @a enmType. */
|
---|
117 | static QString valueToString(UIChooserNodeDataValueType enmType);
|
---|
118 | /** @} */
|
---|
119 |
|
---|
120 | public slots:
|
---|
121 |
|
---|
122 | /** @name Cloud machine stuff.
|
---|
123 | * @{ */
|
---|
124 | /** Handles cloud machine state change. */
|
---|
125 | void sltHandleCloudMachineStateChange();
|
---|
126 | /** @} */
|
---|
127 |
|
---|
128 | /** @name Group saving stuff.
|
---|
129 | * @{ */
|
---|
130 | /** Handles group definition saving complete. */
|
---|
131 | void sltGroupDefinitionsSaveComplete();
|
---|
132 | /** Handles group order saving complete. */
|
---|
133 | void sltGroupOrdersSaveComplete();
|
---|
134 | /** @} */
|
---|
135 |
|
---|
136 | protected slots:
|
---|
137 |
|
---|
138 | /** @name Main event handling stuff.
|
---|
139 | * @{ */
|
---|
140 | /** Handles local machine @a enmState change for machine with certain @a uMachineId. */
|
---|
141 | virtual void sltLocalMachineStateChanged(const QUuid &uMachineId, const KMachineState enmState);
|
---|
142 | /** Handles local machine data change for machine with certain @a uMachineId. */
|
---|
143 | virtual void sltLocalMachineDataChanged(const QUuid &uMachineId);
|
---|
144 | /** Handles local machine registering/unregistering for machine with certain @a uMachineId. */
|
---|
145 | virtual void sltLocalMachineRegistered(const QUuid &uMachineId, const bool fRegistered);
|
---|
146 | /** Handles cloud machine registering/unregistering for machine with certain @a uMachineId.
|
---|
147 | * @param strProviderShortName Brings provider short name.
|
---|
148 | * @param strProfileName Brings profile name. */
|
---|
149 | virtual void sltCloudMachineRegistered(const QString &strProviderShortName, const QString &strProfileName,
|
---|
150 | const QUuid &uMachineId, const bool fRegistered);
|
---|
151 | /** Handles session @a enmState change for machine with certain @a uMachineId. */
|
---|
152 | virtual void sltSessionStateChanged(const QUuid &uMachineId, const KSessionState enmState);
|
---|
153 | /** Handles snapshot change for machine/snapshot with certain @a uMachineId / @a uSnapshotId. */
|
---|
154 | virtual void sltSnapshotChanged(const QUuid &uMachineId, const QUuid &uSnapshotId);
|
---|
155 | /** @} */
|
---|
156 |
|
---|
157 | /** @name Children stuff.
|
---|
158 | * @{ */
|
---|
159 | /** Handles reload machine with certain @a uMachineId request. */
|
---|
160 | virtual void sltReloadMachine(const QUuid &uMachineId);
|
---|
161 | /** @} */
|
---|
162 |
|
---|
163 | /** @name Cloud stuff.
|
---|
164 | * @{ */
|
---|
165 | /** Handles list cloud machines task complete signal. */
|
---|
166 | virtual void sltHandleCloudListMachinesTaskComplete(UITask *pTask);
|
---|
167 | /** @} */
|
---|
168 |
|
---|
169 | private slots:
|
---|
170 |
|
---|
171 | /** @name Group saving stuff.
|
---|
172 | * @{ */
|
---|
173 | /** Handles request to start group saving. */
|
---|
174 | void sltStartGroupSaving();
|
---|
175 | /** @} */
|
---|
176 |
|
---|
177 | private:
|
---|
178 |
|
---|
179 | /** @name Prepare/Cleanup cascade.
|
---|
180 | * @{ */
|
---|
181 | /** Prepares all. */
|
---|
182 | void prepare();
|
---|
183 | /** Prepares connections. */
|
---|
184 | void prepareConnections();
|
---|
185 | /** @} */
|
---|
186 |
|
---|
187 | /** @name Children stuff.
|
---|
188 | * @{ */
|
---|
189 | /** Adds local machine item based on certain @a comMachine and optionally @a fMakeItVisible. */
|
---|
190 | void addLocalMachineIntoTheTree(const CMachine &comMachine, bool fMakeItVisible = false);
|
---|
191 | /** Adds cloud machine item based on certain @a comMachine and optionally @a fMakeItVisible, into @a strGroup. */
|
---|
192 | void addCloudMachineIntoTheTree(const QString &strGroup, const CCloudMachine &comMachine, bool fMakeItVisible = false);
|
---|
193 |
|
---|
194 | /** Acquires local group node, creates one if necessary.
|
---|
195 | * @param strName Brings the name of group we looking for.
|
---|
196 | * @param pParentNode Brings the parent we starting to look for a group from.
|
---|
197 | * @param fAllGroupsOpened Brings whether we should open all the groups till the required one. */
|
---|
198 | UIChooserNode *getLocalGroupNode(const QString &strName, UIChooserNode *pParentNode, bool fAllGroupsOpened);
|
---|
199 | /** Acquires cloud group node, never create new, returns root if nothing found.
|
---|
200 | * @param strName Brings the name of group we looking for.
|
---|
201 | * @param pParentNode Brings the parent we starting to look for a group from.
|
---|
202 | * @param fAllGroupsOpened Brings whether we should open all the groups till the required one. */
|
---|
203 | UIChooserNode *getCloudGroupNode(const QString &strName, UIChooserNode *pParentNode, bool fAllGroupsOpened);
|
---|
204 |
|
---|
205 | /** Returns whether group node with certain @a strName should be opened, searching starting from the passed @a pParentItem. */
|
---|
206 | bool shouldGroupNodeBeOpened(UIChooserNode *pParentNode, const QString &strName);
|
---|
207 |
|
---|
208 | /** Wipes out empty groups starting from @a pParentItem. */
|
---|
209 | void wipeOutEmptyGroupsStartingFrom(UIChooserNode *pParentNode);
|
---|
210 |
|
---|
211 | /** Returns whether global node within the @a pParentNode is favorite. */
|
---|
212 | bool isGlobalNodeFavorite(UIChooserNode *pParentNode) const;
|
---|
213 |
|
---|
214 | /** Acquires desired position for a child of @a pParentNode with specified @a enmDataType and @a strName. */
|
---|
215 | int getDesiredNodePosition(UIChooserNode *pParentNode, UIChooserNodeDataPrefixType enmDataType, const QString &strName);
|
---|
216 | /** Acquires defined position for a child of @a pParentNode with specified @a enmDataType and @a strName. */
|
---|
217 | int getDefinedNodePosition(UIChooserNode *pParentNode, UIChooserNodeDataPrefixType enmDataType, const QString &strName);
|
---|
218 |
|
---|
219 | /** Creates local machine node based on certain @a comMachine as a child of specified @a pParentNode. */
|
---|
220 | void createLocalMachineNode(UIChooserNode *pParentNode, const CMachine &comMachine);
|
---|
221 | /** Creates cloud machine node based on certain @a comMachine as a child of specified @a pParentNode. */
|
---|
222 | void createCloudMachineNode(UIChooserNode *pParentNode, const CCloudMachine &comMachine);
|
---|
223 | /** @} */
|
---|
224 |
|
---|
225 | /** @name Group saving stuff.
|
---|
226 | * @{ */
|
---|
227 | /** Saves group definitions. */
|
---|
228 | void saveGroupDefinitions();
|
---|
229 | /** Saves group orders. */
|
---|
230 | void saveGroupOrders();
|
---|
231 |
|
---|
232 | /** Gathers group @a definitions of @a pParentGroup. */
|
---|
233 | void gatherGroupDefinitions(QMap<QString, QStringList> &definitions, UIChooserNode *pParentGroup);
|
---|
234 | /** Gathers group @a orders of @a pParentGroup. */
|
---|
235 | void gatherGroupOrders(QMap<QString, QStringList> &orders, UIChooserNode *pParentGroup);
|
---|
236 |
|
---|
237 | /** Makes sure group definitions saving is finished. */
|
---|
238 | void makeSureGroupDefinitionsSaveIsFinished();
|
---|
239 | /** Makes sure group orders saving is finished. */
|
---|
240 | void makeSureGroupOrdersSaveIsFinished();
|
---|
241 | /** @} */
|
---|
242 |
|
---|
243 | /** @name General stuff.
|
---|
244 | * @{ */
|
---|
245 | /** Holds the parent widget reference. */
|
---|
246 | UIChooser *m_pParent;
|
---|
247 | /** @} */
|
---|
248 |
|
---|
249 | /** @name Children stuff.
|
---|
250 | * @{ */
|
---|
251 | /** Holds the invisible root node instance. */
|
---|
252 | UIChooserNode *m_pInvisibleRootNode;
|
---|
253 | /** @} */
|
---|
254 |
|
---|
255 | /** @name Search stuff.
|
---|
256 | * @{ */
|
---|
257 | /** Stores the results of the current search. */
|
---|
258 | QList<UIChooserNode*> m_searchResults;
|
---|
259 | /** @} */
|
---|
260 |
|
---|
261 | /** @name Group saving stuff.
|
---|
262 | * @{ */
|
---|
263 | /** Holds the consolidated map of group definitions/orders. */
|
---|
264 | QMap<QString, QStringList> m_groups;
|
---|
265 | /** @} */
|
---|
266 | };
|
---|
267 |
|
---|
268 |
|
---|
269 | /** QThread subclass allowing to save group definitions asynchronously. */
|
---|
270 | class UIThreadGroupDefinitionSave : public QThread
|
---|
271 | {
|
---|
272 | Q_OBJECT;
|
---|
273 |
|
---|
274 | signals:
|
---|
275 |
|
---|
276 | /** Notifies about machine with certain @a uMachineId to be reloaded. */
|
---|
277 | void sigReload(const QUuid &uMachineId);
|
---|
278 |
|
---|
279 | /** Notifies about task is complete. */
|
---|
280 | void sigComplete();
|
---|
281 |
|
---|
282 | public:
|
---|
283 |
|
---|
284 | /** Returns group saving thread instance. */
|
---|
285 | static UIThreadGroupDefinitionSave* instance();
|
---|
286 | /** Prepares group saving thread instance. */
|
---|
287 | static void prepare();
|
---|
288 | /** Cleanups group saving thread instance. */
|
---|
289 | static void cleanup();
|
---|
290 |
|
---|
291 | /** Configures @a groups saving thread with corresponding @a pListener.
|
---|
292 | * @param oldLists Brings the old definition list to be compared.
|
---|
293 | * @param newLists Brings the new definition list to be saved. */
|
---|
294 | void configure(QObject *pParent,
|
---|
295 | const QMap<QString, QStringList> &oldLists,
|
---|
296 | const QMap<QString, QStringList> &newLists);
|
---|
297 |
|
---|
298 | protected:
|
---|
299 |
|
---|
300 | /** Constructs group saving thread. */
|
---|
301 | UIThreadGroupDefinitionSave();
|
---|
302 | /** Destructs group saving thread. */
|
---|
303 | virtual ~UIThreadGroupDefinitionSave() /* override */;
|
---|
304 |
|
---|
305 | /** Contains a thread task to be executed. */
|
---|
306 | void run();
|
---|
307 |
|
---|
308 | /** Holds the singleton instance. */
|
---|
309 | static UIThreadGroupDefinitionSave *s_pInstance;
|
---|
310 |
|
---|
311 | /** Holds the map of group definitions to be compared. */
|
---|
312 | QMap<QString, QStringList> m_oldLists;
|
---|
313 | /** Holds the map of group definitions to be saved. */
|
---|
314 | QMap<QString, QStringList> m_newLists;
|
---|
315 | };
|
---|
316 |
|
---|
317 |
|
---|
318 | /** QThread subclass allowing to save group order asynchronously. */
|
---|
319 | class UIThreadGroupOrderSave : public QThread
|
---|
320 | {
|
---|
321 | Q_OBJECT;
|
---|
322 |
|
---|
323 | signals:
|
---|
324 |
|
---|
325 | /** Notifies about task is complete. */
|
---|
326 | void sigComplete();
|
---|
327 |
|
---|
328 | public:
|
---|
329 |
|
---|
330 | /** Returns group saving thread instance. */
|
---|
331 | static UIThreadGroupOrderSave *instance();
|
---|
332 | /** Prepares group saving thread instance. */
|
---|
333 | static void prepare();
|
---|
334 | /** Cleanups group saving thread instance. */
|
---|
335 | static void cleanup();
|
---|
336 |
|
---|
337 | /** Configures group saving thread with corresponding @a pListener.
|
---|
338 | * @param groups Brings the groups to be saved. */
|
---|
339 | void configure(QObject *pListener,
|
---|
340 | const QMap<QString, QStringList> &groups);
|
---|
341 |
|
---|
342 | protected:
|
---|
343 |
|
---|
344 | /** Constructs group saving thread. */
|
---|
345 | UIThreadGroupOrderSave();
|
---|
346 | /** Destructs group saving thread. */
|
---|
347 | virtual ~UIThreadGroupOrderSave() /* override */;
|
---|
348 |
|
---|
349 | /** Contains a thread task to be executed. */
|
---|
350 | virtual void run() /* override */;
|
---|
351 |
|
---|
352 | /** Holds the singleton instance. */
|
---|
353 | static UIThreadGroupOrderSave *s_pInstance;
|
---|
354 |
|
---|
355 | /** Holds the map of groups to be saved. */
|
---|
356 | QMap<QString, QStringList> m_groups;
|
---|
357 | };
|
---|
358 |
|
---|
359 |
|
---|
360 | #endif /* !FEQT_INCLUDED_SRC_manager_chooser_UIChooserAbstractModel_h */
|
---|